1
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 test web functionality
|
|
5 """
|
|
6
|
|
7 import os
|
|
8 import unittest
|
|
9 from common import datafile
|
|
10 from globalneighbors.read import read_city_list
|
|
11 from globalneighbors.web import autocomplete
|
|
12
|
|
13
|
|
14 class WebFunctionalityTest(unittest.TestCase):
|
|
15
|
|
16 def test_autcomplete(self):
|
|
17 """test autocomplete underlying functionality"""
|
|
18
|
|
19 # read base data
|
|
20 cityfile = datafile('cities1000.txt')
|
|
21 assert os.path.exists(cityfile)
|
|
22 cities = read_city_list(cityfile)
|
|
23
|
|
24 # Let's look for Chicago
|
|
25 q = u'Ch'
|
|
26 results = autocomplete(cities, q)
|
13
|
27 names = [result['name']
|
|
28 for result in results]
|
|
29 assert all([name.startswith(q)
|
|
30 for name in names])
|
|
31 assert sorted(names) == names
|
|
32 assert 'Chicago' in names
|
1
|
33
|
|
34
|
|
35 if __name__ == '__main__':
|
|
36 unittest.main()
|