From 2695b627927e567757fad9bca07edf499fea6e3d Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Thu, 22 Feb 2024 14:24:15 +0100 Subject: [PATCH] :ok_hand: [#2143] PR feedback --- src/open_inwoner/pdc/tests/test_views.py | 54 +++++++++++++----------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/open_inwoner/pdc/tests/test_views.py b/src/open_inwoner/pdc/tests/test_views.py index 1ef14f750d..9e9382fd7f 100644 --- a/src/open_inwoner/pdc/tests/test_views.py +++ b/src/open_inwoner/pdc/tests/test_views.py @@ -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 = "test@email.com" - 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,6 +57,8 @@ def test_category_list_view_access_restricted(self): url = reverse("products:category_list") + user = UserFactory() + # request with anonymous user response = self.client.get(url) @@ -68,7 +66,7 @@ def test_category_list_view_access_restricted(self): 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,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): @@ -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 = "test@email.com" - cls.user.save() - - cls.category = CategoryFactory.create( + def setUp(self): + super().setUp() + + self.user = DigidUserFactory() + + self.category = CategoryFactory.create( name="test cat", description="A descriptive description", visible_for_anonymous=False, @@ -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)