annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test web functionality
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import os
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import unittest
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 from common import datafile
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 from globalneighbors.read import read_city_list
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 from globalneighbors.web import autocomplete
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 class WebFunctionalityTest(unittest.TestCase):
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 def test_autcomplete(self):
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 """test autocomplete underlying functionality"""
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 # read base data
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 cityfile = datafile('cities1000.txt')
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 assert os.path.exists(cityfile)
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 cities = read_city_list(cityfile)
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 # Let's look for Chicago
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 q = u'Ch'
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 results = autocomplete(cities, q)
13
94af113e498a we have links
Jeff Hammel <k0scist@gmail.com>
parents: 1
diff changeset
27 names = [result['name']
94af113e498a we have links
Jeff Hammel <k0scist@gmail.com>
parents: 1
diff changeset
28 for result in results]
94af113e498a we have links
Jeff Hammel <k0scist@gmail.com>
parents: 1
diff changeset
29 assert all([name.startswith(q)
94af113e498a we have links
Jeff Hammel <k0scist@gmail.com>
parents: 1
diff changeset
30 for name in names])
94af113e498a we have links
Jeff Hammel <k0scist@gmail.com>
parents: 1
diff changeset
31 assert sorted(names) == names
94af113e498a we have links
Jeff Hammel <k0scist@gmail.com>
parents: 1
diff changeset
32 assert 'Chicago' in names
1
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 if __name__ == '__main__':
1b94f3bf97e5 * limit distance function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 unittest.main()