Skip to content

Commit e5f63de

Browse files
committed
Added tests to cover the code at lines 61 and 39 in the tracer_analysis_routes.py file.
1 parent d0384fa commit e5f63de

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/to_refactor/python/test_tracer_analysis_routes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
INVALID_HOUSEHOLD_ID = "abc123"
1313
INVALID_POLICY_ID = "invalid-id"
1414
TEST_VARIABLE = "disposable_income"
15+
INVALID_VARIABLE = "123"
1516

1617

1718
@patch("policyengine_api.services.tracer_analysis_service.local_database")
@@ -181,3 +182,33 @@ def test_invalid_types(rest_client):
181182
},
182183
)
183184
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

Comments
 (0)