-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1046 from maykinmedia/fix/2143-categories-for-admins
🐛 [#2143] Show all categories to staff users
- Loading branch information
Showing
2 changed files
with
46 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,32 +22,28 @@ | |
|
||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
class CategoryListViewTest(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = UserFactory() | ||
cls.user.set_password("12345") | ||
cls.user.email = "[email protected]" | ||
cls.user.save() | ||
|
||
cls.category1 = CategoryFactory( | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.category_anonymous = CategoryFactory( | ||
name="0001", | ||
visible_for_anonymous=True, | ||
visible_for_citizens=False, | ||
visible_for_companies=False, | ||
) | ||
cls.category2 = CategoryFactory( | ||
self.category_all = CategoryFactory( | ||
name="0002", | ||
visible_for_anonymous=True, | ||
visible_for_citizens=True, | ||
visible_for_companies=True, | ||
) | ||
cls.category3 = CategoryFactory( | ||
self.category_citizens = CategoryFactory( | ||
name="0003", | ||
visible_for_anonymous=False, | ||
visible_for_citizens=True, | ||
visible_for_companies=False, | ||
) | ||
cls.category4 = CategoryFactory( | ||
self.category_companies = CategoryFactory( | ||
name="0004", | ||
visible_for_anonymous=False, | ||
visible_for_citizens=False, | ||
|
@@ -61,14 +57,16 @@ def test_category_list_view_access_restricted(self): | |
|
||
url = reverse("products:category_list") | ||
|
||
user = UserFactory() | ||
|
||
# request with anonymous user | ||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, "/accounts/login/?next=/products/") | ||
|
||
# request with user logged in | ||
self.client.login(email=self.user.email, password="12345") | ||
self.client.force_login(user=user) | ||
|
||
response = self.client.get(url) | ||
|
||
|
@@ -98,7 +96,8 @@ def test_category_list_view_visibility_for_anonymous_user(self): | |
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category1, self.category2] | ||
list(response.context["object_list"]), | ||
[self.category_anonymous, self.category_all], | ||
) | ||
|
||
def test_category_list_view_visibility_for_digid_user(self): | ||
|
@@ -112,7 +111,8 @@ def test_category_list_view_visibility_for_digid_user(self): | |
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category2, self.category3] | ||
list(response.context["object_list"]), | ||
[self.category_all, self.category_citizens], | ||
) | ||
|
||
@override_settings(MIDDLEWARE=PATCHED_MIDDLEWARE) | ||
|
@@ -126,20 +126,38 @@ def test_category_list_view_visibility_for_eherkenning_user(self): | |
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category2, self.category4] | ||
list(response.context["object_list"]), | ||
[self.category_all, self.category_companies], | ||
) | ||
|
||
def test_category_list_view_visibility_for_staff_user(self): | ||
url = reverse("products:category_list") | ||
|
||
user = UserFactory(is_staff=True) | ||
self.client.force_login(user) | ||
|
||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), | ||
[ | ||
self.category_anonymous, | ||
self.category_all, | ||
self.category_citizens, | ||
self.category_companies, | ||
], | ||
) | ||
|
||
|
||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
class CategoryDetailViewTest(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = DigidUserFactory() | ||
cls.user.set_password("12345") | ||
cls.user.email = "[email protected]" | ||
cls.user.save() | ||
|
||
cls.category = CategoryFactory.create( | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.user = DigidUserFactory() | ||
|
||
self.category = CategoryFactory.create( | ||
name="test cat", | ||
description="A <em>descriptive</em> description", | ||
visible_for_anonymous=False, | ||
|
@@ -159,7 +177,7 @@ def test_category_detail_view_access_restricted(self): | |
self.assertEqual(response.url, "/accounts/login/?next=/products/test-cat/") | ||
|
||
# request with user logged in | ||
self.client.login(email=self.user.email, password="12345") | ||
self.client.force_login(user=self.user) | ||
|
||
response = self.client.get(url) | ||
|
||
|