Skip to content

Commit

Permalink
👌 [#2143] PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Feb 22, 2024
1 parent 0533581 commit 2695b62
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/open_inwoner/pdc/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -126,7 +126,8 @@ 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):
Expand All @@ -140,20 +141,23 @@ def test_category_list_view_visibility_for_staff_user(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(
list(response.context["object_list"]),
[self.category1, self.category2, self.category3, self.category4],
[
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,
Expand All @@ -173,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)

Expand Down

0 comments on commit 2695b62

Please sign in to comment.