|
2 | 2 | from jsonschema import ValidationError
|
3 | 3 |
|
4 | 4 | from sentry.rules.conditions.event_frequency import (
|
| 5 | + PERCENT_INTERVALS, |
| 6 | + STANDARD_INTERVALS, |
5 | 7 | ComparisonType,
|
6 | 8 | EventFrequencyCondition,
|
7 | 9 | EventFrequencyPercentCondition,
|
@@ -140,6 +142,8 @@ def setUp(self):
|
140 | 142 | "comparisonType": ComparisonType.PERCENT,
|
141 | 143 | "comparisonInterval": "1d",
|
142 | 144 | }
|
| 145 | + self.intervals = STANDARD_INTERVALS |
| 146 | + self.other_intervals = PERCENT_INTERVALS |
143 | 147 |
|
144 | 148 | def test_percent(self):
|
145 | 149 | dc = self.create_data_condition(
|
@@ -245,6 +249,18 @@ def test_json_schema(self):
|
245 | 249 | condition_result=True,
|
246 | 250 | )
|
247 | 251 |
|
| 252 | + invalid_interval = list(set(self.other_intervals.keys()) - set(self.intervals.keys()))[0] |
| 253 | + with pytest.raises(ValidationError): |
| 254 | + self.create_data_condition( |
| 255 | + type=self.condition, |
| 256 | + comparison={ |
| 257 | + "interval": invalid_interval, |
| 258 | + "value": 100, |
| 259 | + "comparison_interval": "1d", |
| 260 | + }, |
| 261 | + condition_result=True, |
| 262 | + ) |
| 263 | + |
248 | 264 |
|
249 | 265 | class TestEventUniqueUserFrequencyCountCondition(TestEventFrequencyCountCondition):
|
250 | 266 | def setUp(self):
|
@@ -276,24 +292,28 @@ def setUp(self):
|
276 | 292 | super().setUp()
|
277 | 293 | self.condition = Condition.PERCENT_SESSIONS_COUNT
|
278 | 294 | self.payload: dict[str, int | str] = {
|
279 |
| - "interval": "1h", |
| 295 | + "interval": "30m", # only percent sessions allows 30m |
280 | 296 | "id": EventFrequencyPercentCondition.id,
|
281 | 297 | "value": 17,
|
282 | 298 | "comparisonType": ComparisonType.COUNT,
|
283 | 299 | }
|
| 300 | + self.intervals = PERCENT_INTERVALS |
| 301 | + self.other_intervals = STANDARD_INTERVALS |
284 | 302 |
|
285 | 303 |
|
286 | 304 | class TestPercentSessionsPercentCondition(TestEventFrequencyPercentCondition):
|
287 | 305 | def setUp(self):
|
288 | 306 | super().setUp()
|
289 | 307 | self.condition = Condition.PERCENT_SESSIONS_PERCENT
|
290 | 308 | self.payload: dict[str, int | str] = {
|
291 |
| - "interval": "1h", |
| 309 | + "interval": "30m", # only percent sessions allows 30m |
292 | 310 | "id": EventFrequencyPercentCondition.id,
|
293 | 311 | "value": 17,
|
294 | 312 | "comparisonType": ComparisonType.PERCENT,
|
295 | 313 | "comparisonInterval": "1d",
|
296 | 314 | }
|
| 315 | + self.intervals = PERCENT_INTERVALS |
| 316 | + self.other_intervals = STANDARD_INTERVALS |
297 | 317 |
|
298 | 318 |
|
299 | 319 | class TestEventUniqueUserFrequencyConditionWithConditions(ConditionTestCase):
|
|
0 commit comments