def test_login_form_invalid(self): """ When provided with incorrect username or password the form should not validate. """ form = LoginForm(data={'username': '******', 'password': '******'}) self.assertFalse(form.is_valid()) form = LoginForm(data={'username': '******', 'password': '******'}) self.assertFalse(form.is_valid())
def test_login_form(self): """ When provided with correct data, the form should validate. """ form = LoginForm(data={'username': '******', 'password': '******'}) self.assertTrue(form.is_valid())
def test_login_form_exception(self): """ If an authentication backend raises an exception, the exception should be handled and the form should be invalid. """ form = LoginForm(data={'username': '******', 'password': '******'}) self.assertFalse(form.is_valid())
def test_login_form_empty(self): """ When no username or password is provided, the form should not validate. """ form = LoginForm(data={'username': '', 'password': ''}) self.assertFalse(form.is_valid())
def test_login_form_inactive(self): """ When provided with an inactive user, the form should be invalid. """ InactiveUserFactory() form = LoginForm(data={'username': '******', 'password': '******'}) self.assertFalse(form.is_valid())
def test_login_case_insensitive(self): """ If a case-insensitive authentication backend is in use, authentication should proceed as expected when the case differs. """ UserFactory(first_name='John', last_name='Phillips') form = LoginForm(data={'username': '******', 'password': '******'}) self.assertTrue(form.is_valid())
def test_login_form_username(self): """ When a mixed-case username is provided, it should be converted to lowercase. """ form = LoginForm(data={'username': '******', 'password': '******'}) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['username'], 'ellen')
def test_login_form_inactive(self): """ When provided with an inactive user, the form should not validate. """ self.user.is_active = False self.user.save() form = LoginForm(data={'username': '******', 'password': '******'}) self.assertFalse(form.is_valid())