forked from ExpDev07/coronavirus-tracker-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_populations.py
More file actions
77 lines (71 loc) · 2.02 KB
/
test_populations.py
File metadata and controls
77 lines (71 loc) · 2.02 KB
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
"""tests.test_populations.py"""
import pytest
import requests.exceptions
import responses
import app.io
import app.utils.populations
NOT_FOUND_HTML = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Not Found</pre>
</body>
</html>"""
SAMPLE_GEONAMES_JSON = {
"geonames": [
{
"continent": "EU",
"capital": "Andorra la Vella",
"languages": "ca",
"geonameId": 3041565,
"south": 42.42874300100004,
"isoAlpha3": "AND",
"north": 42.65576500000003,
"fipsCode": "AN",
"population": "77006",
"east": 1.786576000000025,
"isoNumeric": "020",
"areaInSqKm": "468.0",
"countryCode": "AD",
"west": 1.413760001000071,
"countryName": "Andorra",
"continentName": "Europe",
"currencyCode": "EUR",
},
{
"continent": "AS",
"capital": "Abu Dhabi",
"languages": "ar-AE,fa,en,hi,ur",
"geonameId": 290557,
"south": 22.6315119400001,
"isoAlpha3": "ARE",
"north": 26.0693916590001,
"fipsCode": "AE",
"population": "9630959",
"east": 56.381222289,
"isoNumeric": "784",
"areaInSqKm": "82880.0",
"countryCode": "AE",
"west": 51.5904085340001,
"countryName": "United Arab Emirates",
"continentName": "Asia",
"currencyCode": "AED",
},
]
}
@responses.activate
@pytest.mark.parametrize(
"body_arg, json_arg",
[
(None, SAMPLE_GEONAMES_JSON),
(NOT_FOUND_HTML, None),
(None, {"foo": "bar"}),
(requests.exceptions.Timeout("Forced Timeout"), None),
],
)
def test_fetch_populations(body_arg, json_arg):
responses.add(responses.GET, app.utils.populations.GEONAMES_URL, body=body_arg, json=json_arg)
assert app.utils.populations.fetch_populations()