1818
1919
2020class TestUsage (BaseTest ):
21- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
22- @patch ("ee.hogai.chat_agent.queries.get_instance_region" )
21+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
22+ @patch ("ee.hogai.chat_agent.usage. queries.get_instance_region" )
2323 def test_get_ai_free_tier_credits_default (self , mock_region , mock_payload ):
2424 """Test that teams without custom limits get the default free tier."""
2525 mock_region .return_value = "EU"
2626 mock_payload .return_value = None
2727 credits = get_ai_free_tier_credits (team_id = 999 )
2828 self .assertEqual (credits , DEFAULT_FREE_TIER_CREDITS )
2929
30- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
31- @patch ("ee.hogai.chat_agent.queries.get_instance_region" )
30+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
31+ @patch ("ee.hogai.chat_agent.usage. queries.get_instance_region" )
3232 def test_get_ai_free_tier_credits_custom_eu (self , mock_region , mock_payload ):
3333 """Test that EU internal team gets custom free tier limit from feature flag."""
3434 mock_region .return_value = "EU"
3535 mock_payload .return_value = {"EU" : {"1" : 9999999 }, "US" : {"2" : 9999999 }}
3636 credits = get_ai_free_tier_credits (team_id = 1 )
3737 self .assertEqual (credits , 9999999 )
3838
39- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
40- @patch ("ee.hogai.chat_agent.queries.get_instance_region" )
39+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
40+ @patch ("ee.hogai.chat_agent.usage. queries.get_instance_region" )
4141 def test_get_ai_free_tier_credits_custom_us (self , mock_region , mock_payload ):
4242 """Test that US internal team gets custom free tier limit from feature flag."""
4343 mock_region .return_value = "US"
4444 mock_payload .return_value = {"EU" : {"1" : 9999999 }, "US" : {"2" : 9999999 }}
4545 credits = get_ai_free_tier_credits (team_id = 2 )
4646 self .assertEqual (credits , 9999999 )
4747
48- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
49- @patch ("ee.hogai.chat_agent.queries.get_instance_region" )
48+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
49+ @patch ("ee.hogai.chat_agent.usage. queries.get_instance_region" )
5050 def test_get_ai_free_tier_credits_fallback_when_region_unknown (self , mock_region , mock_payload ):
5151 """Test that unknown regions fall back to default."""
5252 mock_region .return_value = None
5353 mock_payload .return_value = {"EU" : {"1" : 9999999 }}
5454 credits = get_ai_free_tier_credits (team_id = 1 )
5555 self .assertEqual (credits , DEFAULT_FREE_TIER_CREDITS )
5656
57- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
58- @patch ("ee.hogai.chat_agent.queries.get_instance_region" )
57+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
58+ @patch ("ee.hogai.chat_agent.usage. queries.get_instance_region" )
5959 def test_get_ai_free_tier_credits_team_not_in_payload (self , mock_region , mock_payload ):
6060 """Test that teams not in the payload get default credits."""
6161 mock_region .return_value = "EU"
6262 mock_payload .return_value = {"EU" : {"1" : 9999999 }}
6363 credits = get_ai_free_tier_credits (team_id = 999 )
6464 self .assertEqual (credits , DEFAULT_FREE_TIER_CREDITS )
6565
66- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
67- @patch ("ee.hogai.chat_agent.queries.get_instance_region" )
66+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
67+ @patch ("ee.hogai.chat_agent.usage. queries.get_instance_region" )
6868 def test_get_ai_free_tier_credits_invalid_payload (self , mock_region , mock_payload ):
6969 """Test that invalid payloads fall back to default."""
7070 mock_region .return_value = "EU"
@@ -90,21 +90,21 @@ def test_get_conversation_start_time_not_exists(self):
9090 start_time = get_conversation_start_time (uuid4 ())
9191 self .assertIsNone (start_time )
9292
93- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
93+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
9494 def test_get_ga_launch_date_from_payload (self , mock_payload ):
9595 """Test that GA launch date is fetched from feature flag payload."""
9696 mock_payload .return_value = {"ga_launch_date" : "2025-12-01" , "EU" : {"1" : 10000 }}
9797 ga_date = get_ga_launch_date ()
9898 self .assertEqual (ga_date , datetime (2025 , 12 , 1 , tzinfo = UTC ))
9999
100- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
100+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
101101 def test_get_ga_launch_date_fallback (self , mock_payload ):
102102 """Test that GA launch date falls back to default when not in payload."""
103103 mock_payload .return_value = None
104104 ga_date = get_ga_launch_date ()
105105 self .assertEqual (ga_date , DEFAULT_GA_LAUNCH_DATE )
106106
107- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
107+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
108108 def test_get_ga_launch_date_invalid_format (self , mock_payload ):
109109 """Test that invalid date format falls back to default."""
110110 mock_payload .return_value = {"ga_launch_date" : "invalid-date" }
@@ -114,20 +114,20 @@ def test_get_ga_launch_date_invalid_format(self, mock_payload):
114114 def test_get_past_month_start_normal (self ):
115115 """Test past month start when 30 days ago is after GA launch."""
116116 now = datetime (2025 , 12 , 20 , tzinfo = UTC )
117- with patch ("ee.hogai.chat_agent.queries.datetime" ) as mock_datetime :
117+ with patch ("ee.hogai.chat_agent.usage. queries.datetime" ) as mock_datetime :
118118 mock_datetime .side_effect = lambda * args , ** kw : datetime (* args , ** kw )
119119 mock_datetime .now .return_value = now
120120 past_month_start = get_past_month_start ()
121121 expected = datetime (2025 , 11 , 20 , tzinfo = UTC )
122122 self .assertEqual (past_month_start , expected )
123123
124- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
124+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
125125 def test_get_past_month_start_capped_at_ga_launch (self , mock_payload ):
126126 """Test that past month start is capped at GA launch date."""
127127 mock_payload .return_value = None
128128 # Set current time to shortly after GA launch
129129 now = DEFAULT_GA_LAUNCH_DATE + timedelta (days = 10 )
130- with patch ("ee.hogai.chat_agent.queries.datetime" ) as mock_datetime :
130+ with patch ("ee.hogai.chat_agent.usage. queries.datetime" ) as mock_datetime :
131131 mock_datetime .side_effect = lambda * args , ** kw : datetime (* args , ** kw )
132132 mock_datetime .now .return_value = now
133133 past_month_start = get_past_month_start ()
@@ -169,7 +169,7 @@ def test_format_usage_message_over_limit(self):
169169 self .assertIn ("**Overage**: 500 credits over limit" , message )
170170 self .assertIn ("125% of free tier" , message )
171171
172- @patch ("ee.hogai.chat_agent.queries.posthoganalytics.get_feature_flag_payload" )
172+ @patch ("ee.hogai.chat_agent.usage. queries.posthoganalytics.get_feature_flag_payload" )
173173 def test_format_usage_message_with_ga_cap (self , mock_payload ):
174174 """Test formatting when GA cap is active."""
175175 mock_payload .return_value = None
0 commit comments