view tests/test_web.py @ 22:e69cb496324e

we have a data dump
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 17:45:19 -0700
parents 94af113e498a
children
line wrap: on
line source

#!/usr/bin/env python

"""
test web functionality
"""

import os
import unittest
from common import datafile
from globalneighbors.read import read_city_list
from globalneighbors.web import autocomplete


class WebFunctionalityTest(unittest.TestCase):

    def test_autcomplete(self):
        """test autocomplete underlying functionality"""

        # read base data
        cityfile = datafile('cities1000.txt')
        assert os.path.exists(cityfile)
        cities = read_city_list(cityfile)

        # Let's look for Chicago
        q = u'Ch'
        results = autocomplete(cities, q)
        names = [result['name']
                 for result in results]
        assert all([name.startswith(q)
                    for name in names])
        assert sorted(names) == names
        assert 'Chicago' in names


if __name__ == '__main__':
    unittest.main()