コード例 #1
0
    def test_can_create_user_and_log_in(self):
        # Joe goes to the new boards app
        # He sees an account link and clicks it

        # Then he clicks the signup link

        # He fills the username, the name, the lastname,
        # the identification number, the password, and
        # Retypes the password

        # He clicks the signup now button

        # And the page tells him his user has been created
        profile = util.get_unsaved_user()
        AccountSignupWindow(self).create_user(profile)

        # Now he proceds to log in
        # He first goes to the index page and clicks the account link again

        # Now he goes to the login tab
        account_login_window = AccountLoginWindow(self).go_to_login_page()

        # And he introduces his username and his password
        account_login_window.write_in_username_input_box(profile.user.username)
        account_login_window.write_in_password_input_box(profile.user.password)

        # And he clicks the login button
        account_login_window.click_login_button()

        # Now he just logs out
        account_login_window.click_logout()
コード例 #2
0
 def test_redirects_to_home_view(self):
     user = util.get_unsaved_user()
     response = self.client.post(
         reverse('accounts:login'),
         data=util.get_login_dict_from_user(user),
     )
     self.assertRedirects(response, reverse('home'))
コード例 #3
0
 def test_retype_password_incorrectly_fails_to_sign_up(self):
     """Test when the password is incorrectly retyped the user is not created"""
     user = util.get_unsaved_user()
     user_dict = util.get_register_dict_from_user(user)
     user_dict['retype_password'] = '******'
     self.client.post(reverse('accounts:signup'), data=user_dict)
     self.assertEqual(0, User.objects.count())
コード例 #4
0
    def test_form_validation_retype_password(self):
        user = util.get_unsaved_user()
        data = util.get_register_dict_from_user(user)
        data['password'] = '******'

        form = SignUpUserForm(data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['retype_password'], [PASSWORD_DONT_MATCH])
コード例 #5
0
    def test_form_save(self):
        user = util.get_unsaved_user()
        data = util.get_register_dict_from_user(user)

        form = SignUpUserForm(data)
        form.is_valid()
        new_user = form.save()

        self.assertEqual(new_user, User.objects.first())
コード例 #6
0
 def test_form_validation_username(self):
     """Creates a user and then creates that user again so that the
     Test can check the error or repeated username"""
     UserFactory()
     user = util.get_unsaved_user()
     data = util.get_register_dict_from_user(user)
     form = SignUpUserForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['username'],
                      [USERNAME_ALREADY_IN_USER % user.username])
コード例 #7
0
    def test_signup_fails_with_repeated_user(self):
        # Joe goes to the new boards app
        # He sees an account link and clicks it

        # Then he clicks the signup link

        # He fills the username, the name, the lastname,
        # the identification number, the password, and
        # Retypes the password

        # He clicks the signup now button

        # And the page tells him his user has been created
        profile = util.get_unsaved_user()
        AccountSignupWindow(self).create_user(profile)
コード例 #8
0
    def test_can_create_user_and_log_in(self):
        # Nato goes to the new blog app
        # and notices a person icon he clicks it

        # Now he can see a couple of tabs so he clicks the tab
        # That says register

        # He fills the username, the email, the password, and
        # Retypes the password

        # He clicks the register now button

        # And the page tells him his user has been created
        user = util.get_unsaved_user()
        AccountSignupPopupWindow(self).create_user(user)

        # Now he proceds to log in
        # He first goes to the index page and clicks the person
        # icon again

        # Now he goes to the login tab
        account_login_popup_window = AccountLoginPopupWindow(
            self).go_to_login_popup()

        # And he introduces his username and his password
        account_login_popup_window.write_in_username_input_box(user.username)
        account_login_popup_window.write_in_password_input_box(user.password)

        # And he clicks the login button
        account_login_popup_window.click_login_button()

        # Now the page tells him he is logged in
        account_login_popup_window.check_message_in_messages(
            'The user has been logged in')

        # Now he just logs out
        account_login_popup_window.click_logout()

        # Now the page tells him he is logged out
        account_login_popup_window.check_message_in_messages(
            'The user has been logged out')
コード例 #9
0
 def test_succesfully_signup_user(self):
     user = util.get_unsaved_user()
     self.client.post(reverse('accounts:signup'),
                      data=util.get_register_dict_from_user(user))
     self.assertEqual(1, User.objects.count())
     self.assertUserIsSavedCorrectly(user, User.objects.first())
コード例 #10
0
 def test_form_validation_blank_content(self):
     user = util.get_unsaved_user(username='')
     data = util.get_register_dict_from_user(user)
     form = SignUpUserForm(data=data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['username'], ['This field is required.'])
コード例 #11
0
 def test_no_errors_if_data_is_correct(self):
     user = util.get_unsaved_user()
     data = util.get_register_dict_from_user(user)
     form = SignUpUserForm(data=data)
     self.assertTrue(form.is_valid())