Exemple #1
0
 def test_success(self):
     # The success case
     data = {
         'username': '******',
         'password': '******',
         }
     form = AuthenticationForm(None, data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.non_field_errors(), [])
Exemple #2
0
 def test_success(self):
     # The success case
     data = {
         'username': '******',
         'password': '******',
     }
     form = AuthenticationForm(None, data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.non_field_errors(), [])
Exemple #3
0
 def test_inactive_user(self):
     # The user is inactive.
     data = {
         'username': '******',
         'password': '******',
     }
     form = AuthenticationForm(None, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.non_field_errors(),
                      [force_unicode(form.error_messages['inactive'])])
Exemple #4
0
    def test_success(self, mocked_authenticate):
        user = mock.MagicMock()
        mocked_authenticate.return_value = user

        form = AuthenticationForm(data=self.data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.non_field_errors(), [])
        self.assertTrue(form.get_user(), user)

        mocked_authenticate.assert_called_with(**self.data)
Exemple #5
0
 def test_inactive_user(self):
     # The user is inactive.
     data = {
         'username': '******',
         'password': '******',
         }
     form = AuthenticationForm(None, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.non_field_errors(),
                      [force_unicode(form.error_messages['inactive'])])
Exemple #6
0
    def test_invalid_username(self):
        # The user submits an invalid username.

        data = {
            'username': '******',
            'password': '******',
        }
        form = AuthenticationForm(None, data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.non_field_errors(),
                         [force_unicode(form.error_messages['invalid_login'])])
Exemple #7
0
    def test_invalid_username(self):
        # The user submits an invalid username.

        data = {
            'username': '******',
            'password': '******',
            }
        form = AuthenticationForm(None, data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.non_field_errors(),
                         [force_unicode(form.error_messages['invalid_login'])])
Exemple #8
0
 def test_inactive_user_i18n(self):
     with self.settings(USE_I18N=True):
         with translation.override('pt-br', deactivate=True):
             # The user is inactive.
             data = {
                 'username': '******',
                 'password': '******',
                 }
             form = AuthenticationForm(None, data)
             self.assertFalse(form.is_valid())
             self.assertEqual(form.non_field_errors(),
                              [force_unicode(form.error_messages['inactive'])])
Exemple #9
0
 def test_inactive_user_i18n(self):
     with self.settings(USE_I18N=True):
         with translation.override('pt-br', deactivate=True):
             # The user is inactive.
             data = {
                 'username': '******',
                 'password': '******',
             }
             form = AuthenticationForm(None, data)
             self.assertFalse(form.is_valid())
             self.assertEqual(
                 form.non_field_errors(),
                 [force_unicode(form.error_messages['inactive'])])
Exemple #10
0
    def test_invalid_code(self, mocked_authenticate):
        """
        Invalid code supplied.
        """
        mocked_authenticate.return_value = None

        form = AuthenticationForm(data=self.data)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.non_field_errors(),
            [force_text(form.error_messages['invalid_login'])]
        )

        mocked_authenticate.assert_called_with(**self.data)