-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlib_test.py
574 lines (489 loc) · 21.5 KB
/
lib_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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
import platform
from pkg_resources import get_distribution
import mock
import numpy as np
from groclient import lib
from groclient.utils import dict_assign
from groclient.constants import DATA_SERIES_UNIQUE_TYPES_ID
MOCK_HOST = 'pytest.groclient.url'
MOCK_TOKEN = 'pytest.groclient.token'
LOOKUP_MAP = {
'metrics': {
'1': {'id': 1, 'name': 'metric 1', 'contains': [], 'belongsTo': [3], 'definition': 'def1'},
'2': {'id': 2, 'name': 'metric 2', 'contains': [], 'belongsTo': [3], 'definition': 'def2'},
'3': {'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'},
'4': {'id': 4, 'name': 'ancestor', 'contains': [3], 'belongsTo': [], 'definition': 'def4'}
},
'items': {
'1': {'id': 1, 'name': 'item 1', 'contains': [], 'belongsTo': [3], 'definition': 'def1'},
'2': {'id': 2, 'name': 'item 2', 'contains': [], 'belongsTo': [3], 'definition': 'def2'},
'3': {'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'},
'4': {'id': 4, 'name': 'ancestor', 'contains': [3], 'belongsTo': [], 'definition': 'def4'}
},
'regions': {
'1': {'id': 1, 'name': 'region 1', 'contains': [], 'belongsTo': [3], 'historical': True},
'2': {'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False},
'3': {'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'historical': False},
'4': {'id': 4, 'name': 'ancestor', 'contains': [3], 'belongsTo': [], 'historical': False}
},
'frequencies': {},
'sources': {},
'units': {}
}
def initialize_requests_mocker_and_get_mock_data(mock_requests_get, mock_data={
'data': [
{'name': 'obj1'},
{'name': 'obj2'},
{'name': 'obj3'}
]}
):
mock_requests_get.return_value.json.return_value = mock_data
mock_requests_get.return_value.status_code = 200
return mock_data
@mock.patch('requests.get')
def test_get_available(mock_requests_get):
mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
# Test data
entity_types = ['items', 'metrics', 'regions']
for ent_type in entity_types:
assert lib.get_available(MOCK_TOKEN, MOCK_HOST, ent_type) == mock_data['data']
@mock.patch('requests.get')
def test_list_available(mock_requests_get):
# Tests the base functionality
mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
entities = {'metricId': '123', 'itemId': '456', 'regionId': '789'}
assert lib.list_available(MOCK_TOKEN, MOCK_HOST, entities) == mock_data['data']
@mock.patch('requests.get')
def test_list_available_snake_to_camel(mock_requests_get):
# Tests that the camel-ing fix is working properly.
mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
entities = {'metric_id': '123', 'item_id': '456', 'regionId': '789'}
assert lib.list_available(MOCK_TOKEN, MOCK_HOST, entities) == mock_data['data']
@mock.patch('requests.get')
def test_single_lookup(mock_requests_get):
api_response = {
'data': {
'12345': {
'id': 12345,
'name': 'Vegetables',
'contains': [67890],
'belongsTo': []
}
}
}
initialize_requests_mocker_and_get_mock_data(mock_requests_get, api_response)
expected_return = {'id': 12345, 'name': 'Vegetables', 'contains': [67890], 'belongsTo': []}
assert lib.lookup(MOCK_TOKEN, MOCK_HOST, 'items', 12345) == expected_return
@mock.patch('requests.get')
def test_multiple_lookups(mock_requests_get):
api_response = {
'data': {
'12345': {'id': 12345, 'name': 'Vegetables', 'contains': [67890], 'belongsTo': []},
'67890': {'id': 67890, 'name': 'Eggplant', 'contains': [], 'belongsTo': [12345]}
}
}
initialize_requests_mocker_and_get_mock_data(mock_requests_get, api_response)
expected_return = {
'12345': {'id': 12345, 'name': 'Vegetables', 'contains': [67890], 'belongsTo': []},
'67890': {'id': 67890, 'name': 'Eggplant', 'contains': [], 'belongsTo': [12345]}
}
assert lib.lookup(MOCK_TOKEN, MOCK_HOST, 'items', [12345, 67890]) == expected_return
@mock.patch('requests.get')
def test_lookup_with_numpy(mock_requests_get):
api_response = {
'data': {
'12345': {'id': 12345, 'name': 'Vegetables', 'contains': [67890], 'belongsTo': []},
'67890': {'id': 67890, 'name': 'Eggplant', 'contains': [], 'belongsTo': [12345]}
}
}
initialize_requests_mocker_and_get_mock_data(mock_requests_get, api_response)
expected_return = {
'12345': {'id': 12345, 'name': 'Vegetables', 'contains': [67890], 'belongsTo': []},
'67890': {'id': 67890, 'name': 'Eggplant', 'contains': [], 'belongsTo': [12345]}
}
assert lib.lookup(MOCK_TOKEN, MOCK_HOST, 'items', np.array([12345, 67890])) == expected_return
assert lib.lookup(MOCK_TOKEN, MOCK_HOST, 'items',
np.array([12345])[0]) == expected_return['12345']
@mock.patch('requests.get')
def test_get_data_series(mock_requests_get):
# Test general case
mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
selection_dict = {'item_id': 123, 'metric_id': 456, 'region_id': 789,
'partner_region_id': 161718, 'frequency_id': 101112, 'source_id': 12}
assert lib.get_data_series(MOCK_TOKEN, MOCK_HOST, **selection_dict) == mock_data['data']
@mock.patch('requests.get')
def test_get_data_points(mock_requests_get):
list_of_series_format_data = [{
'series': {},
'data': [['2000-01-01', '2000-12-31', 1, None, 15, None, '2001-12-31']]
}]
single_series_format_data = [{
'start_date': '2000-01-01',
'end_date': '2000-12-31',
'value': 1,
'unit_id': 15,
'input_unit_id': 15,
'input_unit_scale': 1,
'reporting_date': None,
'available_date':'2001-12-31',
'metric_id': None,
'item_id': None,
'metadata': {},
'region_id': None,
'partner_region_id': 0,
'frequency_id': None,
# 'source_id': None, TODO: add source to output
}]
initialize_requests_mocker_and_get_mock_data(mock_requests_get,
mock_data=list_of_series_format_data)
# Test data
selection_dict = {'item_id': 123, 'metric_id': 456, 'region_id': 789,
'frequency_id': 101112, 'source_id': 131415, 'partner_region_id': 161718}
assert lib.get_data_points(MOCK_TOKEN, MOCK_HOST, **selection_dict) == single_series_format_data
def test_list_of_series_to_single_series():
assert lib.list_of_series_to_single_series([{
'series': {
'metricId': 1,
'itemId': 2,
'regionId': 3,
'unitId': 4,
'inputUnitId': 5,
'belongsTo': {'itemId': 22},
'metadata': {'includesHistoricalRegion': True}
},
'data': [
['2001-01-01', '2001-12-31', 123],
['2002-01-01', '2002-12-31', 123, '2012-01-01', 15, None, '2003-01-01'],
['2002-01-01', '2002-12-31', 123, None, 15, None, '2003-01-01'],
['2003-01-01', '2003-12-31', 123, None, 15, {'confInterval': 2}, '2004-01-01']
]
}], add_belongs_to=True) == [
{'start_date': '2001-01-01',
'end_date': '2001-12-31',
'value': 123,
'unit_id': 4,
'metadata': {},
'input_unit_id': 4,
'input_unit_scale': 1,
'reporting_date': None,
'available_date': None,
'metric_id': 1,
'item_id': 2,
'region_id': 3,
'partner_region_id': 0,
'frequency_id': None,
'belongs_to': {'item_id': 22}},
{'start_date': '2002-01-01',
'end_date': '2002-12-31',
'value': 123,
'unit_id': 15,
'metadata': {},
'input_unit_id': 15,
'input_unit_scale': 1,
'reporting_date': '2012-01-01',
'available_date': '2003-01-01',
'metric_id': 1,
'item_id': 2,
'region_id': 3,
'partner_region_id': 0,
'frequency_id': None,
'belongs_to': {'item_id': 22}},
{'start_date': '2002-01-01',
'end_date': '2002-12-31',
'value': 123,
'unit_id': 15,
'metadata': {},
'input_unit_id': 15,
'input_unit_scale': 1,
'reporting_date': None,
'available_date': '2003-01-01',
'metric_id': 1,
'item_id': 2,
'region_id': 3,
'partner_region_id': 0,
'frequency_id': None,
'belongs_to': {'item_id': 22}},
{'start_date': '2003-01-01',
'end_date': '2003-12-31',
'value': 123,
'unit_id': 15,
'metadata': {'conf_interval': 2},
'input_unit_id': 15,
'input_unit_scale': 1,
'reporting_date': None,
'available_date': '2004-01-01',
'metric_id': 1,
'item_id': 2,
'region_id': 3,
'partner_region_id': 0,
'frequency_id': None,
'belongs_to': {'item_id': 22}},
]
# test the add_belongs_to kwarg:
assert 'belongs_to' in lib.list_of_series_to_single_series([{
'series': {'unitId': 4, 'belongsTo': {'itemId': 22}},
'data': [['2001-01-01', '2001-12-31', 123]]
}], add_belongs_to=True)[0]
assert 'belongs_to' not in lib.list_of_series_to_single_series([{
'series': {'unitId': 4, 'belongsTo': {'itemId': 22}},
'data': [['2001-01-01', '2001-12-31', 123]]
}], add_belongs_to=False)[0]
# test the include_historical kwarg:
assert len(lib.list_of_series_to_single_series([{
'series': {'unitId': 4, 'belongsTo': {'itemId': 22}, 'metadata': {'includesHistoricalRegion': True}},
'data': [['2001-01-01', '2001-12-31', 123]]
}], include_historical=False)) == 0
assert len(lib.list_of_series_to_single_series([{
'series': {'unitId': 4, 'belongsTo': {'itemId': 22}, 'metadata': {'includesHistoricalRegion': True}},
'data': [['2001-01-01', '2001-12-31', 123]]
}], include_historical=True)) == 1
# test invalid input propagation
assert lib.list_of_series_to_single_series('test input') == 'test input'
@mock.patch('requests.get')
def test_search(mock_requests_get):
mock_data = ['obj1', 'obj2', 'obj3']
mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get, mock_data=mock_data)
assert lib.search(MOCK_TOKEN, MOCK_HOST, 'items', 'test123') == mock_data
@mock.patch('groclient.lib.lookup')
@mock.patch('groclient.lib.search')
def test_search_and_lookup(search_mocked, lookup_mocked):
# Set up
# mock return values
search_mocked.return_value = [{'id': 1}, {'id': 2}]
lookup_mocked.side_effect = lookup_mock
search_and_lookup_result = list(lib.search_and_lookup(MOCK_TOKEN, MOCK_HOST,
'regions', 'test123'))
assert search_and_lookup_result == [
LOOKUP_MAP['regions']['1'],
LOOKUP_MAP['regions']['2']
]
@mock.patch('groclient.lib.lookup')
@mock.patch('requests.get')
def test_lookup_belongs(mock_requests_get, lookup_mocked):
mock_requests_get.return_value.json.return_value = {'data': {'1': [3]}}
mock_requests_get.return_value.status_code = 200
lookup_mocked.side_effect = lookup_mock
lookup_belongs_result = list(lib.lookup_belongs(MOCK_TOKEN, MOCK_HOST, 'regions', 1))
assert lookup_belongs_result == [LOOKUP_MAP['regions']['3']]
@mock.patch('requests.get')
def test_get_source_ranking(mock_requests_get):
mock_return = [60, 14, 2, 1]
mock_requests_get.return_value.json.return_value = mock_return
mock_requests_get.return_value.status_code = 200
query_parameters = {'item_id': 1, 'metric_id': 2, 'region_id': 3, 'frequency_id': 4}
ranked_sources_list = lib.get_source_ranking(MOCK_TOKEN, MOCK_HOST, query_parameters)
assert len(ranked_sources_list) == 4
@mock.patch('requests.get')
def test_rank_series_by_source(mock_requests_get):
# for each series selection, mock ranking of 3 source ids
mock_return = [11, 123, 33]
mock_requests_get.return_value.json.return_value = mock_return
mock_requests_get.return_value.status_code = 200
full_data_series = {
'metric_id': 2540047,
'item_id': 3457,
'region_id': 13474,
'partner_region_id': 56789,
'source_id': 123,
'source_name': 'dontcare',
'frequency_id': 9,
'start_date': '2020-01-01',
'end_date': '2020-05-01',
'metadata': {'historical': True}
}
# input selection should allow a list of ids
partial_selection = {
'metric_id': 2540047,
'item_id': 1457,
'region_id': [13474,13475]
}
expected = [
full_data_series,
dict_assign(partial_selection, 'source_id', mock_return[0]),
dict_assign(partial_selection, 'source_id', mock_return[1]),
dict_assign(partial_selection, 'source_id', mock_return[2])
]
for idx, series in enumerate(lib.rank_series_by_source(MOCK_TOKEN,
MOCK_HOST,
[full_data_series,
partial_selection])):
assert series == expected[idx]
def lookup_mock(MOCK_TOKEN, MOCK_HOST, entity_type, entity_ids):
if isinstance(entity_ids, int):
return LOOKUP_MAP[entity_type][str(entity_ids)]
if isinstance(entity_ids, list):
return {str(entity_id): LOOKUP_MAP[entity_type][str(entity_id)]
for entity_id in entity_ids}
@mock.patch('groclient.lib.lookup')
@mock.patch('requests.get')
def test_get_ancestor(mock_requests_get, lookup_mocked):
mock_requests_get.return_value.json.return_value = {'data': {'1': [3, 4]}}
mock_requests_get.return_value.status_code = 200
lookup_mocked.side_effect = lookup_mock
assert lib.get_ancestor(MOCK_TOKEN, MOCK_HOST, 'items', 1) == [
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'},
{'id': 4, 'name': 'ancestor', 'contains': [3], 'belongsTo': [], 'definition': 'def4'}
]
assert lib.get_ancestor(MOCK_TOKEN, MOCK_HOST, 'metrics', 1, include_details=True) == [
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'},
{'id': 4, 'name': 'ancestor', 'contains': [3], 'belongsTo': [], 'definition': 'def4'}
]
assert lib.get_ancestor(MOCK_TOKEN, MOCK_HOST, 'items', 1, include_details=False) == [
{'id': 3},
{'id': 4}
]
assert lib.get_ancestor(MOCK_TOKEN, MOCK_HOST, 'metrics', 1, include_details=True) == [
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'},
{'id': 4, 'name': 'ancestor', 'contains': [3], 'belongsTo': [], 'definition': 'def4'}
]
mock_requests_get.return_value.json.return_value = {'data': {'2': [3]}}
assert lib.get_ancestor(MOCK_TOKEN, MOCK_HOST, 'items', 2, distance=1) == [
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'}
]
@mock.patch('groclient.lib.lookup')
@mock.patch('requests.get')
def test_get_descendant(mock_requests_get, lookup_mocked):
mock_requests_get.return_value.json.return_value = {'data': {'4': [1, 2, 3]}}
mock_requests_get.return_value.status_code = 200
lookup_mocked.side_effect = lookup_mock
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'items', 4) == [
{'id': 1, 'name': 'item 1', 'contains': [], 'belongsTo': [3], 'definition': 'def1'},
{'id': 2, 'name': 'item 2', 'contains': [], 'belongsTo': [3], 'definition': 'def2'},
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'}
]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'metrics', 4, include_details=True) == [
{'id': 1, 'name': 'metric 1', 'contains': [], 'belongsTo': [3], 'definition': 'def1'},
{'id': 2, 'name': 'metric 2', 'contains': [], 'belongsTo': [3], 'definition': 'def2'},
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'}
]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'items', 4, include_details=False) == [
{'id': 1}, {'id': 2}, {'id': 3}
]
mock_requests_get.return_value.json.return_value = {'data': {'4': [3]}}
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'items', 4, distance=1) == [
{'id': 3, 'name': 'parent', 'contains': [1, 2], 'belongsTo': [4], 'definition': 'def3'}
]
mock_requests_get.return_value.json.return_value = {'data': {'3': [1, 2]}}
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3) == [
{'id': 1, 'name': 'region 1', 'contains': [], 'belongsTo': [3], 'historical': True},
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_details=True) == [
{'id': 1, 'name': 'region 1', 'contains': [], 'belongsTo': [3], 'historical': True},
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_details=False) == [
{'id': 1}, {'id': 2}
]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_historical=True) == [
{'id': 1, 'name': 'region 1', 'contains': [], 'belongsTo': [3], 'historical': True},
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3,
include_historical=True, include_details=True) == [
{'id': 1, 'name': 'region 1', 'contains': [], 'belongsTo': [3], 'historical': True},
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]
mock_requests_get.return_value.json.return_value = {'data': {'3': [2]}}
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_historical=False,
include_details=False) == [{'id': 2}]
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_historical=False,
include_details=True) == [
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]
@mock.patch('requests.get')
def test_get_top(mock_requests_get):
mock_response = [
{'itemId': 274, 'value': 13175206696, 'unitId': 14},
{'itemId': 574, 'value': 13175206878, 'unitId': 14},
{'itemId': 7193, 'value': 13175206343, 'unitId': 14}
]
mock_requests_get.return_value.json.return_value = mock_response
mock_requests_get.return_value.status_code = 200
assert lib.get_top(MOCK_TOKEN, MOCK_HOST, 'items', metric_id=14) == mock_response
assert lib.get_top(MOCK_TOKEN, MOCK_HOST, 'items', num_results=3, metric_id=14) == mock_response
@mock.patch('requests.get')
def test_get_geo_centre(mock_requests_get):
US_data = {
"regionId": 1215,
"regionName": "United States",
"centre": [
39.8333,
-98.5855
]
}
api_response = {
'data': [US_data]
}
initialize_requests_mocker_and_get_mock_data(mock_requests_get, api_response)
assert lib.get_geo_centre(MOCK_TOKEN, MOCK_HOST, 1215) == [US_data]
@mock.patch('requests.get')
def test_get_geo_jsons(mock_requests_get):
api_response = {
'data': [{
"regionId": 13051,
"regionName": "Alabama",
"centre": [
32.7933,
-86.8278
],
"geojson": {
"type": "MultiPolygon",
"coordinates": [[[[ -88.201896667, 35.0088806150001]]]]
}
},
{
"regionId": 13052,
"regionName": "Alaska",
"centre": [
64.2386,
-152.279
],
"geojson": {
"type": "MultiPolygon",
"coordinates": [[[[ -179.07043457, 51.2564086920001]]]]
}
}]
}
expected_return = [{
"region_id": 13051,
"region_name": "Alabama",
"centre": [
32.7933,
-86.8278
],
"geojson": {
"type": "MultiPolygon",
"coordinates": [[[[ -88.201896667, 35.0088806150001]]]]
}
},
{
"region_id": 13052,
"region_name": "Alaska",
"centre": [
64.2386,
-152.279
],
"geojson": {
"type": "MultiPolygon",
"coordinates": [[[[ -179.07043457, 51.2564086920001]]]]
}
}]
initialize_requests_mocker_and_get_mock_data(mock_requests_get, api_response)
assert lib.get_geojsons(MOCK_TOKEN, MOCK_HOST, 1215, None, 7) == expected_return
@mock.patch('groclient.lib.get_geojsons')
def test_get_geo_json(geojsons_mocked):
geojsons_mocked.return_value = [{
"region_id": 1215,
"region_name": "United States",
"centre": [
39.8333,
-98.5855
],
"geojson": "{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-155.651382446,20.1647224430001]]]]}]}"
}]
expected_return = {
'type': 'GeometryCollection',
'geometries': [{'type': 'MultiPolygon', 'coordinates': [[[[-155.651382446, 20.1647224430001]]]]}]
}
assert lib.get_geojson(MOCK_TOKEN, MOCK_HOST, 1215, 7) == expected_return