Skip to content

Commit

Permalink
Add test that student should not see related school field
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Gan committed Mar 8, 2023
1 parent 6c836e1 commit 53e2852
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions rca/people/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<div >\n <ul class="multiple" id="id_related_schools-FORMS">'
)

# As a student, I shouldn't see it but it should still be in the template.
self.client.force_login(self.student)
response = self.client.get(self.url)
self.assertContains(response, "Add related schools")
self.assertContains(
response,
'<div style="display: none;">\n <ul class="multiple" id="id_related_schools-FORMS">',
)

0 comments on commit 53e2852

Please sign in to comment.