def test_register_page(self):
        """  test user creation functions using web form"""
        # delete user if it exists
        try:
            userKK = User.objects.get(username=username)
            userKK.delete()
        except User.DoesNotExist:
            pass

        loginDict = {}
        loginDict["username"] = username
        loginDict["email"] = email
        loginDict["password"] = passwd
        loginDict['website'] = website
        loginDict['picture'] = createPicture()

        response = self.client.post(reverse('register'),
                                    loginDict,
                                    follow=True)  # follow redirection
        self.assertEqual(response.status_code, 200)  # redirection
        userKK = User.objects.get(username=username)
        self.assertEqual(username, userKK.username)
        userProfileKK = UserProfile.objects.get(user=userKK)
        self.assertEqual(website, userProfileKK.website)
        imageName = join(settings.MEDIA_ROOT, userProfileKK.picture.name)
        with Image.open(imageName) as im:
            width, height = im.size
        self.assertEqual(width, 200)
    def test_create_user_using_view(self):
        """  test user creation functions in views.py (no form used)"""
        # delete user if it exists
        try:
            userKK = User.objects.get(username=username)
            userKK.delete()
        except User.DoesNotExist:
            pass
        # create user self.username with password self.passwd
        # fill user form
        loginDict = {}
        loginDict["username"] = username
        loginDict["email"] = email
        loginDict["password"] = passwd
        userForm = UserForm(data=loginDict)

        # fill profile form
        profileDict = {}
        profileDict['website'] = website
        # create auxiliary black image for profileForm
        filesDict = {'picture': createPicture()}
        userProfileForm = UserProfileForm(data=profileDict, files=filesDict)

        if userForm.is_valid() and userProfileForm.is_valid():
            try:
                # Save the user's form data to the database.
                user = userForm.save()
                # Now we hash the password with the set_password method.
                # Once hashed, we can update the user object.
                user.set_password(user.password)
                user.save()
                # we need to set a user object in userprofile
                userprofile = userProfileForm.save(commit=False)
                userprofile.user = user
                userprofile.save()

            except Exception as e:
                raise Exception("Error processing form: %s" % e.message)

        self.assertTrue(userForm.is_valid())
        self.assertTrue(userProfileForm.is_valid())

        # check user name
        try:
            userKK = User.objects.get(username=username)
        except User.DoesNotExist:
            userKK = User()
        self.assertEqual(userKK.email, email)

        # check file name
        try:
            userprofileKK = UserProfile.objects.get(user=userKK)
        except User.DoesNotExist:
            userprofileKK = UserProfile()
        imageName = join(settings.MEDIA_ROOT, userprofileKK.picture.name)
        with Image.open(imageName) as im:
            width, height = im.size
        self.assertEqual(width, 200)