/
test.py
472 lines (385 loc) · 24 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
import unittest
from mmapi import *
print "-------------------------------------------------------------------------"
print "Beginning mmapi unittests"
print "-------------------------------------------------------------------------\n\n"
DEV_KEY = 'OA08061815799061525'
LAT = 53.36663
LON = -2.90809
DS_1 = 'mm.poi.global.general.atm'
DS_2 = 'mm.poi.global.general.wifi'
DS_BAD = 'mm.poi.global.herebedragons'
COUNT = 10
FIELDNAME = 'carpark'
OPERATOR = 'eq'
VALUE = 'large'
OPTIONS = ['one', 'two', 'three']
STREET = 'Fleet Street'
CITY = 'London'
COUNTRY_CODE = 'GB'
AREAS = ['London', 'England']
REGION = 'England'
POSTAL_CODE = 'ec1n'
DISPLAY_NAME = 'Multimap Office'
QS_UNIQUE = 'London'
GEOCODE_QUALITY = 1
GEOCODE_SCORE = 0.995
ZOOM_FACTOR = 4
ZIP = '90210'
STATE = 'Washington'
ADDRESS = {
'street': STREET,
'city': CITY,
'areas': AREAS,
'region': REGION,
'state': STATE,
'postal_code': POSTAL_CODE,
'zip': ZIP,
'display_name': DISPLAY_NAME,
'country_code': COUNTRY_CODE,
'qs': QS_UNIQUE
}
LATLON = {
'lat': LAT,
'lon': LON
}
LOCATION = {
'geocode_quality': GEOCODE_QUALITY,
'geocode_score': GEOCODE_SCORE,
'address': ADDRESS,
'zoom_factor': ZOOM_FACTOR,
'point': LATLON
}
class testMMLatLon(unittest.TestCase):
"""Tests MMLatLon objects and methods"""
def setUp(self):
"""Instantiate a MMLatLon object"""
self.latlon = MMLatLon(LAT,LON)
def test_structure(self):
"""MMLatLon.__init__() tests general struture of MMLatLon object."""
self.assertTrue(type(self.latlon) is MMLatLon)
self.assertEqual(self.latlon['lat'], LAT)
self.assertEqual(self.latlon['lon'], LON)
def test_to_api_query(self):
"""MMLatLon.to_api_query() should return query string for API request."""
qs = { 'lat': str(LAT), 'lon': str(LON) }
self.assertEqual(self.latlon.to_api_query(), qs)
def test_to_api_query_with_postfix(self):
"""MMLatLon.to_api_query(3) should return query string for API request including arg_[COUNTER]."""
qs = {'lon_3': str(LON), 'lat_3': str(LAT) }
self.assertEqual(self.latlon.to_api_query(3), qs)
def test_from_json(self):
"""MMLatLon.from_json() should create object with correct structure and values."""
newlatlon = MMLatLon()
newlatlon.from_json( { 'lat': LAT, 'lon': LON } )
self.assertEqual(newlatlon['lat'], LAT)
self.assertEqual(newlatlon['lon'], LON)
class testMMBounds(unittest.TestCase):
"""Test MMBounds objects and methods."""
def setUp(self):
pass
def test_simple_constuctor(self):
"""MMBounds.__init__() test constructor and reset methods give correct values and structure."""
bounds1 = MMBounds( MMLatLon( -10.0, -10.0 ), MMLatLon( 10.0, 10.0 ) )
bounds2 = MMBounds( MMLatLon( -10.0, -10.0 ) )
bounds3 = MMBounds( None, MMLatLon( 10.0, 10.0 ) )
bounds4 = MMBounds( MMLocation( coords=MMLatLon( -10.0, -10.0 ) ), MMLocation( coords=MMLatLon( 10.0, 10.0 ) ) )
bounds5 = MMBounds( MMLatLon( -10.0, 10.0 ), MMLatLon( 10.0, -10.0 ) )
self.assertEqual('(-10.0,-10.0)', bounds1.getSouthWest().to_string(), "Basic assignment of SW broken.")
self.assertEqual('(10.0,10.0)', bounds1.getNorthEast().to_string(), "Basic assignment of NE broken.")
self.assertEqual(bounds2.getSouthWest().to_string(), bounds2.getNorthEast().to_string(),"Assignment with single argument broken.")
self.assertEqual(bounds3.getSouthWest().to_string(), bounds3.getNorthEast().to_string(), "Assignment with undefined first argument broken.")
self.assertEqual('(-10.0,-10.0)', bounds4.getSouthWest().to_string(), "Basic MMLocation assignment of SW broken.")
self.assertEqual('(10.0,10.0)', bounds4.getNorthEast().to_string(), "Basic MMLocation assignment of NE broken.")
self.assertEqual('(-10.0,10.0)', bounds5.getSouthWest().to_string(), "Basic assignment of IDL SW broken." )
self.assertEqual('(10.0,-10.0)', bounds5.getNorthEast().to_string(), "Basic assignment of IDL NE broken.")
def test_extending_normal(self):
"""MMBounds.extend() test for correct values and structure"""
bounds = MMBounds( MMLatLon( -10.0, -10.0 ), MMLatLon( 10.0, 10.0 ) )
bounds.extend( MMLatLon( 15.0, 15.0 ) )
self.assertEqual('[ (-10.0,-10.0), (15.0,15.0) ]', bounds.to_string())
bounds.extend( MMLatLon( 20.0, -15.0 ) )
self.assertEqual('[ (-10.0,-15.0), (20.0,15.0) ]', bounds.to_string())
bounds.extend( MMLatLon( -15.0, 7.0 ) )
self.assertEqual('[ (-15.0,-15.0), (20.0,15.0) ]', bounds.to_string(), "Third extension didn't move S correctly." )
bounds = MMBounds( MMLatLon( 53.36663, -2.90809 ), MMLatLon( 53.38286, -2.88785 ) )
bounds.extend( MMLatLon( 53.382867, -2.90807 ) )
self.assertEqual('[ (53.36663,-2.90809), (53.382867,-2.88785) ]', bounds.to_string(), "Known bad extension failed again.")
def test_to_api_query(self):
"""MMBounds.to_api_query() should return query string for API request."""
bounds = MMBounds( MMLatLon( -10.0, -10.0 ), MMLatLon( 10.0, 10.0 ) )
qs = {'bb': '-10.0,-10.0;10.0,10.0' }
self.assertEqual(bounds.to_api_query(), qs)
def test_to_api_query_with_postfix(self):
"""MMBounds.to_api_query() should return query string for API request."""
bounds = MMBounds( MMLatLon( -10.0, -10.0 ), MMLatLon( 10.0, 10.0 ) )
qs = {'bb_3': '-10.0,-10.0;10.0,10.0' }
self.assertEqual(bounds.to_api_query(3), qs)
class testMMAddress(unittest.TestCase):
"""Tests MMAddress objects and methods."""
def setUp(self):
self.address = MMAddress( street=STREET, city=CITY, areas=AREAS, region=REGION, state=STATE, postal_code=POSTAL_CODE,
zip_code=ZIP, display_name=DISPLAY_NAME, country_code=COUNTRY_CODE, qs=QS_UNIQUE)
def test_to_api_query(self):
"""MMAddress.to_api_query() should return query string for API request."""
qs = {'postalCode': POSTAL_CODE, 'city': CITY, 'countryCode': COUNTRY_CODE, 'ZIP': ZIP, 'region': REGION, 'state': STATE, 'street': STREET, 'qs': QS_UNIQUE }
self.assertEqual(self.address.to_api_query(), qs)
def test_to_api_query_with_postfix(self):
"""MMAddress.to_api_query(3) should return query string for API request including arg_[COUNTER]."""
qs = {'postalCode_3': POSTAL_CODE, 'city_3': CITY, 'ZIP_3': ZIP, 'region_3': REGION, 'countryCode_3': COUNTRY_CODE, 'state_3': STATE, 'street_3': STREET, 'qs_3': QS_UNIQUE }
self.assertEqual(self.address.to_api_query(3), qs)
class testMMLocation(unittest.TestCase):
"""Tests MMlocation objects adn methods"""
def setUp(self):
self.location = MMLocation()
def test_from_json(self):
"""MMLocation.from_json() should create object with correct structure and values."""
self.location.from_json( LOCATION )
self.assertTrue(type(self.location) is MMLocation )
self.assertTrue(type(self.location['address']) is MMAddress )
self.assertTrue(type(self.location['coords']) is MMLatLon )
# Bounds not yet implemented
#self.assertTrue(type(location['bounds']) is MMBounds )
self.assertEqual(self.location['geocode_quality'], GEOCODE_QUALITY )
self.assertEqual(self.location['geocode_score'], GEOCODE_SCORE )
self.assertEqual(self.location['zoom_factor'], ZOOM_FACTOR )
def test_to_api_query(self):
"""MMLocation.to_api_query() should return query string for API request."""
qs = { 'street': STREET, 'city': CITY, 'region': REGION, 'state': STATE, 'postalCode': POSTAL_CODE, 'countryCode': COUNTRY_CODE, 'qs': QS_UNIQUE, 'ZIP': ZIP, 'lat': str(LAT), 'lon': str(LON) }
self.location.from_json( LOCATION )
self.assertEqual(self.location.to_api_query(), qs)
def test_to_api_query_with_postfix(self):
"""MMLocation.to_api_query() should return query string for API request including arg_[COUNTER]."""
qs = { 'street_3': STREET, 'city_3': CITY, 'region_3': REGION, 'state_3': STATE, 'postalCode_3': POSTAL_CODE, 'ZIP_3': ZIP, 'qs_3': QS_UNIQUE, 'countryCode_3': COUNTRY_CODE, 'lat_3': str(LAT), 'lon_3': str(LON) }
self.location.from_json( LOCATION )
self.assertEqual(self.location.to_api_query(3), qs)
def test_lat_lon_constructor(self):
"""MMLocation.__init__(LAT, LON) should create object with correct structure, types and values"""
location = MMLocation( lat=LAT, lon=LON )
self.assertTrue(type(location['coords']) is MMLatLon )
self.assertEqual(location['coords']['lat'], LAT)
self.assertEqual(location['coords']['lon'], LON)
def test_lat_lon_object_constructor(self):
"""MMLocation.__init__(MMLatLon) should create object with correct structure, types and values"""
location = MMLocation( coords=MMLatLon(LAT, LON) )
self.assertTrue(type(location['coords']) is MMLatLon )
self.assertEqual(location['coords']['lat'], LAT)
self.assertEqual(location['coords']['lon'], LON)
def test_qs_constructor(self):
"""MMLocation.__init__(qs) should create object with correct structure, types and values"""
location = MMLocation( qs='se22' )
self.assertTrue(type(location['address']) is MMAddress )
self.assertEqual(location['address']['qs'], 'se22')
def test_address_constructor(self):
"""MMLocation.__init__(MMAddress) should create object with correct structure, types and values"""
location = MMLocation( address=MMAddress(qs='se22', country_code='gb') )
self.assertTrue(type(location['address']) is MMAddress )
self.assertEqual(location['address']['qs'], 'se22')
def test_search_constructor(self):
"""MMLocation.__init__(MMSearch) should create object with correct structure, types and values"""
search = MMSearch()
search['point'] = MMLatLon( LAT, LON )
location = MMLocation( search=search )
self.assertTrue(type(location['search']) is MMSearch )
self.assertTrue(type(location['search']['point']) is MMLatLon )
self.assertEqual(location['search']['point']['lat'], LAT )
def test_route_constructor(self):
"""MMLocation.__init__(MMRoute) should create object with correct structure, types and values"""
route = MMRoute( [] )
route['mode'] = 'driving'
location = MMLocation( route=route )
self.assertTrue(type(location['route']) is MMRoute )
self.assertEqual(location['route']['mode'], 'driving' )
def test_multiple_object_constructor(self):
"""MMLocation.__init__(MMSearch, MMAddress) should create object with correct structure, types and values"""
address = MMAddress(qs='se22', country_code='gb')
search = MMSearch()
search['point'] = MMLatLon( LAT, LON )
location = MMLocation( search=search, address=address )
self.assertTrue(type(location['address']) is MMAddress )
self.assertEqual(location['address']['qs'], 'se22')
self.assertTrue(type(location['search']) is MMSearch )
self.assertTrue(type(location['search']['point']) is MMLatLon )
self.assertEqual(location['search']['point']['lat'], LAT )
class testGeocoder(unittest.TestCase):
"""Tests geocoding results for various qs strings."""
def setUp(self):
self.geocoder = MMGeocoder( DEV_KEY )
def test_london(self):
"""MMGeocoder.request() should return geocoder response object with unique location result, and correct structure, types and values"""
address = MMAddress(qs='london', country_code='gb')
result = self.geocoder.geocode( address )
self.assertEqual(result['location_count'], 1)
self.assertEqual(int(result['result_set'][0]['geocode_quality']), 3)
self.assertTrue(type(result['result_set'][0]) is MMLocation )
self.assertTrue(type(result['result_set'][0]['address']) is MMAddress )
self.assertEqual(result['result_set'][0]['address']['display_name'], 'London, England, SW1P 3')
self.assertEqual(result['result_set'][0]['address']['postal_code'], 'SW1P 3')
self.assertEqual(result['result_set'][0]['address']['country_code'], 'GB')
self.assertEqual(result['result_set'][0]['address']['areas'][0], 'London')
self.assertEqual(result['result_set'][0]['address']['areas'][1], 'England')
self.assertEqual(float(result['result_set'][0]['geocode_score']), 1.000)
self.assertEqual(result['result_set'][0]['zoom_factor'], 14)
self.assertTrue(type(result['result_set'][0]['coords']) is MMLatLon )
self.assertTrue(result['result_set'][0]['coords']['lat'])
self.assertTrue(result['result_set'][0]['coords']['lon'])
def test_sutton(self):
"""MMGeocoder.request() should return geocoder response object with disambiguation result, and correct structure, types and values"""
address = MMAddress(qs='sutton', country_code='gb')
result = self.geocoder.geocode( address )
self.assertEqual(result['error_code'], 'MM_GEOCODE_MULTIPLE_MATCHES')
self.assertTrue(result['location_count'] > 10)
self.assertEqual(int(result['result_set'][5]['geocode_quality']), 3)
self.assertTrue(type(result['result_set'][5]) is MMLocation )
self.assertTrue(type(result['result_set'][5]['address']) is MMAddress )
self.assertTrue(result['result_set'][5]['address']['display_name'])
self.assertTrue(result['result_set'][5]['address']['postal_code'])
self.assertTrue(result['result_set'][5]['address']['country_code'])
self.assertTrue(result['result_set'][5]['address']['areas'][0])
self.assertTrue(result['result_set'][5]['address']['areas'][1])
self.assertTrue(result['result_set'][0]['geocode_score'])
self.assertEqual(result['result_set'][5]['zoom_factor'], 14)
self.assertTrue(type(result['result_set'][5]['coords']) is MMLatLon )
self.assertTrue(result['result_set'][5]['coords']['lat'])
self.assertTrue(result['result_set'][5]['coords']['lon'])
def test_not_found(self):
"""MMGeocoder.request() should return geocoder response object with no matches result, and correct structure, types and values"""
address = MMAddress(qs='herebedragons', country_code='gb')
result = self.geocoder.geocode( address )
self.assertEqual(result['error_code'], 'MM_GEOCODE_NO_MATCHES')
self.assertEqual(result['location_count'], int(0))
class testMMRoute(unittest.TestCase):
"""Tests MMRoute object and methods"""
def setUp(self):
location_1 = MMLocation( MMAddress(qs='w1', country_code='GB') )
location_2 = MMLocation( MMAddress(qs='w2', country_code='GB') )
self.route = MMRoute( [location_1, location_2 ])
self.route['mode'] = 'walking'
self.route['optimize_for'] = 'distance'
self.route['optimize_intermediates'] = 'true'
self.route['emissions'] = 'true'
self.route['custom_emission'] = [
{ 'name': 'car', 'value': 23, 'unit': 'mpg_imp', 'type': 'gas' },
{ 'name': 'truck', 'value': 34, 'unit': 'mpg_imp', 'type': 'gas' },
{ 'name': 'van', 'value': 89, 'unit': 'mpg', 'type': 'diesel' },
]
self.route['exclude'] = 'something'
self.route['format'] = 'dunno'
self.route['lang'] = 'fr'
def test_to_api_query(self):
"""MMRoute.to_api_query() should return query string for API request."""
qs = { 'qs_1': 'w1', 'countryCode_1': 'GB', 'qs_2': 'w2', 'countryCode_2': 'GB', 'mode': 'walking', 'optimizeFor': 'distance', 'optimizeIntermediates': 'true', 'emissions': 'true', 'custom_name_1': 'car', 'custom_value_1': '23', 'custom_unit_1': 'mpg_imp', 'custom_type_1': 'gas', 'custom_name_2': 'truck', 'custom_value_2': '34', 'custom_unit_2': 'mpg_imp', 'custom_type_2': 'gas', 'custom_name_3': 'van', 'custom_value_3': '89', 'custom_unit_3': 'mpg', 'custom_type_3': 'diesel', 'exclude': 'something', 'format': 'dunno', 'lang': 'fr' }
self.assertEqual(self.route.to_api_query(), qs)
class testMMRouteRequester(unittest.TestCase):
"""Tests routing results for various qs strings."""
def setUp(self):
self.router = MMRouteRequester( DEV_KEY )
def test_route(self):
"""MMRouteRequester.request() should return route response object with route result, and correct structure, types and values"""
location_1 = MMLocation( MMAddress(qs='w1', country_code='GB') )
location_2 = MMLocation( MMAddress(qs='w2', country_code='GB') )
route = MMRoute( [location_1, location_2 ] )
result = self.router.request(route)
self.assertTrue(result['copyright'])
self.assertTrue(result['disclaimer'])
self.assertTrue(result['stages'])
self.assertTrue(type(result['stages'][0]['start_point']) is MMLatLon)
self.assertTrue(type(result['stages'][0]['end_point']) is MMLatLon)
self.assertTrue(type(result['stages'][0]['steps'][0]['start_point']) is MMLatLon)
self.assertTrue(type(result['stages'][0]['steps'][0]['end_point']) is MMLatLon)
def test_disambiguation(self):
"""MMRouteRequester.request() should return route response object with disamgiguation result and not found result, and correct structure, types and values"""
location_1 = MMLocation( MMAddress(qs='herebedragons', country_code='GB') )
location_2 = MMLocation( MMAddress(qs='sutton', country_code='GB') )
route = MMRoute( [location_1, location_2 ] )
result = self.router.request(route)
self.assertEquals(result['errors'][0]['action'], 'geocode')
self.assertEquals(result['errors'][0]['error_code'], 'MM_GEOCODE_NO_MATCHES' )
self.assertEquals(int(result['errors'][0]['input_id']), 1)
self.assertEquals(len(result['errors'][0]['results']), 0)
self.assertTrue(type(result['errors'][0]['address']) is MMAddress)
self.assertEquals(result['errors'][1]['action'], 'geocode')
self.assertEquals(result['errors'][1]['error_code'], 'MM_GEOCODE_MULTIPLE_MATCHES' )
self.assertEquals(int(result['errors'][1]['input_id']), 2)
self.assertTrue(len(result['errors'][1]['results']) > 0)
self.assertTrue(type(result['errors'][1]['results'][0]) is MMLocation)
class testSearchRequester(unittest.TestCase):
"""Instantiate a MMSearchRequester object and a sample search object."""
def setUp(self):
self.searcher = MMSearchRequester( DEV_KEY )
self.search = MMSearch()
self.search['point'] = MMLatLon(LAT, LON)
self.search['data_source'] = DS_1
self.search['count'] = COUNT
def test_search_success(self):
"""MMSearchRequester.search() should return a search response with record_set and correct structure"""
result = self.searcher.search( self.search )
self.assertTrue(result['record_sets'][DS_1]['records'])
def test_search_no_results(self):
"""MMSearchRequester.search() should return total_record_count of 0"""
self.search['point'] = MMLatLon('here', 'dragons')
result = self.searcher.search( self.search )
self.assertEqual(result['record_sets'][DS_1]['total_record_count'], 0)
def test_search_bad_datasource(self):
"""MMSearchRequester.search() should return a MM_API_ERROR_DATA_SOURCE_NOT_PROVISIONED error"""
self.search['data_source'] = DS_BAD
result = self.searcher.search( self.search )
self.assertEqual(result['record_sets'][DS_BAD]['error']['error_code'], 'MM_API_ERROR_DATA_SOURCE_NOT_PROVISIONED')
class testSearch(unittest.TestCase):
"""Test search objects and methods"""
def setUp(self):
"""Instantiate a MMSearch object and set some properties on it. Create a filter for use in some filter tests."""
self.search = MMSearch()
self.search['point'] = MMLatLon(LAT,LON)
self.search['data_source'] = DS_1
self.search['count'] = COUNT
self.filter = MMSearchFilter(FIELDNAME, OPERATOR, VALUE, OPTIONS)
def test_to_api_query(self):
"""MMSearch.to_api_query() should return query string for API request."""
qs = { 'dataSource': DS_1, 'count': str(COUNT), 'lat': str(LAT), 'lon': str(LON) }
self.assertEqual(self.search.to_api_query(), qs)
def test_to_api_query_with_postfix(self):
"""MMSearch.to_api_query() should return query string for API request including arg_[COUNTER]."""
qs = { 'dataSource_3': DS_1, 'count_3': str(COUNT), 'lat_3': str(LAT), 'lon_3': str(LON) }
self.assertEqual(self.search.to_api_query(3), qs)
def test_to_api_query_with_filter(self):
"""MMSearch.to_api_query() should return query string for API request including filter."""
self.search['filters'] = [self.filter]
qs = { 'dataSource': DS_1, 'count': str(COUNT), 'lat': str(LAT), 'lon': str(LON), 'fieldname_1': FIELDNAME, 'operator_1': OPERATOR, 'value_1': VALUE, 'fieldFilterOptions_1': ','.join( OPTIONS ) }
self.assertEqual(self.search.to_api_query(), qs)
def test_to_api_query_with_multiple_filters(self):
"""MMSearch.to_api_query() should return query string for API request including multiple filters."""
self.search['filters'] = [self.filter, self.filter]
qs = { 'dataSource': DS_1, 'count': str(COUNT), 'lat': str(LAT), 'lon': str(LON), 'fieldname_1': FIELDNAME, 'operator_1': OPERATOR, 'value_1': VALUE, 'fieldFilterOptions_1': ','.join( OPTIONS ), 'fieldname_2': FIELDNAME, 'operator_2': OPERATOR, 'value_2': VALUE, 'fieldFilterOptions_2': ','.join( OPTIONS ) }
self.assertEqual(self.search.to_api_query(), qs)
def test_to_api_query_with_bounding_box(self):
"""MMSearch.to_api_query() should return query string for API request including bounding box."""
self.search['bounding_box'] = MMBounds(MMLatLon( -10.0, -10.0 ), MMLatLon( 10.0, 10.0 ))
qs = { 'dataSource': DS_1, 'count': str(COUNT), 'bb': '-10.0,-10.0;10.0,10.0', 'lat': str(LAT), 'lon': str(LON) }
self.assertEqual(self.search.to_api_query(), qs)
def test_to_api_query_with_route(self):
"""MMSearch.to_api_query() should return query string for API request including route."""
location_1 = MMLocation( MMAddress(qs='w1', country_code='GB') )
location_2 = MMLocation( MMAddress(qs='w2', country_code='GB') )
self.search['route'] = MMRoute( [location_1, location_2 ])
qs = {'dataSource': DS_1, 'count': str(COUNT), 'lat': str(LAT), 'lon': str(LON), 'qs_1': 'w1', 'countryCode_1': 'GB', 'qs_2': 'w2', 'countryCode_2': 'GB' }
self.assertEqual(self.search.to_api_query(), qs)
class testSearchFilter(unittest.TestCase):
"""Tests search filter objects and methods."""
def setUp(self):
"""Instantiate a MMSearchFilter object with some default args."""
self.filter = MMSearchFilter(FIELDNAME, OPERATOR, VALUE, OPTIONS)
def test_to_api_query(self):
"""MMSearchFilter.to_api_query() should return query string for API request."""
qs = {'fieldname': FIELDNAME, 'operator': OPERATOR, 'value': VALUE, 'fieldFilterOptions': ','.join( OPTIONS ) }
self.assertEqual(self.filter.to_api_query(), qs)
def test_to_api_query_with_postfix(self):
"""MMSearchFilter.to_api_query(3) should return query string for API request including arg_[COUNTER]."""
qs = {'fieldname_3': FIELDNAME, 'operator_3': OPERATOR, 'value_3': VALUE, 'fieldFilterOptions_3': ','.join( OPTIONS ) }
self.assertEqual(self.filter.to_api_query(3), qs)
if __name__ == '__main__':
unittest.main()
#suiteFew = unittest.TestSuite()
#suiteFew.addTest(testGeocoder("testLondon"))
#unittest.TextTestRunner(verbosity=2).run(suiteFew)
#unittest.TextTestRunner(verbosity=2).run(suite())