Esempio n. 1
0
    def test_update_password(self):
        """Test the password"""
        
        # create dummy user (to test)
        user = ProfileFactory()
        login_check = self.client.login(
            username=user.user.username,
            password='******')
        self.assertTrue(login_check)
        
        # 1. If passwords don't match
        form_data = {
            'password_old': 'hostel77',
            'password_new': 'ThePassword1234',
            'password_confirm': 'TheWrongPassword'
        }
        form = ChangePasswordForm(user.user, data=form_data)
        self.assertFalse(form.is_valid())

        # 2. If passwords are too shorts
        form_data = {
            'password_old': 'hostel77',
            'password_new': 'pass',
            'password_confirm': 'pass'
        }
        form = ChangePasswordForm(user.user, data=form_data)
        self.assertFalse(form.is_valid())

        # 3. If passwords are equal to username
        form_data = {
            'password_old': 'hostel77',
            'password_new': user.user.username,
            'password_confirm': user.user.username
        }
        form = ChangePasswordForm(user.user, data=form_data)
        self.assertFalse(form.is_valid())
        
        # 4. If old password is wrong
        form_data = {
            'password_old': 'WrongPassword',
            'password_new': 'ThePassword1234',
            'password_confirm': 'ThePassword1234'
        }
        form = ChangePasswordForm(user.user, data=form_data)
        self.assertFalse(form.is_valid())
        
        # 5. If everything is OK
        form_data = {
            'password_old': 'hostel77',
            'password_new': 'ThePassword1234',
            'password_confirm': 'ThePassword1234'
        }
        form = ChangePasswordForm(user.user, data=form_data)
        self.assertTrue(form.is_valid())
Esempio n. 2
0
 def test_valid_change_password_form(self):
     data = {
         "password_old": self.oldpassword,
         "password_new": self.newpassword,
         "password_confirm": self.newpassword,
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertTrue(form.is_valid())
Esempio n. 3
0
 def test_too_long_change_password_form(self):
     data = {
         'password_old': self.old_password,
         'password_new': stringof77chars,
         'password_confirm': stringof77chars
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 4
0
 def test_not_matching_change_password_form(self):
     data = {
         'password_old': self.old_password,
         'password_new': self.new_password,
         'password_confirm': 'Wronnnng'
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 5
0
 def test_valid_change_password_form(self):
     data = {
         'password_old': self.old_password,
         'password_new': self.new_password,
         'password_confirm': self.new_password
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertTrue(form.is_valid())
Esempio n. 6
0
 def test_match_pseudo_change_password_form(self):
     self.user1.user.username = "******"
     data = {
         "password_old": self.oldpassword,
         "password_new": self.user1.user.username,
         "password_confirm": self.user1.user.username,
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 7
0
 def test_match_username_change_password_form(self):
     self.user1.user.username = '******'
     data = {
         'password_old': self.old_password,
         'password_new': self.user1.user.username,
         'password_confirm': self.user1.user.username
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 8
0
 def test_too_short_change_password_form(self):
     too_short = 'short'
     data = {
         'password_old': self.old_password,
         'password_new': too_short,
         'password_confirm': too_short
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 9
0
 def test_match_username_change_password_form(self):
     self.user1.user.username = '******'
     data = {
         'password_old': self.old_password,
         'password_new': self.user1.user.username,
         'password_confirm': self.user1.user.username
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 10
0
 def test_too_short_change_password_form(self):
     too_short = 'short'
     data = {
         'password_old': self.old_password,
         'password_new': too_short,
         'password_confirm': too_short
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 11
0
 def test_match_username_change_password_form(self):
     self.user1.user.username = "******"
     data = {
         "password_old": self.old_password,
         "password_new": self.user1.user.username,
         "password_confirm": self.user1.user.username,
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 12
0
 def test_too_short_change_password_form(self):
     too_short = "short"
     data = {
         "password_old": self.old_password,
         "password_new": too_short,
         "password_confirm": too_short
     }
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 13
0
 def test_too_short_change_password_form(self):
     tooshort = "short"
     data = {"password_old": self.oldpassword, "password_new": tooshort, "password_confirm": tooshort}
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 14
0
 def test_not_matching_change_password_form(self):
     data = {"password_old": self.oldpassword, "password_new": self.newpassword, "password_confirm": "Wronnnng"}
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())
Esempio n. 15
0
 def test_not_matching_change_password_form(self):
     data = {"password_old": self.old_password, "password_new": self.new_password, "password_confirm": "Wronnnng"}
     form = ChangePasswordForm(data=data, user=self.user1.user)
     self.assertFalse(form.is_valid())