Skip to content

Commit ee81694

Browse files
authored
Merge pull request #67 from kbevers/compare-apis
Add script for comparing to deployed versions of the API
2 parents ff6476e + 76d542a commit ee81694

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

scripts/compare_apis.py

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""
2+
Script for comparing API deployed in test and prod.
3+
4+
The old Flask-based API includes whitespace and trailing newline in the response.
5+
We knowingly strip that for the sake of comparison. If this affects users, they're
6+
parsing the data in a bad way.
7+
If necessary, the old ways can be introduced in FastAPI as well using a response_class.
8+
9+
For more, see:
10+
https://stackoverflow.com/questions/67783530/is-there-a-way-to-pretty-print-prettify-a-json-response-in-fastapi
11+
"""
12+
import json
13+
14+
import requests
15+
16+
TOKEN = "8051bfcbe3b04250f4239d7379eb5a52"
17+
18+
URL_TEST = "https://api.dataforsyningen.dk/rest/webproj_test/"
19+
URL_PROD = "https://api.dataforsyningen.dk/rest/webproj/"
20+
21+
TEST_CASES = [
22+
"v1.0/crs/",
23+
"v1.1/crs/",
24+
"v1.2/crs/",
25+
26+
"v1.0/crs/EPSG:4093",
27+
"v1.1/crs/EPSG:4093",
28+
"v1.2/crs/EPSG:4093",
29+
30+
"v1.0/trans/EPSG:4258/EPSG:25832/12.0,56.0",
31+
"v1.1/trans/EPSG:4258/EPSG:25832/12.0,56.0",
32+
"v1.2/trans/EPSG:4258/EPSG:25832/12.0,56.0",
33+
34+
"v1.0/trans/EPSG:4258/EPSG:25832/12.0,56.0,123.4",
35+
"v1.1/trans/EPSG:4258/EPSG:25832/12.0,56.0,123.4",
36+
"v1.2/trans/EPSG:4258/EPSG:25832/12.0,56.0,123.4",
37+
38+
"v1.0/trans/EPSG:4258/EPSG:25832/12.0,56.0,123.4,2024.5",
39+
"v1.1/trans/EPSG:4258/EPSG:25832/12.0,56.0,123.4,2024.5",
40+
"v1.2/trans/EPSG:4258/EPSG:25832/12.0,56.0,123.4,2024.5",
41+
42+
"v1.0/trans/EPSG:4230/DK:S34S/55.5190,11.83303",
43+
"v1.1/trans/EPSG:4230/DK:S34S/55.5190,11.83303",
44+
"v1.2/trans/EPSG:4230/DK:S34S/55.5190,11.83303",
45+
]
46+
47+
EXPECTED_FAILURES = [
48+
# Different version numbers of both PROJ and WEBPROJ
49+
"v1.2/info/",
50+
"v1.2/info",
51+
52+
# Area of use and bounding box are different due to changes in EPSG registry
53+
"v1.0/crs/EPSG:25832",
54+
"v1.1/crs/EPSG:25832",
55+
"v1.2/crs/EPSG:25832",
56+
57+
# Numerical differences in the vertical component at the centimeter level.
58+
# Caused by use of different DVR90 geoid models in different PROJ versions
59+
# in PROD and TEST
60+
"v1.0/trans/EPSG:4258+5799/EPSG:4230+5733/55.6581,11.5991,52.4",
61+
"v1.1/trans/EPSG:4258+5799/EPSG:4230+5733/55.6581,11.5991,52.4",
62+
"v1.2/trans/EPSG:4258+5799/EPSG:4230+5733/55.6581,11.5991,52.4",
63+
]
64+
65+
def run_test_case(test_case: str) -> bool:
66+
"""
67+
Perform a specific test case.
68+
"""
69+
r_test = requests.get(URL_TEST + test_case, params={"token": TOKEN})
70+
r_prod = requests.get(URL_PROD + test_case, params={"token": TOKEN})
71+
72+
try:
73+
json_test = r_test.json()
74+
except json.decoder.JSONDecodeError:
75+
json_prod = "JSON decoding error"
76+
77+
try:
78+
json_prod = r_prod.json()
79+
except json.decoder.JSONDecodeError:
80+
json_prod = "JSON decoding error"
81+
82+
test_result = json_test == json_prod
83+
84+
print(f"{test_case} {(test_result)}")
85+
86+
if not test_result:
87+
print("-"*25)
88+
print(json_prod)
89+
print("")
90+
print(json_test)
91+
print("-"*25)
92+
93+
return test_result
94+
95+
if __name__ == "__main__":
96+
for test_case in TEST_CASES:
97+
run_test_case(test_case)

0 commit comments

Comments
 (0)