Skip to content

Commit 682d3c0

Browse files
authored
ref(stacktrace-link): Minor refactor (#101154)
There's too much happening within the setUp call, thus, making it less clear when reading the tests what code mappings are being considered for the test. This makes it more clear.
1 parent 61b194c commit 682d3c0

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

src/sentry/integrations/utils/stacktrace_link.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
from collections.abc import Sequence
45
from typing import TYPE_CHECKING, NotRequired, TypedDict
56

67
from sentry.constants import ObjectStatus
@@ -10,7 +11,6 @@
1011
from sentry.issues.auto_source_code_config.code_mapping import (
1112
convert_stacktrace_frame_path_to_source_path,
1213
)
13-
from sentry.models.organization import Organization
1414
from sentry.models.repository import Repository
1515
from sentry.shared_integrations.exceptions import ApiError
1616
from sentry.utils.event_frames import EventFrame
@@ -82,9 +82,7 @@ class StacktraceLinkOutcome(TypedDict):
8282

8383

8484
def get_stacktrace_config(
85-
configs: list[RepositoryProjectPathConfig],
86-
ctx: StacktraceLinkContext,
87-
organization: Organization | None = None,
85+
configs: Sequence[RepositoryProjectPathConfig], ctx: StacktraceLinkContext
8886
) -> StacktraceLinkOutcome:
8987
result: StacktraceLinkOutcome = {
9088
"source_url": None,

src/sentry/issues/endpoints/project_stacktrace_link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get(self, request: Request, project: Project) -> Response:
154154
scope = Scope.get_isolation_scope()
155155

156156
set_top_tags(scope, project, ctx, len(configs) > 0)
157-
result = get_stacktrace_config(configs, ctx, project.organization)
157+
result = get_stacktrace_config(configs, ctx)
158158
error = result["error"]
159159
src_path = result["src_path"]
160160
# Post-processing before exiting scope context

tests/sentry/issues/endpoints/test_project_stacktrace_link.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,7 @@ def expected_configurations(
124124

125125

126126
class ProjectStacktraceLinkTest(BaseProjectStacktraceLink):
127-
endpoint = "sentry-api-0-project-stacktrace-link"
128-
129-
def setUp(self) -> None:
130-
BaseProjectStacktraceLink.setUp(self)
131-
self.code_mapping1 = self._create_code_mapping(
132-
stack_root="usr/src/getsentry/",
133-
source_root="",
134-
)
135-
self.code_mapping2 = self._create_code_mapping(
136-
stack_root="sentry/",
137-
source_root="src/sentry/",
138-
automatically_generated=True, # Created by the automation
139-
)
140-
141-
self.filepath = "usr/src/getsentry/src/sentry/src/sentry/utils/safe.py"
127+
filepath = "usr/src/getsentry/src/sentry/src/sentry/utils/safe.py"
142128

143129
def test_no_filepath(self) -> None:
144130
"""The file query search is missing"""
@@ -168,10 +154,11 @@ def test_no_configs(self) -> None:
168154

169155
def test_file_not_found_error(self) -> None:
170156
"""File matches code mapping but it cannot be found in the source repository."""
157+
cm = self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="")
171158
response = self.get_success_response(
172159
self.organization.slug, self.project.slug, qs_params={"file": self.filepath}
173160
)
174-
assert response.data["config"] == self.expected_configurations(self.code_mapping1)
161+
assert response.data["config"] == self.expected_configurations(cm)
175162
assert not response.data["sourceUrl"]
176163
assert response.data["error"] == "file_not_found"
177164
assert response.data["integrations"] == [serialized_integration(self.integration)]
@@ -182,6 +169,8 @@ def test_file_not_found_error(self) -> None:
182169

183170
def test_stack_root_mismatch_error(self) -> None:
184171
"""Looking for a stacktrace file path that will not match any code mappings"""
172+
# At least one code mapping to produce the stack_root_mismatch error
173+
self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="")
185174
response = self.get_success_response(
186175
self.organization.slug, self.project.slug, qs_params={"file": "wrong/file/path"}
187176
)
@@ -195,10 +184,11 @@ def test_config_and_source_url(self) -> None:
195184
with patch.object(
196185
ExampleIntegration, "get_stacktrace_link", return_value="https://sourceurl.com/"
197186
):
187+
cm = self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="")
198188
response = self.get_success_response(
199189
self.organization.slug, self.project.slug, qs_params={"file": self.filepath}
200190
)
201-
assert response.data["config"] == self.expected_configurations(self.code_mapping1)
191+
assert response.data["config"] == self.expected_configurations(cm)
202192
assert response.data["sourceUrl"] == "https://sourceurl.com/"
203193
assert response.data["integrations"] == [serialized_integration(self.integration)]
204194

@@ -207,6 +197,8 @@ def test_file_no_stack_root_match(self, mock_integration: MagicMock) -> None:
207197
# Pretend that the file was not found in the repository
208198
mock_integration.return_value = None
209199

200+
# At least one code mapping to produce the stack_root_mismatch error
201+
self._create_code_mapping(stack_root="usr/src/getsentry/", source_root="")
210202
response = self.get_success_response(
211203
self.organization.slug,
212204
self.project.slug,

0 commit comments

Comments
 (0)