forked from CSIRO-enviro-informatics/loci-integration-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
51 lines (44 loc) · 2.11 KB
/
Copy pathtest_basic.py
File metadata and controls
51 lines (44 loc) · 2.11 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
import pytest
import json
import logging
logging.basicConfig(level=logging.DEBUG)
from app import create_app
data = []
with open('./loci-testdata/test_case_contains_result.json') as json_file:
json_data = json.load(json_file)
data = [{ "uri": aData[1], "test_data": aData[2], "test_name": aData[0]} for aData in json_data]
@pytest.yield_fixture
def app():
yield create_app()
@pytest.fixture
def test_cli(loop, sanic_client, app):
return loop.run_until_complete(sanic_client(app))
async def test_index(test_cli):
resp = await test_cli.get('/')
assert resp.status == 200
@pytest.mark.parametrize("get_data", data)
async def test_overlaps_within(test_cli, get_data):
aUri = get_data["uri"]
test_name = get_data["test_name"]
logging.debug("Test Name {}".format(test_name))
resp = await test_cli.get('/api/v1/location/overlaps?uri={}&areas=false&proportion=true&contains=true&within=false&count=1000000&offset=0'.format(aUri))
result_dict = await resp.json()
results_uris = { aResult["uri"]: aResult for aResult in result_dict["overlaps"] }
for expected_result in get_data["test_data"]:
if not expected_result["toAreaDataset"] is None:
to_area = expected_result["toAreaDataset"]
result_uri = expected_result["to"]
else:
to_area = expected_result["toAreaLinkset"]
result_uri = expected_result["toParent"]
result_proportion = (float(to_area) / float(expected_result["fromAreaDataset"])) * 100
logging.debug("From Uri {}".format(expected_result["from"]))
logging.debug("To Uri {}".format(result_uri))
logging.debug("Expected Proportion {}".format(result_proportion))
assert result_uri in results_uris.keys()
logging.debug(results_uris[result_uri])
if "forwardPercentage" in results_uris[result_uri].keys():
returned_proportion = float(results_uris[result_uri]["forwardPercentage"])
logging.debug("Returned Proportion {}".format(returned_proportion))
assert returned_proportion == pytest.approx(result_proportion, 0.001)
assert resp.status == 200