Skip to content

ref: fix some typing issues in tests when models are checked #73742

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

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tests/sentry/api/endpoints/test_debug_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ def test_source_maps_sorting(self):
def test_source_maps_delete_archive(self):
project = self.create_project(name="foo")

release = Release.objects.create(
organization_id=project.organization_id, version="1", id="1"
)
release = Release.objects.create(organization_id=project.organization_id, version="1", id=1)
release.add_project(project)

ReleaseFile.objects.create(
Expand Down
4 changes: 4 additions & 0 deletions tests/sentry/api/endpoints/test_group_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_note_merge(self):
data={"text": "This looks bad :)"},
datetime=now - datetime.timedelta(days=70),
)
assert note1.data is not None
note2 = Activity.objects.create(
group=group1,
project=project1,
Expand All @@ -60,6 +61,7 @@ def test_note_merge(self):
data={"text": "Yeah we should probably look into this"},
datetime=now - datetime.timedelta(days=66),
)
assert note2.data is not None

project2 = self.create_project()
group2 = self.create_group(project2)
Expand All @@ -72,6 +74,7 @@ def test_note_merge(self):
data={"text": "I have been a good Sentry :)"},
datetime=now - datetime.timedelta(days=90),
)
assert note3.data is not None
note4 = Activity.objects.create(
group=group2,
project=project2,
Expand All @@ -80,6 +83,7 @@ def test_note_merge(self):
data={"text": "You have been a bad user :)"},
datetime=now - datetime.timedelta(days=88),
)
assert note4.data is not None

with self.tasks():
merge_groups([group1.id], group2.id)
Expand Down
1 change: 1 addition & 0 deletions tests/sentry/api/endpoints/test_project_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def test_get(self):

