From 53e28524cd64f754a15461f6869b9857807ebb09 Mon Sep 17 00:00:00 2001 From: Patrick Gan Date: Wed, 8 Mar 2023 11:04:52 +0800 Subject: [PATCH] Add test that student should not see related school field --- rca/people/tests/test_models.py | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/rca/people/tests/test_models.py b/rca/people/tests/test_models.py index 87b69412a..ae9aad126 100644 --- a/rca/people/tests/test_models.py +++ b/rca/people/tests/test_models.py @@ -275,3 +275,60 @@ def test_create_page_validation_no_collection(self): "If you are adding a student user account so a student can access " "this page, an image collection must be added.", ) + + +class TestStudentPageEdit(TestCase, WagtailTestUtils): + + create_view_name = "student_account_create" + + def setUp(self): + super().setUp() + self.student = UserFactory(username="student") + self.user = UserFactory(is_superuser=True) + self.student_group = Group.objects.get(name="Students") + admin_permission = Permission.objects.get(codename="access_admin") + self.student_group.permissions.add(admin_permission) + self.student.groups.add(self.student_group) + self.student.set_password("test") + self.student.save() + + self.home_page = HomePage.objects.first() + self.home_page.add_child( + instance=StudentIndexPage( + title="Students", + slug="students", + introduction="students", + ) + ) + self.student_index = StudentIndexPage.objects.first() + GroupPagePermission.objects.create( + group=self.student_group, + page=self.student_index, + permission_type="edit", + ) + self.student_index.add_child( + instance=StudentPage( + title="A student", slug="a-student", first_name="a", last_name="student" + ) + ) + self.student_page = StudentPage.objects.first() + + self.url = reverse("wagtailadmin_pages:edit", args=(self.student_page.id,)) + + def test_related_school_fields_should_be_in_page(self): + # As a superuser, there should be an option to add related schools and I should see it. + self.client.force_login(self.user) + response = self.client.get(self.url) + self.assertContains(response, "Add related schools") + self.assertContains( + response, '
\n