def test_success(self, mocked_authenticate): """ Successful authentication. """ mocked_authenticate.return_value = mock.MagicMock() form = AuthenticationForm(data=self.credentials) self.assertTrue(form.is_valid()) self.assertEqual(form.non_field_errors(), []) mocked_authenticate.assert_called_with(**self.credentials)
def test_invalid_credentials(self, mocked_authenticate): """ The User submits invalid credentials """ mocked_authenticate.return_value = None data = { 'username': '******', 'password': '******', } form = AuthenticationForm(data=data) self.assertFalse(form.is_valid()) self.assertEqual( form.non_field_errors(), [force_text(form.error_messages['invalid_login'])] ) mocked_authenticate.assert_called_with(**data)