Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Oct 20, 2025

Last week when I was debugging tests for #101720 it was confusing to find events and groups that had nothing to do with the tests I was working on.

This refactor moves the majority of the logic from the setUp function to the first test since it's where its needed.

When debugging tests, it becomes harder to do when there are events and groups that have nothing to do with the tests you're working on.

This refactor moves the majority of the logic from the setUp function to the first test.
def _get_node_id(self, event: Event) -> str:
return Event.generate_node_id(event.project_id, event.event_id)

def _create_event_with_many_group_children(self) -> Event:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one event required all the extra models:

UserReport.objects.create(
group_id=group.id, project_id=self.event.project_id, name="With group id"
)
UserReport.objects.create(
event_id=self.event.event_id, project_id=self.event.project_id, name="With event id"
)
EventAttachment.objects.create(
event_id=self.event.event_id,
project_id=self.event.project_id,
name="hello.png",
content_type="image/png",
)
GroupAssignee.objects.create(group=group, project=self.project, user_id=self.user.id)
GroupHash.objects.create(project=self.project, group=group, hash=uuid4().hex)
GroupMeta.objects.create(group=group, key="foo", value="bar")
GroupRedirect.objects.create(group_id=group.id, previous_group_id=1)

GroupRedirect.objects.create(group_id=event.group.id, previous_group_id=1)

def test_simple(self) -> None:
ErrorEventsDeletionTask.DEFAULT_CHUNK_SIZE = 1 # test chunking logic
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is not actually testing that the chunking logic is working. I'm removing this.

assert nodestore.backend.get(self.keep_node_id)
return event

def test_delete_group_with_many_related_children(self) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming test_simple to this since it is more clear and it was not simple.

assert event.group is not None

event2 = self.store_event(
data=self._generate_data(fingerprint="group1"), project_id=self.project.id
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're testing that both events belonging to group1 will be deleted.

assert not nodestore.backend.get(self.node_id)
assert not nodestore.backend.get(self.node_id2)
assert nodestore.backend.get(self.keep_node_id), "Does not remove from second group"
assert Group.objects.filter(id=self.keep_event.group_id).exists()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not keeping the last two lines of this test since it makes no sense for this test.

@armenzg armenzg changed the title tests: Remove setUp function ref(tests): Remove setUp function Oct 20, 2025
@armenzg armenzg marked this pull request as ready for review October 20, 2025 14:23
@armenzg armenzg requested a review from a team as a code owner October 20, 2025 14:23
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #101796      +/-   ##
===========================================
- Coverage   80.95%    80.59%   -0.36%     
===========================================
  Files        8707      8712       +5     
  Lines      387114    390775    +3661     
  Branches    24524     24524              
===========================================
+ Hits       313375    314962    +1587     
- Misses      73391     75465    +2074     
  Partials      348       348              

@armenzg armenzg merged commit 045b32a into master Oct 20, 2025
68 checks passed
@armenzg armenzg deleted the 0/ref/delete_group_test/armenzg branch October 20, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants