-
-
Couldn't load subscription status.
- Fork 4.5k
ref(tests): Remove setUp function #101796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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: |
There was a problem hiding this comment.
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:
sentry/tests/sentry/deletions/test_group.py
Lines 54 to 69 in be7268d
| 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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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 |
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.