Skip to content

Commit

Permalink
ongoing work to fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpbc committed Feb 5, 2025
1 parent 45948cb commit e260afb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions rctab/routers/accounting/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ async def insert_usage(all_usage: AllUsage) -> None:
all_usage: Usage data to insert.
"""
usage_query = insert(accounting_models.usage)
update_dict = {c.name: c for c in usage_query.excluded if not c.primary_key}
on_duplicate_key_stmt = usage_query.on_conflict_do_update(
index_elements=inspect(accounting_models.usage).primary_key,
set_=update_dict,
)
# update_dict = {c.name: c for c in usage_query.excluded if not c.primary_key}
# on_duplicate_key_stmt = usage_query.on_conflict_do_update(
# index_elements=inspect(accounting_models.usage).primary_key,
# set_=update_dict,
# )

logger.info("Inserting usage data")
insert_start = datetime.datetime.now()

await executemany(
database,
on_duplicate_key_stmt,
usage_query,
values=[i.model_dump() for i in all_usage.usage_list],
)
logger.info("Inserting usage data took %s", datetime.datetime.now() - insert_start)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_routes/test_send_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async def test_usage_emails(
allocated_amount=100.0,
approved=(100.0, date.today() + timedelta(days=10)),
spent=(20.0, 0),
spent_date=date.today(),
)

ninety_percent = await create_subscription(
Expand All @@ -135,6 +136,7 @@ async def test_usage_emails(
allocated_amount=100.0,
approved=(100.0, date.today() + timedelta(days=10)),
spent=(80.0, 0),
spent_date=date.today(),
)

ninety_five_percent = await create_subscription(
Expand All @@ -144,6 +146,7 @@ async def test_usage_emails(
allocated_amount=100.0,
approved=(100.0, date.today() + timedelta(days=10)),
spent=(85.0, 0),
spent_date=date.today(),
)

ninety_percent_usage = USAGE_DICT.copy()
Expand All @@ -169,7 +172,9 @@ async def test_usage_emails(
Usage(**ninety_percent_usage),
Usage(**thirty_percent_usage),
Usage(**ninety_five_percent_usage),
]
],
start_date=date.today() - timedelta(1),
end_date=date.today() + timedelta(1),
)

mock_send = AsyncMock()
Expand Down

0 comments on commit e260afb

Please sign in to comment.