# Assert that "identifier" is not renamed to "name" in the backend
ownership = ProjectOwnership.objects.get(project=self.project)
assert ownership.schema is not None
assert ownership.schema["rules"] == [
{
"matcher": {"type": "path", "pattern": "*.js"},
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/deletions/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_discover_query_cleanup(self):
other = self.create_organization(name="other", owner=self.user)
other_project = self.create_project(organization=other, name="other project")

query = DiscoverSavedQuery.objects.create(organization=org, name="test query", query="{}")
query = DiscoverSavedQuery.objects.create(organization=org, name="test query", query={})
# Make a cross-org project reference. This can happen when an account was
# merged in the past and we didn't update the discover queries.
query_project = DiscoverSavedQueryProject.objects.create(
Expand Down
10 changes: 10 additions & 0 deletions tests/sentry/event_manager/test_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def test_marks_as_unresolved_with_new_release(
assert group.status == GroupStatus.RESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == ""

assert GroupResolution.objects.filter(group=group).exists()
Expand All @@ -371,6 +372,7 @@ def test_marks_as_unresolved_with_new_release(
assert group.status == GroupStatus.UNRESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == "b"

assert not GroupResolution.objects.filter(group=group).exists()
Expand Down Expand Up @@ -431,11 +433,13 @@ def test_that_release_in_latest_activity_prior_to_regression_is_not_overridden(
assert group.status == GroupStatus.UNRESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == "foobar"

regressed_activity = Activity.objects.get(
group=group, type=ActivityType.SET_REGRESSION.value
)
assert regressed_activity.data is not None
assert regressed_activity.data["version"] == "b"
assert regressed_activity.data["follows_semver"] is False

Expand Down Expand Up @@ -493,12 +497,14 @@ def test_current_release_version_in_latest_activity_prior_to_regression_is_not_o
assert group.status == GroupStatus.UNRESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == "b"
assert activity.data["current_release_version"] == "pre foobar"

regressed_activity = Activity.objects.get(
group=group, type=ActivityType.SET_REGRESSION.value
)
assert regressed_activity.data is not None
assert regressed_activity.data["version"] == "b"

mock_send_activity_notifications_delay.assert_called_once_with(regressed_activity.id)
Expand Down Expand Up @@ -555,11 +561,13 @@ def test_resolved_in_release_regression_activity_follows_semver(
assert group.status == GroupStatus.UNRESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == "foo@1.0.0"

regressed_activity = Activity.objects.get(
group=group, type=ActivityType.SET_REGRESSION.value
)
assert regressed_activity.data is not None
assert regressed_activity.data["version"] == "foo@2.0.0"
assert regressed_activity.data["follows_semver"] is True
assert regressed_activity.data["resolved_in_version"] == "foo@1.0.0"
Expand Down Expand Up @@ -835,6 +843,7 @@ def test_marks_as_unresolved_with_new_release_with_integration(
assert group.status == GroupStatus.RESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == ""

assert GroupResolution.objects.filter(group=group).exists()
Expand All @@ -853,6 +862,7 @@ def test_marks_as_unresolved_with_new_release_with_integration(
assert group.status == GroupStatus.UNRESOLVED

activity = Activity.objects.get(id=activity.id)
assert activity.data is not None
assert activity.data["version"] == "b"

assert not GroupResolution.objects.filter(group=group).exists()
Expand Down
14 changes: 7 additions & 7 deletions tests/sentry/event_manager/test_event_manager_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_puts_events_with_only_partial_message_match_in_different_groups(self):
def test_adds_default_fingerprint_if_none_in_event(self):
event = save_new_event({"message": "Dogs are great!"}, self.project)

assert event.data.get("fingerprint") == ["{{ default }}"]
assert event.data["fingerprint"] == ["{{ default }}"]

def test_ignores_fingerprint_on_transaction_event(self):
error_event = save_new_event(
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_updates_group_metadata(self):
assert group.times_seen == 1
assert group.last_seen == event1.datetime
assert group.message == event1.message
assert group.data.get("metadata").get("title") == event1.title
assert group.data["metadata"]["title"] == event1.title

# Normally this should go into a different group, since the messages don't match, but the
# fingerprint takes precedence. (We need to make the messages different in order to show
Expand All @@ -131,7 +131,7 @@ def test_updates_group_metadata(self):
assert group.times_seen == 2
assert group.last_seen == event2.datetime
assert group.message == event2.message
assert group.data.get("metadata").get("title") == event2.title
assert group.data["metadata"]["title"] == event2.title

def test_auto_updates_grouping_config(self):
self.project.update_option("sentry:grouping_config", LEGACY_CONFIG)
Expand All @@ -145,7 +145,7 @@ def test_auto_updates_grouping_config(self):
assert self.project.get_option("sentry:grouping_config") == DEFAULT_GROUPING_CONFIG

with assume_test_silo_mode_of(AuditLogEntry):
audit_log_entry = AuditLogEntry.objects.first()
audit_log_entry = AuditLogEntry.objects.get()

assert audit_log_entry.event == audit_log.get_event_id("PROJECT_EDIT")
assert audit_log_entry.actor_label == "Sentry"
Expand Down Expand Up @@ -237,8 +237,8 @@ def test_fixes_broken_title_data(self):
assert group.title == event2.title == "<unlabeled event>"
assert group.data["title"] == event2.data["title"] == "<unlabeled event>"
assert (
group.data["metadata"].get("title")
== event2.data["metadata"].get("title")
group.data["metadata"]["title"]
== event2.data["metadata"]["title"]
== "<unlabeled event>"
)
assert group.message == "<unlabeled event>"
Expand Down Expand Up @@ -318,7 +318,7 @@ def test_bug_regression_no_longer_breaks_titles(self):
assert event2.data["title"] == "<unlabeled event>"
assert group.data["title"] == "DogsAreNeverAnError: Dogs are great!"
assert group.data["metadata"].get("title") is None
assert event2.data["metadata"].get("title") == "<unlabeled event>"
assert event2.data["metadata"]["title"] == "<unlabeled event>"
assert group.message == "Dogs are great! DogsAreNeverAnError"

# An event after the bug was fixed
Expand Down
1 change: 1 addition & 0 deletions tests/sentry/incidents/action_handlers/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_fire_metric_alert_sdk_error(self, mock_metrics):
assert NotificationMessage.objects.all().count() == 1
msg = NotificationMessage.objects.all()[0]
assert msg.error_code == 200
assert msg.error_details is not None
assert msg.error_details["data"] == {"ok": False, "error": "invalid_auth"}

mock_metrics.incr.assert_called_with(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_note(self, mock_send_card: MagicMock):
f"[{self.group.title}](http://testserver/organizations/{self.organization.slug}/issues/{self.group.id}/?referrer=note\\_activity-msteams&amp;notification\\_uuid="
in body[1]["text"]
)
assert notification.activity.data is not None
assert notification.activity.data["text"] == body[2]["text"]
notification_uuid = self.get_notification_uuid(body[3]["columns"][1]["items"][0]["text"])
assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def test_resolved_in_release(self, mock_send_card):
body = args[1]["body"]
assert 4 == len(body)

assert notification.activity.data is not None
release_name = notification.activity.data["version"]
assert (
f"Issue marked as resolved in {release_name} by {self.user.get_display_name()}"
Expand Down
13 changes: 12 additions & 1 deletion tests/sentry/issues/endpoints/test_organization_group_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4112,6 +4112,7 @@ def test_self_assign_issue_next_release(self) -> None:
activity = Activity.objects.get(
group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value
)
assert activity.data is not None
assert activity.data["version"] == ""
with assume_test_silo_mode(SiloMode.CONTROL):
uo1.delete()
Expand Down Expand Up @@ -4178,7 +4179,7 @@ def test_in_semver_projects_group_resolution_stores_current_release_version(self
ident=grp_resolution.id,
)

assert "current_release_version" in activity.data
assert activity.data is not None
assert activity.data["current_release_version"] == release_2.version

def test_in_non_semver_projects_group_resolution_stores_current_release_version(self) -> None:
Expand Down Expand Up @@ -4328,6 +4329,7 @@ def test_in_non_semver_projects_resolved_in_next_release_is_equated_to_in_releas
type=ActivityType.SET_RESOLVED_IN_RELEASE.value,
ident=grp_resolution.id,
)
assert activity.data is not None
assert activity.data["version"] == release_2.version

def test_selective_status_update(self) -> None:
Expand Down Expand Up @@ -4397,6 +4399,7 @@ def test_set_resolved_in_current_release(self) -> None:
activity = Activity.objects.get(
group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value
)
assert activity.data is not None
assert activity.data["version"] == release.version
assert GroupHistory.objects.filter(
group=group, status=GroupHistoryStatus.SET_RESOLVED_IN_RELEASE
Expand Down Expand Up @@ -4438,6 +4441,7 @@ def test_set_resolved_in_explicit_release(self) -> None:
activity = Activity.objects.get(
group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value
)
assert activity.data is not None
assert activity.data["version"] == release.version

def test_in_semver_projects_set_resolved_in_explicit_release(self) -> None:
Expand Down Expand Up @@ -4482,6 +4486,7 @@ def test_in_semver_projects_set_resolved_in_explicit_release(self) -> None:
activity = Activity.objects.get(
group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value
)
assert activity.data is not None
assert activity.data["version"] == release_1.version

assert GroupResolution.has_resolution(group=group, release=release_2)
Expand Down Expand Up @@ -4519,6 +4524,7 @@ def test_set_resolved_in_next_release(self) -> None:
activity = Activity.objects.get(
group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value
)
assert activity.data is not None
assert activity.data["version"] == ""

def test_set_resolved_in_next_release_legacy(self) -> None:
Expand Down Expand Up @@ -4556,6 +4562,7 @@ def test_set_resolved_in_next_release_legacy(self) -> None:
activity = Activity.objects.get(
group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value
)
assert activity.data is not None
assert activity.data["version"] == ""

def test_set_resolved_in_explicit_commit_unreleased(self) -> None:
Expand Down Expand Up @@ -4588,6 +4595,7 @@ def test_set_resolved_in_explicit_commit_unreleased(self) -> None:
).exists()

activity = Activity.objects.get(group=group, type=ActivityType.SET_RESOLVED_IN_COMMIT.value)
assert activity.data is not None
assert activity.data["commit"] == commit.id
assert GroupHistory.objects.filter(
group=group, status=GroupHistoryStatus.SET_RESOLVED_IN_COMMIT
Expand Down Expand Up @@ -4626,6 +4634,7 @@ def test_set_resolved_in_explicit_commit_released(self) -> None:
).exists()

activity = Activity.objects.get(group=group, type=ActivityType.SET_RESOLVED_IN_COMMIT.value)
assert activity.data is not None
assert activity.data["commit"] == commit.id

resolution = GroupResolution.objects.get(group=group)
Expand Down Expand Up @@ -4759,6 +4768,7 @@ def test_snooze_count(self) -> None:
assert snooze.user_count is None
assert snooze.user_window is None
assert snooze.window is None
assert snooze.state is not None
assert snooze.state["times_seen"] == 1

assert response.data["status"] == "ignored"
Expand Down Expand Up @@ -4797,6 +4807,7 @@ def test_snooze_user_count(self) -> None:
assert snooze.user_count == 10
assert snooze.user_window is None
assert snooze.window is None
assert snooze.state is not None
assert snooze.state["users_seen"] == 10

assert response.data["status"] == "ignored"
Expand Down
2 changes: 2 additions & 0 deletions tests/sentry/issues/test_status_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_ignore_new_issue(self, issue_ignored: Any) -> None:

assert issue_ignored.called
activity = Activity.objects.get(group=self.group, type=ActivityType.SET_IGNORED.value)
assert activity.data is not None
assert activity.data.get("ignoreDuration") == 30

assert GroupHistory.objects.filter(
Expand All @@ -106,6 +107,7 @@ def test_ignore_until_escalating(self, issue_ignored: Any) -> None:

assert issue_ignored.called
activity = Activity.objects.get(group=self.group, type=ActivityType.SET_IGNORED.value)
assert activity.data is not None
assert activity.data.get("ignoreUntilEscalating")

assert GroupHistory.objects.filter(
Expand Down
2 changes: 2 additions & 0 deletions tests/sentry/models/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_get_activities_for_group_priority(self):
assert act_for_group[0] == activities[-1]
assert act_for_group[1] == activities[-2]
assert act_for_group[-1].type == ActivityType.FIRST_SEEN.value
assert act_for_group[-1].data is not None
assert act_for_group[-1].data["priority"] == PriorityLevel.HIGH.to_str()

def test_get_activities_for_group_simple_priority_ff_on_dups(self):
Expand Down Expand Up @@ -90,6 +91,7 @@ def test_get_activities_for_group_simple_priority_ff_on_dups(self):
assert act_for_group[0] == activities[-1]
assert act_for_group[1] == activities[-2]
assert act_for_group[-1].type == ActivityType.FIRST_SEEN.value
assert act_for_group[-1].data is not None
assert act_for_group[-1].data["priority"] == PriorityLevel.HIGH.to_str()

def test_get_activities_for_group_simple(self):
Expand Down
20 changes: 6 additions & 14 deletions tests/sentry/models/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ def test_no_commits_no_head_commits(self):
Deploy.notify_if_ready(deploy.id)

# make sure activity has been created
assert Activity.objects.filter(
activity = Activity.objects.get(
type=ActivityType.DEPLOY.value, project=project, ident=release.version
).exists()
assert (
Activity.objects.get(
type=ActivityType.DEPLOY.value, project=project, ident=release.version
).data["deploy_id"]
== deploy.id
)
assert activity.data is not None
assert activity.data["deploy_id"] == deploy.id
assert Deploy.objects.get(id=deploy.id).notified is True

def test_head_commits_fetch_not_complete(self):
Expand Down Expand Up @@ -114,13 +110,9 @@ def test_no_commits_fetch_complete(self):
Deploy.notify_if_ready(deploy.id, fetch_complete=True)

# make sure activity has been created
assert Activity.objects.filter(
activity = Activity.objects.get(
type=ActivityType.DEPLOY.value, project=project, ident=release.version
).exists()
assert (
Activity.objects.get(
type=ActivityType.DEPLOY.value, project=project, ident=release.version
).data["deploy_id"]
== deploy.id
)
assert activity.data is not None
assert activity.data["deploy_id"] == deploy.id
assert Deploy.objects.get(id=deploy.id).notified is True
Loading
Loading