|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from sentry.models.groupshare import GroupShare |
| 4 | +from sentry.silo.base import SiloMode |
| 5 | +from sentry.testutils.cases import TestCase |
| 6 | +from sentry.testutils.silo import assume_test_silo_mode, control_silo_test |
| 7 | + |
| 8 | + |
| 9 | +@control_silo_test(stable=True) |
| 10 | +class SharedGroupDetailsTest(TestCase): |
| 11 | + def setUp(self): |
| 12 | + self.group = self.create_group(project=self.project) |
| 13 | + self.org_domain = f"{self.organization.slug}.testserver" |
| 14 | + |
| 15 | + def share_group(self): |
| 16 | + with assume_test_silo_mode(SiloMode.REGION): |
| 17 | + return GroupShare.objects.create( |
| 18 | + project=self.project, group=self.group, user_id=self.user.id |
| 19 | + ) |
| 20 | + |
| 21 | + def assert_group_metadata_present(self, response: Any): |
| 22 | + response_body = response.content.decode("utf8") |
| 23 | + assert f'<meta property="og:title" content="{self.group.title}"' in response_body |
| 24 | + assert f'<meta property="og:description" content="{self.group.message}"' in response_body |
| 25 | + assert '<meta property="twitter:card" content="summary"' in response_body |
| 26 | + assert f'<meta property="twitter:title" content="{self.group.title}"' in response_body |
| 27 | + assert ( |
| 28 | + f'<meta property="twitter:description" content="{self.group.message}"' in response_body |
| 29 | + ) |
| 30 | + |
| 31 | + def assert_group_metadata_absent(self, response: Any): |
| 32 | + response_body = response.content.decode("utf8") |
| 33 | + assert f'<meta property="og:title" content="{self.group.title}"' not in response_body |
| 34 | + assert ( |
| 35 | + f'<meta property="og:description" content="{self.group.message}"' not in response_body |
| 36 | + ) |
| 37 | + assert '<meta property="twitter:card" content="summary"' not in response_body |
| 38 | + assert f'<meta property="twitter:title" content="{self.group.title}"' not in response_body |
| 39 | + assert ( |
| 40 | + f'<meta property="twitter:description" content="{self.group.message}"' |
| 41 | + not in response_body |
| 42 | + ) |
| 43 | + |
| 44 | + def test_get_not_found(self): |
| 45 | + response = self.client.get("/share/issue/lolnope/", HTTP_HOST=self.org_domain) |
| 46 | + assert response.status_code == 200 |
| 47 | + self.assert_group_metadata_absent(response) |
| 48 | + |
| 49 | + def test_get_org_disable_sharing(self): |
| 50 | + share = self.share_group() |
| 51 | + with assume_test_silo_mode(SiloMode.REGION): |
| 52 | + self.organization.flags.disable_shared_issues = True |
| 53 | + self.organization.save() |
| 54 | + response = self.client.get(f"/share/issue/{share.uuid}/", HTTP_HOST=self.org_domain) |
| 55 | + assert response.status_code == 200 |
| 56 | + self.assert_group_metadata_absent(response) |
| 57 | + |
| 58 | + def test_get_no_subdomain(self): |
| 59 | + share = self.share_group() |
| 60 | + response = self.client.get(f"/share/issue/{share.uuid}/") |
| 61 | + assert response.status_code == 200 |
| 62 | + self.assert_group_metadata_present(response) |
| 63 | + |
| 64 | + def test_get_success(self): |
| 65 | + share = self.share_group() |
| 66 | + response = self.client.get(f"/share/issue/{share.uuid}/", HTTP_HOST=self.org_domain) |
| 67 | + assert response.status_code == 200 |
| 68 | + self.assert_group_metadata_present(response) |
0 commit comments