|
1 | 1 | from datetime import datetime, timedelta
|
2 |
| -from unittest.mock import Mock, patch |
| 2 | +from unittest.mock import MagicMock, Mock, patch |
3 | 3 |
|
4 | 4 | import pytest
|
5 | 5 | from django.http import QueryDict
|
@@ -264,6 +264,102 @@ def test_ignore_with_substatus_archived_until_escalating(self, send_robust: Mock
|
264 | 264 | assert not GroupInbox.objects.filter(group=group).exists()
|
265 | 265 |
|
266 | 266 |
|
| 267 | +class MergeGroupsTest(TestCase): |
| 268 | + @patch("sentry.api.helpers.group_index.update.handle_merge") |
| 269 | + def test_simple(self, mock_handle_merge: MagicMock): |
| 270 | + group_ids = [self.create_group().id, self.create_group().id] |
| 271 | + project = self.project |
| 272 | + |
| 273 | + request = self.make_request(method="PUT") |
| 274 | + request.user = self.user |
| 275 | + request.data = {"merge": 1} |
| 276 | + request.GET = {"id": group_ids, "project": [project.id]} |
| 277 | + |
| 278 | + update_groups(request, group_ids, [project], self.organization.id, search_fn=Mock()) |
| 279 | + |
| 280 | + call_args = mock_handle_merge.call_args.args |
| 281 | + |
| 282 | + assert len(call_args) == 3 |
| 283 | + # Have to convert to ids because first argument is a queryset |
| 284 | + assert [group.id for group in call_args[0]] == group_ids |
| 285 | + assert call_args[1] == {project.id: project} |
| 286 | + assert call_args[2] == self.user |
| 287 | + |
| 288 | + @patch("sentry.api.helpers.group_index.update.handle_merge") |
| 289 | + def test_multiple_projects(self, mock_handle_merge: MagicMock): |
| 290 | + project1 = self.create_project() |
| 291 | + project2 = self.create_project() |
| 292 | + projects = [project1, project2] |
| 293 | + project_ids = [project.id for project in projects] |
| 294 | + |
| 295 | + group_ids = [ |
| 296 | + self.create_group(project1).id, |
| 297 | + self.create_group(project2).id, |
| 298 | + ] |
| 299 | + |
| 300 | + request = self.make_request(method="PUT") |
| 301 | + request.user = self.user |
| 302 | + request.data = {"merge": 1} |
| 303 | + request.GET = {"id": group_ids, "project": project_ids} |
| 304 | + |
| 305 | + response = update_groups( |
| 306 | + request, group_ids, projects, self.organization.id, search_fn=Mock() |
| 307 | + ) |
| 308 | + |
| 309 | + assert response.data == {"detail": "Merging across multiple projects is not supported"} |
| 310 | + assert mock_handle_merge.call_count == 0 |
| 311 | + |
| 312 | + def test_metrics(self): |
| 313 | + for referer, expected_referer_tag in [ |
| 314 | + ("https://sentry.io/organizations/dogsaregreat/issues/", "issue stream"), |
| 315 | + ("https://dogsaregreat.sentry.io/issues/", "issue stream"), |
| 316 | + ( |
| 317 | + "https://sentry.io/organizations/dogsaregreat/issues/12311121/similar/", |
| 318 | + "similar issues tab", |
| 319 | + ), |
| 320 | + ( |
| 321 | + "https://dogsaregreat.sentry.io/issues/12311121/similar/", |
| 322 | + "similar issues tab", |
| 323 | + ), |
| 324 | + ( |
| 325 | + "https://sentry.io/organizations/dogsaregreat/some/other/path/", |
| 326 | + "unknown", |
| 327 | + ), |
| 328 | + ( |
| 329 | + "https://dogsaregreat.sentry.io/some/other/path/", |
| 330 | + "unknown", |
| 331 | + ), |
| 332 | + ( |
| 333 | + "", |
| 334 | + "unknown", |
| 335 | + ), |
| 336 | + ]: |
| 337 | + |
| 338 | + group_ids = [ |
| 339 | + self.create_group(platform="javascript").id, |
| 340 | + self.create_group(platform="javascript").id, |
| 341 | + ] |
| 342 | + project = self.project |
| 343 | + |
| 344 | + request = self.make_request(method="PUT") |
| 345 | + request.user = self.user |
| 346 | + request.data = {"merge": 1} |
| 347 | + request.GET = {"id": group_ids, "project": [project.id]} |
| 348 | + request.META = {"HTTP_REFERER": referer} |
| 349 | + |
| 350 | + with patch("sentry.api.helpers.group_index.update.metrics.incr") as mock_metrics_incr: |
| 351 | + update_groups(request, group_ids, [project], self.organization.id, search_fn=Mock()) |
| 352 | + |
| 353 | + mock_metrics_incr.assert_any_call( |
| 354 | + "grouping.merge_issues", |
| 355 | + sample_rate=1.0, |
| 356 | + tags={ |
| 357 | + "platform": "javascript", |
| 358 | + "referer": expected_referer_tag, |
| 359 | + }, |
| 360 | + ) |
| 361 | + |
| 362 | + |
267 | 363 | class TestHandleIsSubscribed(TestCase):
|
268 | 364 | def setUp(self) -> None:
|
269 | 365 | self.group = self.create_group()
|
|
0 commit comments