view tests/test_web.py @ 25:991bce6b6881 default tip

[knn] placeholder for planning session
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Sep 2017 14:35:50 -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()