Skip to content

Commit

Permalink
json -> model_dump_json
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed Sep 4, 2024
1 parent bb43c36 commit a06b7f6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions tests/test_routes/api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create_subscription_detail(
role_assignments=role_assignments,
)
]
).json(),
).model_dump_json(),
headers={"authorization": "Bearer " + token},
)

Expand Down Expand Up @@ -177,6 +177,6 @@ def create_usage(

return client.post(
"usage/all-usage",
content=post_data.json(),
content=post_data.model_dump_json(),
headers={"authorization": "Bearer " + token},
)
6 changes: 3 additions & 3 deletions tests/test_routes/test_cost_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_cost_recovery_app_route(
recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
result = client.post(
PREFIX + "/app-cost-recovery",
content=recovery_period.json(),
content=recovery_period.model_dump_json(),
headers={"authorization": "Bearer " + token},
)

Expand Down Expand Up @@ -73,7 +73,7 @@ def test_cost_recovery_cli_route(
recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
result = client.post(
PREFIX + "/cli-cost-recovery",
content=recovery_period.json(),
content=recovery_period.model_dump_json(),
)

mock.assert_called_once_with(
Expand All @@ -99,7 +99,7 @@ def test_cost_recovery_cli_route_dry_run(
result = client.request(
"GET",
PREFIX + "/cli-cost-recovery",
content=recovery_period.json(),
content=recovery_period.model_dump_json(),
)

mock.assert_called_once_with(
Expand Down
18 changes: 10 additions & 8 deletions tests/test_routes/test_finances.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_finance_route(auth_app: FastAPI) -> None:
result = client.request(
"GET",
PREFIX + "/finance",
content=SubscriptionItem(sub_id=UUID(int=33)).json(),
content=SubscriptionItem(sub_id=UUID(int=33)).model_dump_json(),
)

assert result.status_code == 200
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_finances_route(auth_app: FastAPI) -> None:
finance_code="test_finance",
priority=1,
)
result = client.post(PREFIX + "/finances", content=f_a.json())
result = client.post(PREFIX + "/finances", content=f_a.model_dump_json())

assert result.status_code == 201

Expand Down Expand Up @@ -364,13 +364,14 @@ def test_finance_post_get_put_delete(auth_app: FastAPI) -> None:
finance_code="test_finance",
priority=1,
)
result = client.post(PREFIX + "/finances", content=f_a.json())
result = client.post(PREFIX + "/finances", content=f_a.model_dump_json())
assert result.status_code == 201
f_a_returned = FinanceWithID.parse_raw(result.content)

f_a_returned.amount = 10.0
result = client.put(
PREFIX + f"/finances/{f_a_returned.id}", content=f_a_returned.json()
PREFIX + f"/finances/{f_a_returned.id}",
content=f_a_returned.model_dump_json(),
)
assert result.status_code == 200

Expand All @@ -381,7 +382,7 @@ def test_finance_post_get_put_delete(auth_app: FastAPI) -> None:
result = client.request(
"DELETE",
PREFIX + f"/finances/{f_a_returned.id}",
content=SubscriptionItem(sub_id=constants.TEST_SUB_UUID).json(),
content=SubscriptionItem(sub_id=constants.TEST_SUB_UUID).model_dump_json(),
)
assert result.status_code == 200

Expand Down Expand Up @@ -545,19 +546,20 @@ def test_finance_can_update(auth_app: FastAPI) -> None:
finance_code="test_finance",
priority=1,
)
result = client.post(PREFIX + "/finances", content=f_a.json())
result = client.post(PREFIX + "/finances", content=f_a.model_dump_json())
assert result.status_code == 201
f_a_returned = FinanceWithID.parse_raw(result.content)

result = client.post(
PREFIX + "/cli-cost-recovery",
content=CostRecoveryMonth(first_day="2022-09-01").json(),
content=CostRecoveryMonth(first_day="2022-09-01").model_dump_json(),
)
assert result.status_code == 200

f_a_returned.amount = 10.0
result = client.put(
PREFIX + f"/finances/{f_a_returned.id}", content=f_a_returned.json()
PREFIX + f"/finances/{f_a_returned.id}",
content=f_a_returned.model_dump_json(),
)
assert result.status_code == 200

Expand Down
4 changes: 2 additions & 2 deletions tests/test_routes/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_post_status(

resp = client.post(
"accounting/all-status",
content=all_status.json(),
content=all_status.model_dump_json(),
headers={"authorization": "Bearer " + token},
)
assert resp.status_code == 200
Expand All @@ -72,7 +72,7 @@ def test_post_status(
# Check that we can POST the same status again without issue (idempotency).
resp = client.post(
"accounting/all-status",
content=all_status.json(),
content=all_status.model_dump_json(),
headers={"authorization": "Bearer " + token},
)
assert resp.status_code == 200
Expand Down
12 changes: 6 additions & 6 deletions tests/test_routes/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_post_usage(

resp = client.post(
"usage/all-usage",
content=post_data.json(),
content=post_data.model_dump_json(),
headers={"authorization": "Bearer " + token},
)

Expand Down Expand Up @@ -221,7 +221,7 @@ def _post_costmanagement(
post_client = client.post(
"/usage/all-cm-usage",
headers={"authorization": "Bearer " + token},
content=all_usage.json(),
content=all_usage.model_dump_json(),
) # type: ignore
return post_client # type: ignore

Expand Down Expand Up @@ -300,23 +300,23 @@ def test_post_monthly_usage(

resp = client.post(
"usage/monthly-usage",
content=post_example_1_data.json(),
content=post_example_1_data.model_dump_json(),
headers={"authorization": "Bearer " + token},
)

assert resp.status_code == 400

resp = client.post(
"usage/monthly-usage",
content=post_example_2_data.json(),
content=post_example_2_data.model_dump_json(),
headers={"authorization": "Bearer " + token},
)

assert resp.status_code == 400

resp = client.post(
"usage/monthly-usage",
content=post_example_3_data.json(),
content=post_example_3_data.model_dump_json(),
headers={"authorization": "Bearer " + token},
)

Expand Down Expand Up @@ -383,7 +383,7 @@ def test_post_usage_emails(

resp = client.post(
"usage/all-usage",
content=post_data.json(),
content=post_data.model_dump_json(),
headers={"authorization": "Bearer " + token},
)
assert resp.status_code == 200
Expand Down

0 comments on commit a06b7f6

Please sign in to comment.