def test_check_context_data(self): """Test to check edit profile page.""" response = HelloAppTests.authorize_admin(self) profile_ = Profile.objects.first() self.assertEqual(response.context["object"], profile_) self.assertEqual( response.context["form"].__class__, ProfileModelForm().__class__ )
def test_accessibility_and_template(self): """This test checks whether available a edit page and uses a right template.""" response = self.client.get(reverse("edit")) self.assertRedirects( response, reverse("login") + "?next=/edit/", status_code=302, ) response = HelloAppTests.authorize_admin(self) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "hello/edit.html")
def test_initial_data_of_edit_form(self): """Test to check initial data of edit profile form.""" response = HelloAppTests.authorize_admin(self) profile_ = Profile.objects.first() data_ = response.context["form"].initial self.assertEqual(data_["email"], profile_.email) self.assertEqual(data_["first_name"], profile_.first_name) self.assertEqual(data_["last_name"], profile_.last_name) self.assertEqual(data_["birthday"], profile_.birthday) self.assertEqual(data_["jabber"], profile_.jabber) self.assertEqual(data_["skype"], profile_.skype) self.assertEqual(data_["bio"], profile_.bio) self.assertEqual(data_["contacts_other"], profile_.contacts_other) self.assertEqual(data_["photo"], profile_.photo)
def test_present_admin_edit_link(self): """Test to check or no present a admin edit link for anonymous users. """ profile_ = Profile.objects.first() type_ = ContentType.objects.get_for_model(profile_.__class__) # Get admin edit url for profile. admin_url = reverse( "admin:%s_%s_change" % (type_.app_label, type_.model), args=(profile_.id,), ) # Must not be a link for anonymous user. self.assertNotContains(self.response, admin_url) # Authorise as admin response = HelloAppTests.authorize_admin(self) self.assertContains(response, admin_url)