Commits

Sergey Maranchuk committed 8bd44dc

added tests for login view

  • Participants
  • Parent commits 5fa3867

Comments (0)

Files changed (3)

openauth/tests.py

 
 
 class RegistrationTest(unittest.TestCase):
-    
+
     def setUp(self):
         openauth.settings.REGISTRATION_ALLOWED = True
+        openauth.settings.ACTIVATION_REQUIRED = True
         self.client = Client()
         self.registration_url = reverse('openauth-registration')
+        self.active_user = User.objects.create_user('ivan', 'ivan@example.com', password='test')
+        self.inactive_user = User.objects.create_user('vova', 'vova@example.com', password='test')
+        self.inactive_user.is_active = False
+        self.inactive_user.save()
+
+    def tearDown(self):
+        self.active_user.delete()
+        self.inactive_user.delete()
 
     def test_registration(self):
         response = self.client.post(self.registration_url, {'username': 'petya', 'email': 'admin@example.com', 'password': 'test', 'password_dup': 'test'}) 
         response = self.client.post(self.registration_url, {'username': 'petya', 'email': 'admin@example.com', 'password': 'test', 'password_dup': 'test'}) 
         self.failUnlessRaises(User.DoesNotExist, User.objects.get, username='petya')
 
+    def test_login(self):
+        #active user login
+        response = self.client.login(username=self.active_user.username, password='test')
+        self.assertTrue(response)
 
+        #active user, incorrect password
+        response = self.client.login(username=self.active_user.username, password='INCORRECT')
+        self.assertFalse(response)
+
+        #inactive user, activation enabled
+        response = self.client.login(username=self.inactive_user.username, password='test')
+        self.assertFalse(response)
+
+        #inactive user, activation disabled
+        openauth.settings.ACTIVATION_REQUIRED = False
+        response = self.client.login(username=self.inactive_user.username, password='test')
+        self.assertTrue(response)

openauth/utils.py

             if openauth.settings.ACTIVATION_REQUIRED and not request.user.is_active:
                 return message(request, _('You account is not activated! Check your email please.'), 'notice', '/')
         else:
-            next_data = { 'next':request.path }
+            next_data = {'next': request.path}
             next = reverse('openauth-login')
             joiner = ('?' in next) and '&' or '?'
             next += joiner + unicode_urlencode(next_data) 

openauth/views.py

 
 @render_to('openauth/login.html')
 def login(request):
-    #TODO correct next url redirect
+
     if request.user.is_authenticated():
         return message(request, _('You are already authenticated'), 'notice', '/')
     if request.POST: