-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
118 lines (90 loc) · 3.52 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
from fastapi.testclient import TestClient
from main import app
import json
# Create a test client for the FastAPI app
client = TestClient(app)
def test_search_issues(s3_bucket):
# Prepare test params
params = {
"dataset": "conservation-area",
"offset": 0,
"limit": 10,
}
# Test the function that interacts with DuckDB and S3 via LocalStack
response = client.get("/log/issue", params=params)
# Validate the results from the search
assert response.status_code == 200
response_data = response.json()
assert "X-Pagination-Total-Results" in response.headers
assert response.headers["X-Pagination-Total-Results"] == str(83)
assert len(response_data) > 0
assert response_data[0]["dataset"] == "conservation-area"
assert (
response_data[0]["resource"]
== "0b4284077da580a6daea59ee2227f9c7c55a9a45d57ef470d82418a4391ddf9a"
)
def test_search_issues_no_parameters():
# Prepare test params
params = {}
# Test the function that interacts with DuckDB and S3 via LocalStack
response = client.get("/log/issue", params=params)
response_json = json.loads(response.content.decode("utf-8"))
details = response_json.get("detail", [])
# Validate the results from the search
assert response.status_code == 400
assert any(
"The 'dataset' query parameter is required" in detail for detail in details
)
def test_provision_summary(s3_bucket):
# Prepare test params
params = {
"organisation": "local-authority:BDG",
"offset": 0,
"limit": 8,
}
response = client.get("/performance/provision_summary", params=params)
# Validate the results from the search
assert response.status_code == 200
response_data = response.json()
assert "X-Pagination-Total-Results" in response.headers
assert response.headers["X-Pagination-Total-Results"] == str(17)
assert response.headers["X-Pagination-Limit"] == "8"
assert len(response_data) > 0
assert response_data[0]["dataset"] == "article-4-direction"
for item in response_data:
if item.get("dataset") == "article-4-direction-area":
assert (
item.get("active_endpoint_count") == 1
), "Expected active endpoint count to be 1"
def test_specification(s3_bucket):
# Prepare test params
params = {
"offset": 0,
"limit": 8,
}
response = client.get("/specification/specification", params=params)
# Validate the results from the search
assert response.status_code == 200
response_data = response.json()
assert "X-Pagination-Total-Results" in response.headers
assert response.headers["X-Pagination-Total-Results"] == str(36)
assert response.headers["X-Pagination-Limit"] == "8"
assert len(response_data) > 0
def test_specification_with_dataset(s3_bucket):
# Prepare test params
params = {
"offset": 0,
"limit": 8,
"dataset": "article-4-direction-area",
}
response = client.get("/specification/specification", params=params)
# Validate the results from the search
assert response.status_code == 200
response_data = response.json()
assert "X-Pagination-Total-Results" in response.headers
assert response.headers["X-Pagination-Total-Results"] == str(1)
assert response.headers["X-Pagination-Limit"] == "8"
assert len(response_data) > 0
assert response_data[0]["dataset"] == "article-4-direction-area"
assert response_data[0]["fields"]
assert len(response_data[0]["fields"]) > 1