-
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 #844 from maykinmedia/feature/1837-category-visibi…
…lity-digid-eherkenning ✨ [#1837] Category visibility for DigiD/eHerkenning
- Loading branch information
Showing
2 changed files
with
94 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from unittest import skip | ||
|
||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
|
||
from open_inwoner.accounts.tests.factories import UserFactory | ||
from open_inwoner.accounts.tests.factories import DigidUserFactory, UserFactory | ||
from open_inwoner.configurations.models import SiteConfiguration | ||
|
||
from .factories import CategoryFactory | ||
|
@@ -16,6 +18,35 @@ def setUpTestData(cls): | |
cls.user.email = "[email protected]" | ||
cls.user.save() | ||
|
||
cls.category1 = CategoryFactory( | ||
name="0001", | ||
visible_for_anonymous=True, | ||
visible_for_authenticated=True, | ||
visible_for_citizens=False, | ||
visible_for_companies=False, | ||
) | ||
cls.category2 = CategoryFactory( | ||
name="0002", | ||
visible_for_anonymous=True, | ||
visible_for_authenticated=False, | ||
visible_for_citizens=True, | ||
visible_for_companies=True, | ||
) | ||
cls.category3 = CategoryFactory( | ||
name="0003", | ||
visible_for_anonymous=False, | ||
visible_for_authenticated=True, | ||
visible_for_citizens=True, | ||
visible_for_companies=False, | ||
) | ||
cls.category4 = CategoryFactory( | ||
name="0004", | ||
visible_for_anonymous=False, | ||
visible_for_authenticated=False, | ||
visible_for_citizens=False, | ||
visible_for_companies=True, | ||
) | ||
|
||
def test_category_list_view_access_restricted(self): | ||
config = SiteConfiguration.get_solo() | ||
config.hide_categories_from_anonymous_users = True | ||
|
@@ -48,6 +79,64 @@ def test_category_list_view_access_not_restricted(self): | |
|
||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_category_list_view_visibility_for_anonymous_user(self): | ||
config = SiteConfiguration.get_solo() | ||
config.hide_categories_from_anonymous_users = False | ||
config.save() | ||
|
||
url = reverse("products:category_list") | ||
|
||
# request with anonymous user | ||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category1, self.category2] | ||
) | ||
|
||
def test_category_list_view_visibility_for_authenticated_user(self): | ||
url = reverse("products:category_list") | ||
|
||
self.client.force_login(self.user) | ||
|
||
# request with authenticated user | ||
response = self.client.get(url, user=self.user) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category1, self.category3] | ||
) | ||
|
||
def test_category_list_view_visibility_for_digid_user(self): | ||
url = reverse("products:category_list") | ||
|
||
user = DigidUserFactory() | ||
self.client.force_login(user) | ||
|
||
# request with DigiD user | ||
response = self.client.get(url, user=user) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category2, self.category3] | ||
) | ||
|
||
@skip("eHerkenning is not implemented yet") | ||
def test_category_list_view_visibility_for_eherkenning_user(self): | ||
url = reverse("products:category_list") | ||
|
||
# TODO should be eHerkenningUserFactory | ||
user = DigidUserFactory() | ||
self.client.force_login(user) | ||
|
||
# request with eHerkenning user | ||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
list(response.context["object_list"]), [self.category2, self.category4] | ||
) | ||
|
||
|
||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
class CategoryDetailViewTest(TestCase): | ||
|