Skip to content

Commit 48b7d01

Browse files
authored
ref(replay): move summarize tests out of unit tests (#97775)
- Mock the fetch_feedback_details fx which is the only reason we have DB dependency atm. - Move the file out of unit test folder since there are DB query fxs in summarize.py (currently tested in test_project_replay_summary only). We could split them up between unit/integration but I'd rather have them in the same file
1 parent 6c19c53 commit 48b7d01

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

tests/sentry/replays/unit/lib/test_summarize.py renamed to tests/sentry/replays/lib/test_summarize.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
from collections.abc import Generator
2+
from unittest.mock import Mock, patch
23

3-
from sentry.models.project import Project
44
from sentry.replays.lib.summarize import (
55
EventDict,
66
_parse_iso_timestamp_to_ms,
77
as_log_message,
88
get_summary_logs,
99
)
10-
from sentry.testutils.pytest.fixtures import django_db_all
1110
from sentry.utils import json
1211

1312

14-
@django_db_all
15-
def test_get_summary_logs(default_project: Project) -> None:
13+
@patch("sentry.replays.lib.summarize.fetch_feedback_details")
14+
def test_get_summary_logs(mock_fetch_feedback_details: Mock) -> None:
15+
16+
def _mock_fetch_feedback(feedback_id: str | None, _project_id: int) -> EventDict | None:
17+
if feedback_id == "12345678123456781234567812345678":
18+
return EventDict(
19+
category="feedback",
20+
id=feedback_id,
21+
title="User Feedback",
22+
timestamp=4.0,
23+
message="Great website!",
24+
)
25+
return None
26+
27+
mock_fetch_feedback_details.side_effect = _mock_fetch_feedback
28+
1629
def _faker() -> Generator[tuple[int, memoryview]]:
1730
yield 0, memoryview(
1831
json.dumps(
@@ -33,6 +46,17 @@ def _faker() -> Generator[tuple[int, memoryview]]:
3346
"payload": {"category": "console", "message": "world"},
3447
},
3548
},
49+
{
50+
"type": 5,
51+
"timestamp": 4.0,
52+
"data": {
53+
"tag": "breadcrumb",
54+
"payload": {
55+
"category": "sentry.feedback",
56+
"data": {"feedbackId": "12345678123456781234567812345678"},
57+
},
58+
},
59+
},
3660
]
3761
).encode()
3862
)
@@ -54,12 +78,13 @@ def _faker() -> Generator[tuple[int, memoryview]]:
5478
),
5579
]
5680

57-
result = get_summary_logs(_faker(), error_events=error_events, project_id=default_project.id)
81+
result = get_summary_logs(_faker(), error_events=error_events, project_id=1)
5882
assert result == [
5983
"User experienced an error: 'BadError: something else bad' at 1.0",
6084
"Logged: hello at 1.5",
6185
"Logged: world at 2.0",
6286
"User experienced an error: 'ZeroDivisionError: division by zero' at 3.0",
87+
"User submitted feedback: 'Great website!' at 4.0",
6388
]
6489

6590

0 commit comments

Comments
 (0)