def test_clean_password2_valid(self): self.assertTrue(self.user.check_password('test1234')) form = SettingsForm(data={ 'password1': 'test2345', 'password2': 'test2345' }, instance=self.user) self.assertTrue(form.is_valid()) self.assertTrue(self.user.check_password('test2345'))
def test_clean_email_change_user(self): form = SettingsForm(data={ 'email': '*****@*****.**'}, instance=self.user) self.assertTrue(form.is_valid()) self.assertEqual(len(Action.objects.all()), 1) self.assertEqual(Action.objects.all()[0].data, '*****@*****.**') self.assertEqual(Action.objects.all()[0].user, self.user) self.assertEqual(Action.objects.all()[0].atype, ACTION_TYPES.change_email)
def test_clean_password2_one_empty(self): form = SettingsForm(data={ 'password1': 'test2345', 'password2': '' }, instance=self.user) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['password2'], [PASSWORD_MISMATCH_ERROR]) self.assertTrue(self.user.check_password('test1234'))
def test_clean_email_change_user(self): form = SettingsForm(data={'email': '*****@*****.**'}, instance=self.user) self.assertTrue(form.is_valid()) self.assertEqual(len(Action.objects.all()), 1) self.assertEqual(Action.objects.all()[0].data, '*****@*****.**') self.assertEqual(Action.objects.all()[0].user, self.user) self.assertEqual(Action.objects.all()[0].atype, ACTION_TYPES.change_email)
def test_clean_password2_empty(self): form = SettingsForm(data={}, instance=self.user) self.assertTrue(form.is_valid()) self.assertTrue(self.user.check_password('test1234'))
def test_clean_email_duplicate_address(self): User.objects.create_user(username='******', email='*****@*****.**') form = SettingsForm(data={ 'email': '*****@*****.**'}, instance=self.user) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['email'], [DUPLICATE_EMAIL_ERROR])
def test_clean_email_no_change(self): form = SettingsForm(data={ 'email': '*****@*****.**'}, instance=self.user) self.assertTrue(form.is_valid())
def test_clean_email_duplicate_address(self): User.objects.create_user(username='******', email='*****@*****.**') form = SettingsForm(data={'email': '*****@*****.**'}, instance=self.user) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['email'], [DUPLICATE_EMAIL_ERROR])
def test_clean_email_no_change(self): form = SettingsForm(data={'email': '*****@*****.**'}, instance=self.user) self.assertTrue(form.is_valid())