|
| 1 | +import django_dynamic_fixture as fixture |
| 2 | +from django.contrib.contenttypes.models import ContentType |
1 | 3 | from django.test import override_settings
|
2 | 4 | from django.urls import reverse
|
3 | 5 | from django.urls.exceptions import NoReverseMatch
|
4 | 6 |
|
| 7 | +from readthedocs.notifications.models import Notification |
| 8 | +from readthedocs.organizations.models import Organization |
5 | 9 | from readthedocs.subscriptions.constants import TYPE_CONCURRENT_BUILDS
|
6 | 10 | from readthedocs.subscriptions.products import RTDProductFeature
|
7 | 11 |
|
@@ -51,6 +55,38 @@ def test_organizations_notifications_list(self):
|
51 | 55 | self._get_response_dict("organizations-notifications-list"),
|
52 | 56 | )
|
53 | 57 |
|
| 58 | + def test_organizations_notifications_list_only_given_organization(self): |
| 59 | + url = reverse( |
| 60 | + "organizations-notifications-list", |
| 61 | + kwargs={ |
| 62 | + "parent_lookup_organization__slug": self.organization.slug, |
| 63 | + }, |
| 64 | + ) |
| 65 | + other_organization = fixture.get( |
| 66 | + Organization, |
| 67 | + pub_date=self.created, |
| 68 | + modified_date=self.modified, |
| 69 | + name="other_organization", |
| 70 | + slug="other_organization", |
| 71 | + owners=[self.me], |
| 72 | + ) |
| 73 | + |
| 74 | + fixture.get( |
| 75 | + Notification, |
| 76 | + attached_to_content_type=ContentType.objects.get_for_model( |
| 77 | + other_organization |
| 78 | + ), |
| 79 | + attached_to_id=other_organization.pk, |
| 80 | + ) |
| 81 | + |
| 82 | + self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}") |
| 83 | + response = self.client.get(url) |
| 84 | + self.assertEqual(response.status_code, 200) |
| 85 | + self.assertDictEqual( |
| 86 | + response.json(), |
| 87 | + self._get_response_dict("organizations-notifications-list"), |
| 88 | + ) |
| 89 | + |
54 | 90 | def test_organizations_notifications_list_other_user(self):
|
55 | 91 | url = reverse(
|
56 | 92 | "organizations-notifications-list",
|
@@ -103,6 +139,28 @@ def test_organizations_notifications_detail(self):
|
103 | 139 | self._get_response_dict("organizations-notifications-detail"),
|
104 | 140 | )
|
105 | 141 |
|
| 142 | + def test_organizations_notifications_detail_other_organization(self): |
| 143 | + other_organization = fixture.get( |
| 144 | + Organization, |
| 145 | + pub_date=self.created, |
| 146 | + modified_date=self.modified, |
| 147 | + name="new_org", |
| 148 | + slug="new_org", |
| 149 | + owners=[self.me], |
| 150 | + ) |
| 151 | + |
| 152 | + url = reverse( |
| 153 | + "organizations-notifications-detail", |
| 154 | + kwargs={ |
| 155 | + "parent_lookup_organization__slug": other_organization.slug, |
| 156 | + "notification_pk": self.notification_organization.pk, |
| 157 | + }, |
| 158 | + ) |
| 159 | + |
| 160 | + self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}") |
| 161 | + response = self.client.get(url) |
| 162 | + self.assertEqual(response.status_code, 404) |
| 163 | + |
106 | 164 | def test_organizations_notifications_detail_other(self):
|
107 | 165 | url = reverse(
|
108 | 166 | "organizations-notifications-detail",
|
|
0 commit comments