@@ -19,15 +19,26 @@ async def test_query_get_usage_cost_returns_zero_when_no_usage_records_exist(
1919 """Test that get_usage_cost returns zero cost when no usage records exist."""
2020 pool = await create_db_pool (dsn = pg_dsn )
2121
22- # Calculate expected cost
22+ # Create a new developer ID for this test to ensure clean state
23+ clean_developer_id = uuid7 ()
24+ await create_developer (
25+ email = f"clean-test-{ clean_developer_id } @example.com" ,
26+ active = True ,
27+ tags = ["test" ],
28+ settings = {},
29+ developer_id = clean_developer_id ,
30+ connection_pool = pool ,
31+ )
32+
33+ # Calculate expected cost - should be 0 for new developer
2334 expected_cost = Decimal ("0" )
2435
2536 # Get the usage cost
26- cost_record = await get_usage_cost (developer_id = test_developer_id , connection_pool = pool )
37+ cost_record = await get_usage_cost (developer_id = clean_developer_id , connection_pool = pool )
2738
2839 # Verify the record
2940 assert cost_record is not None , "Should have a cost record"
30- assert cost_record ["developer_id" ] == test_developer_id
41+ assert cost_record ["developer_id" ] == clean_developer_id
3142 assert "cost" in cost_record , "Should have a cost field"
3243 assert isinstance (cost_record ["cost" ], Decimal ), "Cost should be a Decimal"
3344 assert cost_record ["cost" ] == expected_cost , (
@@ -43,17 +54,28 @@ async def test_query_get_usage_cost_returns_the_correct_cost_when_records_exist(
4354 """Test that get_usage_cost returns the correct cost for a developer with usage records."""
4455 pool = await create_db_pool (dsn = pg_dsn )
4556
57+ # Create a new developer ID for this test to ensure clean state
58+ clean_developer_id = uuid7 ()
59+ await create_developer (
60+ email = f"clean-test-{ clean_developer_id } @example.com" ,
61+ active = True ,
62+ tags = ["test" ],
63+ settings = {},
64+ developer_id = clean_developer_id ,
65+ connection_pool = pool ,
66+ )
67+
4668 # Create some usage records for the developer
4769 record1 = await create_usage_record (
48- developer_id = test_developer_id ,
70+ developer_id = clean_developer_id ,
4971 model = "gpt-4o-mini" ,
5072 prompt_tokens = 1000 ,
5173 completion_tokens = 2000 ,
5274 connection_pool = pool ,
5375 )
5476
5577 record2 = await create_usage_record (
56- developer_id = test_developer_id ,
78+ developer_id = clean_developer_id ,
5779 model = "gpt-4o-mini" ,
5880 prompt_tokens = 500 ,
5981 completion_tokens = 1500 ,
@@ -71,11 +93,11 @@ async def test_query_get_usage_cost_returns_the_correct_cost_when_records_exist(
7193 await asyncio .sleep (0.1 )
7294
7395 # Get the usage cost
74- cost_record = await get_usage_cost (developer_id = test_developer_id , connection_pool = pool )
96+ cost_record = await get_usage_cost (developer_id = clean_developer_id , connection_pool = pool )
7597
7698 # Verify the record
7799 assert cost_record is not None , "Should have a cost record"
78- assert cost_record ["developer_id" ] == test_developer_id
100+ assert cost_record ["developer_id" ] == clean_developer_id
79101 assert "cost" in cost_record , "Should have a cost field"
80102 assert isinstance (cost_record ["cost" ], Decimal ), "Cost should be a Decimal"
81103 assert cost_record ["cost" ] == expected_cost , (
0 commit comments