/
test_main.py
132 lines (111 loc) · 3.96 KB
/
test_main.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
import pandas
import pytest
from up42 import main
from .fixtures import fixtures_globals as constants
@pytest.fixture(autouse=True)
def setup_auth_mock(auth_mock):
main._auth = auth_mock # pylint: disable=protected-access
yield
def test_get_blocks(requests_mock):
url_get_blocks = f"{constants.API_HOST}/blocks"
requests_mock.get(
url=url_get_blocks,
json={
"data": [
{"id": "789-2736-212", "name": "tiling"},
{"id": "789-2736-212", "name": "sharpening"},
],
"error": {},
},
)
blocks = main.get_blocks()
assert isinstance(blocks, dict)
assert "tiling" in list(blocks.keys())
def test_get_blocks_not_basic_dataframe(requests_mock):
url_get_blocks = f"{constants.API_HOST}/blocks"
json_get_blocks = {
"data": [
{"id": "789-2736-212", "name": "tiling"},
{"id": "789-2736-212", "name": "sharpening"},
],
"error": {},
}
requests_mock.get(url=url_get_blocks, json=json_get_blocks)
blocks_df = main.get_blocks(basic=False, as_dataframe=True)
assert isinstance(blocks_df, pandas.DataFrame)
assert "tiling" in blocks_df["name"].to_list()
def test_get_block_details(requests_mock):
block_id = "273612-13"
url_get_blocks_details = f"{constants.API_HOST}/blocks/{block_id}"
requests_mock.get(
url=url_get_blocks_details,
json={
"data": {"id": "273612-13", "name": "tiling", "createdAt": "123"},
"error": {},
},
)
details = main.get_block_details(block_id=block_id)
assert isinstance(details, dict)
assert details["id"] == block_id
assert "createdAt" in details
def test_get_block_coverage(requests_mock):
block_id = "273612-13"
url_get_blocks_coverage = f"{constants.API_HOST}/blocks/{block_id}/coverage"
requests_mock.get(
url=url_get_blocks_coverage,
json={
"data": {"url": "https://storage.googleapis.com/coverage-area-interstellar-prod/coverage.json"},
"error": {},
},
)
url_geojson_response = "https://storage.googleapis.com/coverage-area-interstellar-prod/coverage.json"
requests_mock.get(
url=url_geojson_response,
json={
"type": "FeatureCollection",
"name": "bundle6m",
"crs": {
"type": "name",
"properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"},
},
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {"type": "MultiPolygon", "coordinates": []},
}
],
},
)
coverage = main.get_block_coverage(block_id=block_id)
assert isinstance(coverage, dict)
assert "features" in coverage
def test_get_credits_balance():
balance = main.get_credits_balance()
assert isinstance(balance, dict)
assert "balance" in balance
def test_fails_to_get_auth_safely_if_unauthenticated():
main._auth = None # pylint: disable=protected-access
with pytest.raises(ValueError):
main.get_auth_safely()
def test_get_webhook_events(requests_mock):
url_webhook_events = f"{constants.API_HOST}/webhooks/events"
events = ["some-event"]
requests_mock.get(
url=url_webhook_events,
json={
"data": events,
"error": {},
},
)
assert main.get_webhook_events() == events
@pytest.mark.parametrize("return_json", [False, True])
def test_get_webhooks(webhooks_mock, return_json):
webhooks = main.get_webhooks(return_json=return_json)
expected = webhooks_mock.get_webhooks(return_json=return_json)
if return_json:
assert webhooks == expected
else:
for hook, expected_hook in zip(webhooks, expected):
assert hook.webhook_id == expected_hook.webhook_id
assert hook._info == expected_hook._info # pylint: disable=protected-access