Beispiel #1
0
 def test_authenticated_user_class(self):
     # We should find that the class of request.user is that of
     # LAZSIGNUP_CUSTOM_USER
     request = HttpRequest()
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     lazy_view(request)
     self.assertEqual(get_user_model(), type(request.user))
Beispiel #2
0
 def test_backend_get_custom_user_class(self):
     # The get_user method on the backend should also return instances of
     # the custom user class.
     lazy_view(self.request)
     backend = LazySignupBackend()
     user_class = LazyUser.get_user_class()
     pk = user_class.objects.all()[0].pk
     self.assertEqual(user_class, type(backend.get_user(pk)))
Beispiel #3
0
 def test_backend_get_custom_user_class(self):
     # The get_user method on the backend should also return instances of
     # the custom user class.
     lazy_view(self.request)
     backend = LazySignupBackend()
     user_class = LazyUser.get_user_class()
     pk = user_class.model.objects.all()[0].pk
     self.assertEqual(user_class, type(backend.get_user(pk)))
Beispiel #4
0
 def test_authenticated_user_class(self):
     # We should find that the class of request.user is that of
     # LAZSIGNUP_CUSTOM_USER
     request = HttpRequest()
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     lazy_view(request)
     self.assertEqual(get_user_model(), type(request.user))
Beispiel #5
0
 def test_backend_get_user_annotates(self):
     # Check that the lazysignup backend annotates the user object
     # with the backend, mirroring what Django's does
     lazy_view(self.request)
     backend = LazySignupBackend()
     pk = get_user_model().objects.all()[0].pk
     self.assertEqual('lazysignup.backends.LazySignupBackend',
                      backend.get_user(pk).backend)
Beispiel #6
0
 def test_backend_get_user_annotates(self):
     # Check that the lazysignup backend annotates the user object
     # with the backend, mirroring what Django's does
     lazy_view(self.request)
     backend = LazySignupBackend()
     pk = get_user_model().objects.all()[0].pk
     self.assertEqual(
         'lazysignup.backends.LazySignupBackend',
         backend.get_user(pk).backend
     )
Beispiel #7
0
    def test_session_name_conflict(self):
        # Test for issue #6. If a user object exists with the same name as
        # the sha-1 hash of the session id (well, the first
        # username.max_length characters thereof) then we should not see an
        # error when the user is created. This was actually fixed by changing
        # the mechanism to associate a lazy user with a session.

        # Calling get_user triggers a session key cycle the first time. Do it
        # now, so we can grab the final session key.
        get_user(self.request)
        key = self.request.session.session_key
        username = hashlib.sha1(key.encode('ascii')).hexdigest()[:30]
        get_user_model().objects.create_user(username, '')
        r = lazy_view(self.request)
        self.assertEqual(200, r.status_code)
Beispiel #8
0
    def test_session_name_conflict(self):
        # Test for issue #6. If a user object exists with the same name as
        # the sha-1 hash of the session id (well, the first
        # username.max_length characters thereof) then we should not see an
        # error when the user is created. This was actually fixed by changing
        # the mechanism to associate a lazy user with a session.

        # Calling get_user triggers a session key cycle the first time. Do it
        # now, so we can grab the final session key.
        get_user(self.request)
        key = self.request.session.session_key
        username = hashlib.sha1(key.encode('ascii')).hexdigest()[:30]
        get_user_model().objects.create_user(username, '')
        r = lazy_view(self.request)
        self.assertEqual(200, r.status_code)
Beispiel #9
0
 def test_bad_session_user_id(self):
     self.request.session[SESSION_KEY] = 1000
     self.request.session[BACKEND_SESSION_KEY] = \
         'lazysignup.backends.LazySignupBackend'
     lazy_view(self.request)
Beispiel #10
0
 def test_is_lazy_user_lazy(self):
     self.request.user = AnonymousUser()
     lazy_view(self.request)
     self.assertEqual(True, is_lazy_user(self.request.user))
Beispiel #11
0
 def test_bad_session_user_id(self):
     self.request.session[SESSION_KEY] = 1000
     self.request.session[BACKEND_SESSION_KEY] = \
         'lazysignup.backends.LazySignupBackend'
     lazy_view(self.request)
Beispiel #12
0
 def test_is_lazy_user_lazy(self):
     self.request.user = AnonymousUser()
     lazy_view(self.request)
     self.assertEqual(True, is_lazy_user(self.request.user))