Skip to content

Commit df6d7df

Browse files
committed
add tests
1 parent d560a3e commit df6d7df

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

tests/sentry/event_manager/grouping/test_assign_to_group.py

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import Any
66
from unittest import mock
77

8+
import pytest
9+
810
from sentry.event_manager import _create_group
911
from sentry.eventstore.models import Event
1012
from sentry.grouping.ingest import (
@@ -15,6 +17,7 @@
1517
from sentry.models.grouphash import GroupHash
1618
from sentry.models.project import Project
1719
from sentry.testutils.helpers.eventprocessing import save_new_event
20+
from sentry.testutils.pytest.fixtures import django_db_all
1821
from sentry.testutils.pytest.mocking import capture_return_values
1922
from sentry.testutils.skips import requires_snuba
2023

@@ -218,3 +221,188 @@ def get_results_from_saving_event(
218221
"primary_grouphash_exists_now": primary_grouphash_exists_now,
219222
"secondary_grouphash_exists_now": secondary_grouphash_exists_now,
220223
}
224+
225+
226+
@django_db_all
227+
@pytest.mark.parametrize(
228+
"in_transition", (True, False), ids=(" in_transition: True ", " in_transition: False ")
229+
)
230+
def test_new_group(
231+
in_transition: bool,
232+
default_project: Project,
233+
):
234+
project = default_project
235+
event_data = {"message": "testing, testing, 123"}
236+
237+
results = get_results_from_saving_event(
238+
event_data=event_data,
239+
project=project,
240+
primary_config=NEWSTYLE_CONFIG,
241+
secondary_config=LEGACY_CONFIG,
242+
in_transition=in_transition,
243+
)
244+
245+
if in_transition:
246+
assert results == {
247+
"primary_hash_calculated": True,
248+
"secondary_hash_calculated": True,
249+
"hashes_different": True,
250+
"primary_hash_found": False,
251+
"secondary_hash_found": False,
252+
"new_group_created": True,
253+
"primary_grouphash_existed_already": False,
254+
"secondary_grouphash_existed_already": False,
255+
"primary_grouphash_exists_now": True,
256+
"secondary_grouphash_exists_now": True,
257+
# Moot since no existing group was passed
258+
"event_assigned_to_given_existing_group": None,
259+
}
260+
else:
261+
assert results == {
262+
"primary_hash_calculated": True,
263+
"secondary_hash_calculated": False,
264+
"primary_hash_found": False,
265+
"new_group_created": True,
266+
"primary_grouphash_existed_already": False,
267+
"primary_grouphash_exists_now": True,
268+
# The rest are moot since no existing group was passed and no secondary hash was
269+
# calculated.
270+
"event_assigned_to_given_existing_group": None,
271+
"hashes_different": None,
272+
"secondary_hash_found": None,
273+
"secondary_grouphash_existed_already": None,
274+
"secondary_grouphash_exists_now": None,
275+
}
276+
277+
278+
@django_db_all
279+
@pytest.mark.parametrize(
280+
"in_transition", (True, False), ids=(" in_transition: True ", " in_transition: False ")
281+
)
282+
def test_existing_group_no_new_hash(
283+
in_transition: bool,
284+
default_project: Project,
285+
):
286+
project = default_project
287+
event_data = {"message": "testing, testing, 123"}
288+
289+
# Set the stage by creating a group with the soon-to-be-secondary hash
290+
existing_event = save_event_with_grouping_config(event_data, project, LEGACY_CONFIG)
291+
292+
# Now save a new, identical, event with an updated grouping config
293+
results = get_results_from_saving_event(
294+
event_data=event_data,
295+
project=project,
296+
primary_config=NEWSTYLE_CONFIG,
297+
secondary_config=LEGACY_CONFIG,
298+
in_transition=in_transition,
299+
existing_group_id=existing_event.group_id,
300+
)
301+
302+
if in_transition:
303+
assert results == {
304+
"primary_hash_calculated": True,
305+
"secondary_hash_calculated": True,
306+
"hashes_different": True,
307+
"primary_hash_found": False,
308+
"secondary_hash_found": True,
309+
"new_group_created": False,
310+
"event_assigned_to_given_existing_group": True,
311+
"primary_grouphash_existed_already": False,
312+
"secondary_grouphash_existed_already": True,
313+
"primary_grouphash_exists_now": True,
314+
"secondary_grouphash_exists_now": True,
315+
}
316+
else:
317+
assert results == {
318+
"primary_hash_calculated": True,
319+
"secondary_hash_calculated": False,
320+
"primary_hash_found": False,
321+
"new_group_created": True,
322+
"event_assigned_to_given_existing_group": False,
323+
"primary_grouphash_existed_already": False,
324+
"primary_grouphash_exists_now": True,
325+
# The rest are moot since no secondary hash was calculated.
326+
"hashes_different": None,
327+
"secondary_hash_found": None,
328+
"secondary_grouphash_existed_already": None,
329+
"secondary_grouphash_exists_now": None,
330+
}
331+
332+
333+
@django_db_all
334+
@pytest.mark.parametrize(
335+
"in_transition", (True, False), ids=(" in_transition: True ", " in_transition: False ")
336+
)
337+
@pytest.mark.parametrize(
338+
"secondary_hash_exists",
339+
(True, False),
340+
ids=(" secondary_hash_exists: True ", " secondary_hash_exists: False "),
341+
)
342+
def test_existing_group_new_hash_exists(
343+
secondary_hash_exists: bool,
344+
in_transition: bool,
345+
default_project: Project,
346+
):
347+
project = default_project
348+
event_data = {"message": "testing, testing, 123"}
349+
350+
# Set the stage by creating a group tied to the new hash (and possibly the legacy hash as well)
351+
if secondary_hash_exists:
352+
existing_event = save_event_with_grouping_config(
353+
event_data, project, NEWSTYLE_CONFIG, LEGACY_CONFIG, True
354+
)
355+
assert (
356+
GroupHash.objects.filter(
357+
project_id=project.id, group_id=existing_event.group_id
358+
).count()
359+
== 2
360+
)
361+
else:
362+
existing_event = save_event_with_grouping_config(event_data, project, NEWSTYLE_CONFIG)
363+
assert (
364+
GroupHash.objects.filter(
365+
project_id=project.id, group_id=existing_event.group_id
366+
).count()
367+
== 1
368+
)
369+
370+
# Now save a new, identical, event
371+
results = get_results_from_saving_event(
372+
event_data=event_data,
373+
project=project,
374+
primary_config=NEWSTYLE_CONFIG,
375+
secondary_config=LEGACY_CONFIG,
376+
in_transition=in_transition,
377+
existing_group_id=existing_event.group_id,
378+
)
379+
380+
if in_transition:
381+
assert results == {
382+
"primary_hash_calculated": True,
383+
"secondary_hash_calculated": True,
384+
"hashes_different": True,
385+
"primary_hash_found": True,
386+
"secondary_hash_found": False, # We found the new hash first and quit looking
387+
"new_group_created": False,
388+
"event_assigned_to_given_existing_group": True,
389+
"primary_grouphash_existed_already": True,
390+
"secondary_grouphash_existed_already": secondary_hash_exists,
391+
"primary_grouphash_exists_now": True,
392+
"secondary_grouphash_exists_now": True,
393+
}
394+
else:
395+
assert results == {
396+
"primary_hash_calculated": True,
397+
"secondary_hash_calculated": False,
398+
"primary_hash_found": True,
399+
"new_group_created": False,
400+
"event_assigned_to_given_existing_group": True,
401+
"primary_grouphash_existed_already": True,
402+
"primary_grouphash_exists_now": True,
403+
# The rest are moot since no secondary hash was calculated.
404+
"hashes_different": None,
405+
"secondary_hash_found": None,
406+
"secondary_grouphash_existed_already": None,
407+
"secondary_grouphash_exists_now": None,
408+
}

0 commit comments

Comments
 (0)