1
1
from fastapi .testclient import TestClient
2
2
from main import app
3
- from unittest .mock import patch
4
3
import json
5
4
6
5
# Create a test client for the FastAPI app
@@ -15,7 +14,6 @@ def test_search_issues(s3_bucket):
15
14
"limit" : 10 ,
16
15
}
17
16
18
- # Test the function that interacts with DuckDB and S3 via LocalStack
19
17
response = client .get ("/log/issue" , params = params )
20
18
21
19
# Validate the results from the search
@@ -75,15 +73,14 @@ def test_provision_summary(s3_bucket):
75
73
), "Expected active endpoint count to be 1"
76
74
77
75
78
- def test_specification (s3_bucket , duckdb_connection ):
76
+ def test_specification (s3_bucket ):
79
77
# Prepare test params
80
78
params = {
81
79
"offset" : 0 ,
82
80
"limit" : 8 ,
83
81
}
84
82
85
- with patch ("db.duckdb.connect" , return_value = duckdb_connection ):
86
- response = client .get ("/specification/specification" , params = params )
83
+ response = client .get ("/specification/specification" , params = params )
87
84
88
85
# Validate the results from the search
89
86
assert response .status_code == 200
@@ -96,16 +93,15 @@ def test_specification(s3_bucket, duckdb_connection):
96
93
assert len (response_data ) > 0
97
94
98
95
99
- def test_specification_with_dataset (s3_bucket , duckdb_connection ):
96
+ def test_specification_with_dataset (s3_bucket ):
100
97
# Prepare test params
101
98
params = {
102
99
"offset" : 0 ,
103
100
"limit" : 8 ,
104
101
"dataset" : "article-4-direction-area" ,
105
102
}
106
103
107
- with patch ("db.duckdb.connect" , return_value = duckdb_connection ):
108
- response = client .get ("/specification/specification" , params = params )
104
+ response = client .get ("/specification/specification" , params = params )
109
105
110
106
# Validate the results from the search
111
107
assert response .status_code == 200
@@ -138,7 +134,6 @@ def test_issue_type_summary(s3_bucket):
138
134
assert "X-Pagination-Total-Results" in response .headers
139
135
assert response .headers ["X-Pagination-Total-Results" ] == str (11 )
140
136
assert response .headers ["X-Pagination-Limit" ] == "8"
141
-
142
137
assert len (response_data ) > 0
143
138
filtered_rows = [
144
139
item
@@ -147,7 +142,62 @@ def test_issue_type_summary(s3_bucket):
147
142
== "8c61c7b72902daeaaa462002e62d840ce3916defacd54db97986654b180ce250"
148
143
]
149
144
150
- assert len (filtered_rows ) == 5
145
+ assert len (filtered_rows ) == 6
146
+ assert sum (1 for item in filtered_rows if item .get ("issue_type" ) == "patch" ) == 4
147
+ assert (
148
+ sum (
149
+ item .get ("count_issues" )
150
+ for item in filtered_rows
151
+ if item .get ("issue_type" ) == "patch"
152
+ )
153
+ == 807
154
+ )
155
+
156
+
157
+ def test_dataset_resource_mapping (s3_bucket ):
158
+ # Prepare test params
159
+ params = {
160
+ "organisation" : "local-authority:BUC" ,
161
+ "dataset" : "article-4-direction-area" ,
162
+ "offset" : 0 ,
163
+ "limit" : 8 ,
164
+ }
165
+ response = client .get ("/performance/dataset_resource_mapping" , params = params )
166
+
167
+ # Validate the results from the search
168
+ assert response .status_code == 200
169
+
170
+ response_data = response .json ()
171
+ assert "X-Pagination-Total-Results" in response .headers
172
+ assert response .headers ["X-Pagination-Total-Results" ] == str (9 )
173
+ assert response .headers ["X-Pagination-Limit" ] == "8"
174
+ assert len (response_data ) > 0
175
+ assert response_data [0 ]["mapping_field" ] == "geometry"
176
+ assert (
177
+ response_data [0 ]["non_mapping_field" ]
178
+ == "start-date;entry-date;name;description;reference"
179
+ )
180
+
181
+
182
+ def test_endpoint_dataset_summary (s3_bucket ):
183
+ # Prepare test params
184
+ params = {
185
+ "organisation" : "local-authority:BUC" ,
186
+ "dataset" : "article-4-direction-area" ,
187
+ "offset" : 0 ,
188
+ "limit" : 10 ,
189
+ }
190
+ response = client .get ("/performance/endpoint_dataset_summary" , params = params )
191
+
192
+ # Validate the results from the search
193
+ assert response .status_code == 200
194
+
195
+ response_data = response .json ()
196
+ assert "X-Pagination-Total-Results" in response .headers
197
+ assert response .headers ["X-Pagination-Total-Results" ] == str (7 )
198
+ assert response .headers ["X-Pagination-Limit" ] == "10"
199
+ assert len (response_data ) > 0
151
200
assert (
152
- sum (1 for item in filtered_rows if item .get ("issue_type" ) == "patch" ) == 3
153
- ) # Ensure 3 have issue_type as "patch"
201
+ response_data [0 ]["endpoint" ]
202
+ == "01de81578391eab3a1fdc9fcb92e559aa0a0bf1aafc777905d680fc0e189811e"
203
+ )
0 commit comments