Beispiel #1
0
class AuthenticationTest(TestCase):
    fixtures = ['initial_data.json']

    def setUp(self):
        self.dev_middleware = DevAuthenticationMiddleware()

    def test_dev_middleware_login(self):
        """
        Test development middleware logs on development user
        Precondition: anonymous
        Postcondition: logged in as development
        """
        request = HttpRequest()
        request.user = AnonymousUser()
        request.session = SessionStore()

        self.dev_middleware.process_request(request)

        self.assertTrue(str(request.user) is not 'AnonymousUser')

    def test_user_profile_create(self):
        """
        Test that user profile is created on user creation
        Precondition: new user created
        Postcondition: user profile created
        """
        user = User(username='******', password='******')
        user.save()
        try:
            self.assertTrue(user.get_profile())
        except:
            self.fail("DoesNotExist: user profile was not created on user creation")
Beispiel #2
0
    def test_session_has_ctnr_dev(self):
        """Test session ctnr set on log in"""
        self.setup_request()
        self.request.user = AnonymousUser()

        dev_middleware = DevAuthenticationMiddleware()
        dev_middleware.process_request(self.request)

        self.assertIn('ctnr', self.request.session)
Beispiel #3
0
    def test_session_has_ctnr_dev(self):
        """Test session ctnr set on log in"""
        self.setup_request()
        self.request.user = AnonymousUser()

        dev_middleware = DevAuthenticationMiddleware()
        dev_middleware.process_request(self.request)

        self.assertIn('ctnr', self.request.session)
Beispiel #4
0
    def test_session_has_ctnr_dev(self):
        """
        Test middleware sets session ctnr on log in
        Precondition: no session container
        Postcondition: session container
        """
        request = HttpRequest()
        request.user = AnonymousUser()
        request.session = SessionStore()

        dev_middleware = DevAuthenticationMiddleware()
        dev_middleware.process_request(request)

        self.assertTrue('ctnr' in request.session)
Beispiel #5
0
 def setUp(self):
     self.setup_request()
     self.dev_middleware = DevAuthenticationMiddleware()
Beispiel #6
0
class AuthenticationTest(TestCase):
    fixtures = ['core/users']

    def setUp(self):
        self.setup_request()
        self.dev_middleware = DevAuthenticationMiddleware()

    def test_middleware_login_dev(self):
        """
        Test development middleware logs on development user
        """
        self.setup_request()
        self.request.user = AnonymousUser()

        self.dev_middleware.process_request(self.request)

        self.assertTrue(str(self.request.user) is not 'AnonymousUser')

    def test_user_profile_create(self):
        """
        Test that user profile is created on user creation
        """
        user = User(username='******', password='******')
        user.save()
        try:
            self.assertTrue(user.get_profile())
        except:
            self.fail("DoesNotExist: user profile was not created on user creation")

    def test_session_has_ctnr_dev(self):
        """
        Test session ctnr set on log in
        """
        self.setup_request()
        self.request.user = AnonymousUser()

        dev_middleware = DevAuthenticationMiddleware()
        dev_middleware.process_request(self.request)

        self.assertTrue('ctnr' in self.request.session)

    def test_become_user(self):
        """
        Tests the functionality to be able to become and unbecome another user if superuser
        """
        self.setup_request()
        request = login_session(self.request, 'development')

        user = User.objects.get_or_create(username='******')[0]
        user.save()

        become_user(self.request, 'development2')
        self.assertTrue(self.request.user.username == 'development2')
        become_user(self.request, 'development')
        self.assertTrue(self.request.user.username == 'development')

        unbecome_user(self.request)
        self.assertTrue(self.request.user.username == 'development2')
        unbecome_user(self.request)
        self.assertTrue(self.request.user.username == 'development')
        unbecome_user(self.request)
        self.assertTrue(self.request.user.username == 'development')

    def setup_request(self):
        """
        Utility function for flushing and setting up request object for testing
        """
        self.request = HttpRequest()
        self.request.user = AnonymousUser()
        self.request.session = SessionStore()
Beispiel #7
0
 def setUp(self):
     self.setup_request()
     self.dev_middleware = DevAuthenticationMiddleware()
Beispiel #8
0
class AuthenticationTest(TestCase):
    fixtures = ['core/users']

    def setUp(self):
        self.setup_request()
        self.dev_middleware = DevAuthenticationMiddleware()

    def test_middleware_login_dev(self):
        """
        Test development middleware logs on development user
        """
        self.setup_request()
        self.request.user = AnonymousUser()

        self.dev_middleware.process_request(self.request)

        self.assertTrue(str(self.request.user) is not 'AnonymousUser')

    def test_user_profile_create(self):
        """
        Test that user profile is created on user creation
        """
        user = User(username='******')
        user.save()
        try:
            self.assertTrue(user.get_profile())
        except:
            self.fail("DoesNotExist: user profile was not created on "
                      "user creation")

    def test_session_has_ctnr_dev(self):
        """
        Test session ctnr set on log in
        """
        self.setup_request()
        self.request.user = AnonymousUser()

        dev_middleware = DevAuthenticationMiddleware()
        dev_middleware.process_request(self.request)

        self.assertTrue('ctnr' in self.request.session)

    def test_become_user(self):
        """
        Tests the functionality to be able to become and unbecome another
        user if superuser
        """
        self.setup_request()
        self.request = login_session(self.request, 'development')

        user = User.objects.create(username='******')
        user.save()

        become_user(self.request, 'development2')
        self.assertTrue(self.request.user.username == 'development2')
        become_user(self.request, 'development')
        self.assertTrue(self.request.user.username == 'development')

        unbecome_user(self.request)
        self.assertTrue(self.request.user.username == 'development2')
        unbecome_user(self.request)
        self.assertTrue(self.request.user.username == 'development')
        unbecome_user(self.request)
        self.assertTrue(self.request.user.username == 'development')

    def setup_request(self):
        """
        Utility function for flushing and setting up request object for testing
        """
        self.request = HttpRequest()
        self.request.user = AnonymousUser()
        self.request.session = SessionStore()
Beispiel #9
0
 def setUp(self):
     self.dev_middleware = DevAuthenticationMiddleware()