class TestStudentAdmin(TestCase): def setUp(self): self.user = UserFactory(is_superuser=True) student_group = Group.objects.get(name="Students") self.student_user = UserFactory() self.student_user.groups.add(student_group) admin_permission = Permission.objects.get(codename="access_admin") student_group.permissions.add(admin_permission) self.student_user.save() def test_search_is_visible_for_superusers(self): self.client.force_login(self.user) response = self.client.get("/admin/") self.assertEqual(response.status_code, 200) self.assertContains( response, '<input type="text" id="menu-search-q" name="q" placeholder="Search" />', ) def test_search_is_not_visible_for_students(self): self.client.force_login(self.student_user) response = self.client.get("/admin/") self.assertEqual(response.status_code, 200) self.assertNotContains( response, '<input type="text" id="menu-search-q" name="q" placeholder="Search" />', )
def setUp(self): # Find root page self.student = UserFactory(username="******") 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()
def setUp(self): self.user = UserFactory(is_superuser=True) student_group = Group.objects.get(name="Students") self.student_user = UserFactory() self.student_user.groups.add(student_group) admin_permission = Permission.objects.get(codename="access_admin") student_group.permissions.add(admin_permission) self.student_user.save()
class TestUserModel(TestCase): def setUp(self): self.student_user = UserFactory() self.student_group = Group.objects.get(name="Students") self.student_user.groups.add(self.student_group) self.student_user.save() def test_is_student(self): self.assertTrue(self.student_user.is_student()) def test_is_not_student(self): self.student_user.groups.remove(self.student_group) self.assertFalse(self.student_user.is_student())
class TestPerRequestEditHandler(TestCase, WagtailTestUtils): def setUp(self): # Find root page self.student = UserFactory(username="******") 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() def test_create_page_with_per_request_custom_edit_handlers(self): """ Test that per-request custom behaviour in edit handlers is honoured """ # non-superusers should not see secret_data self.client.force_login(self.student) response = self.client.get( reverse("wagtailadmin_pages:edit", args=(self.student_page.id, ))) self.assertEqual(response.status_code, 200) self.assertContains(response, '"profile_image"') self.assertNotContains(response, '"student_user_account"') # superusers should see secret_data self.client.force_login(self.user) response = self.client.get( reverse("wagtailadmin_pages:edit", args=(self.student_page.id, ))) self.assertEqual(response.status_code, 200) self.assertContains(response, '"profile_image"') self.assertContains(response, '"student_user_account"')
def setUp(self): self.user = UserFactory(is_superuser=True) self.home_page = HomePage.objects.first() self.student_index = StudentIndexPageFactory( parent=self.home_page, title="Students", slug="students", introduction="students", ) self.form_data = { "first_name": "Monty", "last_name": "python", "email": "*****@*****.**", "username": "******", "create_student_page": True, "student_user_image_collection": CollectionFactory(name="Student: Monty python").id, } students = Group.objects.get(name="Students") admin_permission = Permission.objects.get(codename="access_admin") students.permissions.add(admin_permission)
def test_set_password_reset_link(self): user = UserFactory() reset_link = get_set_password_url(user) self.assertRegex( reset_link, r"^/admin/password_reset/confirm/([0-9A-Za-z_\-]+)/([0-9A-Za-z]{1,6}-[0-9A-Za-z]{8,32})", )
def setUp(self): self.user = UserFactory(is_superuser=True) self.home_page = HomePage.objects.first() self.student_index = StudentIndexPageFactory( parent=self.home_page, title="Students", slug="students", introduction="students", ) self.collection = CollectionFactory(name="Student: Monty python") self.form_data = { "first_name": "Monty", "last_name": "python", "email": "*****@*****.**", "username": "******", "create_student_page": False, "student_user_image_collection": self.collection.id, }
def test_factories(self): UserFactory()
def setUp(self): self.student_user = UserFactory() self.student_group = Group.objects.get(name="Students") self.student_user.groups.add(self.student_group) self.student_user.save()
def setUp(self): super().setUp() self.user = UserFactory(is_superuser=True) self.client.force_login(self.user) self.home_page = HomePage.objects.first() self.student_index = StudentIndexPageFactory( parent=self.home_page, title="Students", slug="students", introduction="students", ) self.student = User.objects.create_user( username="******", first_name="fox", last_name="mulder", email="*****@*****.**", password="******", ) self.collection = CollectionFactory(name="Student: fox mulder") student_group = Group.objects.get(name="Students") # Add the student group self.student.groups.add(student_group) self.student.save() self.post_data = { "title": "Fox Mulder", "slug": "fox", "student_title": "Dr", "first_name": "Fox", "last_name": "Mulder", "profile_image": "", "email": "", "programme": "", "degree_start_date": "", "degree_end_date": "", "degree_status": "", "link_to_final_thesis": "", "related_supervisor-TOTAL_FORMS": "0", "related_supervisor-INITIAL_FORMS": "0", "related_supervisor-MIN_NUM_FORMS": "0", "related_supervisor-MAX_NUM_FORMS": "1000", "introduction": "", "bio": rich_text(""), "related_project_pages-TOTAL_FORMS": "0", "related_project_pages-INITIAL_FORMS": "0", "related_project_pages-MIN_NUM_FORMS": "0", "related_project_pages-MAX_NUM_FORMS": "5", "gallery_slides-TOTAL_FORMS": "0", "gallery_slides-INITIAL_FORMS": "0", "gallery_slides-MIN_NUM_FORMS": "0", "gallery_slides-MAX_NUM_FORMS": "5", "biography": rich_text(""), "degrees": rich_text(""), "experience": rich_text(""), "awards": rich_text(""), "funding": rich_text(""), "exhibitions": rich_text(""), "publications": rich_text(""), "research_outputs": rich_text(""), "conferences": rich_text(""), "additional_information_title": "", "addition_information_content": rich_text(""), "relatedlinks-TOTAL_FORMS": "0", "relatedlinks-INITIAL_FORMS": "0", "relatedlinks-MIN_NUM_FORMS": "0", "relatedlinks-MAX_NUM_FORMS": "5", "related_area_of_expertise-TOTAL_FORMS": "0", "related_area_of_expertise-INITIAL_FORMS": "0", "related_area_of_expertise-MIN_NUM_FORMS": "0", "related_area_of_expertise-MAX_NUM_FORMS": "1000", "related_research_centre_pages-TOTAL_FORMS": "0", "related_research_centre_pages-INITIAL_FORMS": "0", "related_research_centre_pages-MIN_NUM_FORMS": "0", "related_research_centre_pages-MAX_NUM_FORMS": "1000", "related_schools-TOTAL_FORMS": "0", "related_schools-INITIAL_FORMS": "0", "related_schools-MIN_NUM_FORMS": "0", "related_schools-MAX_NUM_FORMS": "1000", "personal_links-TOTAL_FORMS": "0", "personal_links-INITIAL_FORMS": "0", "personal_links-MIN_NUM_FORMS": "0", "personal_links-MAX_NUM_FORMS": "5", "related_project_pages": inline_formset([]), "gallery_slides": inline_formset([]), "related_supervisor": inline_formset([]), "relatedlinks": inline_formset([]), "related_area_of_expertise": inline_formset([]), "related_research_centre_pages": inline_formset([]), "related_schools": inline_formset([]), "personal_links": inline_formset([]), "student_funding": rich_text(""), "seo_title": "", "show_in_menus": "on", "search_description": "", "social_image": "", "social_text": "", "listing_image": "", "listing_title": "", "listing_summary": "", "go_live_at": "", "expire_at": "", "student_user_image_collection": "", "student_user_account": "", }