예제 #1
0
파일: tests.py 프로젝트: Aer-o/zds-site
    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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())
예제 #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())