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)
Exemple #11
0
def login(request, form_id, email, password, **kwargs):
    dajax = Dajax()
    clear_form_errors(dajax, form_id)
    
    form = AuthenticationForm(data={'email' : email, 'password' : password})
    
    if form.is_valid():
        auth_login(request, form.get_user())
        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()
            
        dajax.redirect(kwargs.get('next'))
    else:
        
        set_form_errors(dajax, form_id, form.errors)
        
    return dajax.json()
Exemple #12
0
def api_login(request):
    if request.method == "POST" :
        form = AuthenticationForm(data=request.POST)
    else:
        return api_error(request, '407')

    if form.is_valid():
        auth_login(request, form.get_user())
        info = {}
        email = request.user.username
        info['email'] = email
        info['feedback'] = settings.DEFAULT_FROM_EMAIL
        info['sessionid'] = request.session.session_key
        info['usage'] = seafserv_threaded_rpc.get_user_quota_usage(email)
        info['total'] = seafserv_threaded_rpc.get_user_quota(email)
        return HttpResponse(json.dumps([info]), status=200, content_type=json_content_type)
    else:
        return api_error(request, '408')
Exemple #13
0
def index(request):
    form = AuthenticationForm()
    return render(request, 'index.html', {'form': form})