From e260afb31ca3e61e2f4398d11d77a93a8a445006 Mon Sep 17 00:00:00 2001 From: Ese <17943860+dlpbc@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:50:13 +0000 Subject: [PATCH] ongoing work to fix failing tests --- rctab/routers/accounting/usage.py | 12 ++++++------ tests/test_routes/test_send_emails.py | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/rctab/routers/accounting/usage.py b/rctab/routers/accounting/usage.py index 8a767fc..266edd8 100644 --- a/rctab/routers/accounting/usage.py +++ b/rctab/routers/accounting/usage.py @@ -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) diff --git a/tests/test_routes/test_send_emails.py b/tests/test_routes/test_send_emails.py index d7142d2..6bce625 100644 --- a/tests/test_routes/test_send_emails.py +++ b/tests/test_routes/test_send_emails.py @@ -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( @@ -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( @@ -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() @@ -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()