def test_present_photo(self):

        """Test to check or present photo on home page."""

        profile_ = Profile.objects.first()
        HelloAppTests.set_temporary_photo(profile_)
        # profile_.set_temporary_photo()

        response = self.client.get(reverse("home"))
        self.assertContains(response, profile_.photo.url)
    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_size_of_photo(self):

        """Test to check a size of photo. On save image should be
            scale to size 200x200."""

        profile_ = Profile.objects.first()
        # Get temp photo. It has demenssions of 512x512px.
        photo_ = HelloAppTests.get_temporary_photo(pil=True)
        # Check size of original image.
        self.assertLessEqual(photo_.width, 512)
        self.assertLessEqual(photo_.height, 512)

        profile_.photo = photo_.fp
        profile_.save()

        # And check after save.
        self.assertLessEqual(profile_.photo.width, 200)
        self.assertLessEqual(profile_.photo.height, 200)
    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)