-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
101 lines (69 loc) · 3.26 KB
/
tests.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
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
TEST_URL = 'https://st2.newmexicowaterdata.org/FROST-Server/v1.1'
def test_root():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Welcome to NMWDI Validation Service"}
def test_validate_locations():
response = client.get("/validate_locations", params={"url": TEST_URL})
assert response.status_code == 200
# assert response.json() == {"msg": "Hello World"}
def test_validate_n_locations():
response = client.get("/validate_locations", params={"url": TEST_URL, "n": 3})
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) == 3
def validate_n_things():
response = client.get("/validate_things", params={"url": TEST_URL, "n": 3})
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) == 3
def test_validate_location():
response = client.get("/validate_location", params={"url": f'{TEST_URL}/Locations(1)'})
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) == 1
def test_validate_location_bad_url():
response = client.get("/validate_location", params={"url": TEST_URL})
assert response.status_code == 200
assert response.json() == {"error": f"invalid url: {TEST_URL}"}
def test_validate_things():
response = client.get("/validate_things", params={"url": TEST_URL})
assert response.status_code == 200
#
def test_validate_thing():
response = client.get("/validate_thing", params={"url": f'{TEST_URL}/Things(1)'})
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) == 1
def test_validate_thing_bad_url():
response = client.get("/validate_thing", params={"url": TEST_URL})
assert response.status_code == 200
assert response.json() == {"error": f"invalid url: {TEST_URL}"}
# assert response.json() == {"msg": "Hello World"}
def test_validate_datastreams():
response = client.get("/validate_datastreams", params={"url": TEST_URL})
assert response.status_code == 200
def test_validate_datastream():
response = client.get("/validate_datastream", params={"url": f'{TEST_URL}/Datastreams(1)'})
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) == 1
def test_validate_datastream_bad_url():
response = client.get("/validate_datastream", params={"url": TEST_URL})
assert response.status_code == 200
assert response.json() == {"error": f"invalid url: {TEST_URL}"}
def test_validate_sensors():
response = client.get("/validate_sensors", params={"url": TEST_URL})
assert response.status_code == 200
def test_validate_sensor():
response = client.get("/validate_sensor", params={"url": f'{TEST_URL}/Sensors(1)'})
assert response.status_code == 200
assert isinstance(response.json(),list)
assert len(response.json()) == 1
def test_validate_sensor_bad_url():
response = client.get("/validate_sensor", params={"url": TEST_URL})
assert response.status_code == 200
assert response.json() == {"error": f"invalid url: {TEST_URL}"}