|
12 | 12 | INVALID_HOUSEHOLD_ID = "abc123" |
13 | 13 | INVALID_POLICY_ID = "invalid-id" |
14 | 14 | TEST_VARIABLE = "disposable_income" |
| 15 | +INVALID_VARIABLE = "123" |
15 | 16 |
|
16 | 17 |
|
17 | 18 | @patch("policyengine_api.services.tracer_analysis_service.local_database") |
@@ -181,3 +182,33 @@ def test_invalid_types(rest_client): |
181 | 182 | }, |
182 | 183 | ) |
183 | 184 | assert response.status_code == 400 |
| 185 | + |
| 186 | + |
| 187 | +def test_invalid_variable_type(rest_client): |
| 188 | + """Test that non-string variable is rejected""" |
| 189 | + response = rest_client.post( |
| 190 | + "/us/tracer-analysis", |
| 191 | + json={ |
| 192 | + "household_id": VALID_HOUSEHOLD_ID, |
| 193 | + "policy_id": VALID_POLICY_ID, |
| 194 | + "variable": 123, |
| 195 | + }, |
| 196 | + ) |
| 197 | + assert response.status_code == 400 |
| 198 | + assert "variable must be a string" in json.loads(response.data)["message"] |
| 199 | + |
| 200 | + |
| 201 | +def test_null_payload(rest_client): |
| 202 | + """Test that null payload is rejected""" |
| 203 | + response = rest_client.post( |
| 204 | + "/us/tracer-analysis", data="{}", content_type="application/json" |
| 205 | + ) |
| 206 | + assert response.status_code == 400 |
| 207 | + assert "No payload provided" in json.loads(response.data)["message"] |
| 208 | + |
| 209 | + |
| 210 | +def test_empty_payload(rest_client): |
| 211 | + """Test that empty payload is rejected""" |
| 212 | + response = rest_client.post("/us/tracer-analysis", json={}) |
| 213 | + assert response.status_code == 400 |
| 214 | + assert "No payload provided" in json.loads(response.data)["message"] |
0 commit comments