Skip to content

Commit

Permalink
Replace deprecated func calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed Jan 9, 2025
1 parent 52047ab commit ba9390e
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 76 deletions.
2 changes: 1 addition & 1 deletion rctab/routers/accounting/allocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def post_subscription_allocation(
"new_allocation.html",
"New allocation for your Azure subscription:",
"subscription allocation",
allocation.dict(),
allocation.model_dump(),
)

await refresh_desired_states(user.oid, [allocation.sub_id])
Expand Down
2 changes: 1 addition & 1 deletion rctab/routers/accounting/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ async def post_approval(
"new_approval.html",
"New approval for your Azure subscription:",
EMAIL_TYPE_SUB_APPROVAL,
approval.dict(),
approval.model_dump(),
)

await refresh_desired_states(user.oid, [approval.sub_id])
Expand Down
5 changes: 3 additions & 2 deletions rctab/routers/accounting/finances.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ async def post_finance(

async with database.transaction():
new_primary_key = await database.execute(
insert(accounting_models.finance), {"admin": user.oid, **new_finance.dict()}
insert(accounting_models.finance),
{"admin": user.oid, **new_finance.model_dump()},
)
new_row = await database.fetch_one(
select([finance]).where(finance.c.id == new_primary_key)
Expand Down Expand Up @@ -151,7 +152,7 @@ async def update_finance(
update(finance)
.where(finance.c.id == finance_id)
.where(finance.c.subscription_id == new_finance.subscription_id)
.values({**new_finance.dict(), **{"admin": user.oid}})
.values({**new_finance.model_dump(), **{"admin": user.oid}})
)

return {"status": "success", "detail": "finance updated"}
Expand Down
2 changes: 1 addition & 1 deletion rctab/routers/accounting/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def post_persistency_status(
"persistence_change.html",
"Persistence change for your Azure subscription:",
"subscription persistence",
persistence.dict(),
persistence.model_dump(),
)

return {
Expand Down
4 changes: 2 additions & 2 deletions rctab/routers/accounting/send_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ def prepare_roles_email(
needed, in which case return an empty dictionary.
"""
# Convert to Dicts so we can remove items
old_rbac = [x.dict() for x in old_status.role_assignments]
new_rbac = [x.dict() for x in new_status.role_assignments]
old_rbac = [x.model_dump() for x in old_status.role_assignments]
new_rbac = [x.model_dump() for x in new_status.role_assignments]

# We don't need to display these in emails
for rbac_list in (old_rbac, new_rbac):
Expand Down
10 changes: 7 additions & 3 deletions rctab/routers/accounting/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,24 @@ async def post_status(
# If there is no prior status or the status has changed at all, we want to insert a new row.
if old_status != new_status:
status_insert = insert(subscription_details)
await database.execute(query=status_insert, values=new_status.dict())
await database.execute(
query=status_insert, values=new_status.model_dump()
)

if previous_welcome_email:
# We want to ignore some roles when deciding whether to
# send a status change email.
filtered_new_status = SubscriptionStatus(**new_status.dict())
filtered_new_status = SubscriptionStatus(**new_status.model_dump())
filtered_new_status.role_assignments = tuple(
x
for x in filtered_new_status.role_assignments
if x.role_name in get_settings().roles_filter
)

if old_status:
filtered_old_status = SubscriptionStatus(**old_status.dict())
filtered_old_status = SubscriptionStatus(
**old_status.model_dump()
)
filtered_old_status.role_assignments = tuple(
x
for x in filtered_old_status.role_assignments
Expand Down
4 changes: 2 additions & 2 deletions rctab/routers/accounting/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def insert_usage(all_usage: AllUsage) -> None:
await executemany(
database,
on_duplicate_key_stmt,
values=[i.dict() for i in all_usage.usage_list],
values=[i.model_dump() for i in all_usage.usage_list],
)
logger.info("Inserting usage data took %s", datetime.datetime.now() - insert_start)
refresh_start = datetime.datetime.now()
Expand Down Expand Up @@ -232,7 +232,7 @@ async def post_cm_usage(
await executemany(
database,
on_duplicate_key_stmt,
values=[i.dict() for i in all_cm_usage.cm_usage_list],
values=[i.model_dump() for i in all_cm_usage.cm_usage_list],
)

return TmpReturnStatus(
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_public_key_and_token(app_name: str) -> Tuple[str, str]:
token_claims: Dict[str, Any] = {"sub": app_name}
access_token_expires = datetime.timedelta(minutes=10)

expire = datetime.datetime.utcnow() + access_token_expires
expire = datetime.datetime.now(datetime.UTC) + access_token_expires
token_claims.update({"exp": expire})

private_key = rsa.generate_private_key(
Expand Down Expand Up @@ -135,7 +135,7 @@ def app_with_signed_billing_token(
token_claims: Dict[str, Any] = {"sub": "usage-app"}
access_token_expires = datetime.timedelta(minutes=10)

expire = datetime.datetime.utcnow() + access_token_expires
expire = datetime.datetime.now(datetime.UTC) + access_token_expires
token_claims.update({"exp": expire})

token = jwt.encode(token_claims, private_key_bytes, algorithm="RS256") # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/test_routes/test_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_successful_approval(auth_app: FastAPI, mocker: MockerFixture) -> None:
date_to=date_to,
sub_id=constants.TEST_SUB_UUID,
ticket="T001-12",
).dict(),
).model_dump(),
)


Expand Down
39 changes: 21 additions & 18 deletions tests/test_routes/test_cost_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def test_cost_recovery_simple(
total_cost=1,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

new_finance = Finance(
Expand All @@ -139,7 +139,7 @@ async def test_cost_recovery_simple(
priority=1,
)
await test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.model_dump()}
)
cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
await calc_cost_recovery(
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_cost_recovery_two_finances(
total_cost=3,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Two finances in our period of interest and one outside
Expand All @@ -190,7 +190,8 @@ async def test_cost_recovery_two_finances(
priority=1,
)
await test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance),
{**ADMIN_DICT, **new_finance.model_dump()},
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down Expand Up @@ -226,7 +227,7 @@ async def test_cost_recovery_second_month(
total_cost=1,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Feb
Expand All @@ -238,7 +239,7 @@ async def test_cost_recovery_second_month(
total_cost=2,
invoice_section="",
date=date(2001, 2, 1),
).dict(),
).model_dump(),
)

# Jan - Feb
Expand All @@ -252,7 +253,7 @@ async def test_cost_recovery_second_month(
priority=1,
)
await test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.model_dump()}
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down Expand Up @@ -300,7 +301,7 @@ async def test_cost_recovery_two_subscriptions(
total_cost=1,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Jan
Expand All @@ -312,7 +313,7 @@ async def test_cost_recovery_two_subscriptions(
total_cost=2,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Jan - Feb
Expand All @@ -326,7 +327,7 @@ async def test_cost_recovery_two_subscriptions(
priority=1,
)
await test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.model_dump()}
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down Expand Up @@ -365,7 +366,7 @@ async def test_cost_recovery_priority_one_month(
total_cost=3,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Two finances in our period of interest and one outside
Expand All @@ -380,7 +381,8 @@ async def test_cost_recovery_priority_one_month(
priority=priority,
)
await test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance),
{**ADMIN_DICT, **new_finance.model_dump()},
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down Expand Up @@ -421,7 +423,7 @@ async def test_cost_recovery_priority_two_months(
total_cost=3,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Two finances in our period of interest and one outside
Expand All @@ -436,7 +438,8 @@ async def test_cost_recovery_priority_two_months(
priority=priority,
)
await test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance),
{**ADMIN_DICT, **new_finance.model_dump()},
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down Expand Up @@ -515,7 +518,7 @@ async def test_cost_recovery_commit_param(
total_cost=1,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Jan - Feb
Expand All @@ -529,7 +532,7 @@ async def test_cost_recovery_commit_param(
priority=1,
)
new_finance_id = await no_rollback_test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.model_dump()}
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down Expand Up @@ -594,7 +597,7 @@ async def test_cost_recovery_rollsback(
total_cost=1,
invoice_section="",
date=date(2001, 1, 1),
).dict(),
).model_dump(),
)

# Jan - Feb
Expand All @@ -608,7 +611,7 @@ async def test_cost_recovery_rollsback(
priority=1,
)
await no_rollback_test_db.execute(
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.dict()}
insert(accounting_models.finance), {**ADMIN_DICT, **new_finance.model_dump()}
)

cost_recovery_period = CostRecoveryMonth(first_day=date(year=2001, month=1, day=1))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_routes/test_email_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async def test_allocation_emails_render(

template_data = Allocation(
sub_id=subscription_id, ticket="C2022-999", amount=300
).dict()
).model_dump()
template_data["summary"] = subscription_summary
template_data["rctab_url"] = None

Expand Down Expand Up @@ -253,7 +253,7 @@ async def test_approval_emails_render(
ticket="Ticket C1",
date_from=date.today(),
date_to=date.today() + timedelta(days=20),
).dict()
).model_dump()
template_data["summary"] = dict(subscription_summary) # type: ignore
template_data["rctab_url"] = None
template = jinja2_environment.get_template(template_name)
Expand Down Expand Up @@ -393,7 +393,7 @@ def test_render_finance_email(jinja2_environment: Environment) -> None:
date_to=date(2022, 8, 31),
finance_code="test_finance",
priority=1,
).dict()
).model_dump()

template_name = "new_finance.html"

Expand Down Expand Up @@ -485,7 +485,7 @@ async def test_send_summary_email_render(test_db: Database) -> None:
role_name="Billing Reader",
principal_id="some-principal-id",
display_name="SomePrincipal Display Name",
).dict()
).model_dump()

await test_db.execute(
accounting_models.subscription_details.insert().values(),
Expand Down
Loading

0 comments on commit ba9390e

Please sign in to comment.