def test_user_backend_required(self):

        condition = authaction.conditions.backend_required('testing')
        test_user = UserFactory.create()
        test_user.backend = 'testing'

        self.assertTrue(
            condition(test_user, {})
        )
    def test_user_backend_required(self):

        condition = authaction.conditions.backend_required('testing')
        test_user = UserFactory.create()
        test_user.backend = 'two-factor'

        with self.assertRaises(authaction.exceptions.ConditionFailed)\
             as assertion:

            condition(test_user, {})
    def test_is_anonymous_fails_for_authed_user(self):

        with self.assertRaises(authaction.exceptions.ConditionFailed)\
             as assertion:

            authaction.conditions.is_anonymous(UserFactory.create(), {})

        self.assertEqual(
            assertion.exception.action_hint,
            authaction_constants.LOGOUT,
        )
Esempio n. 4
0
    def test_auth_action_required_decorator(self):

        @authaction.guard.auth_action_required('testing')
        def test_psuedo_view(request):
            return "Called and returned."

        request = HttpRequest()

        # simulate auth and session middleware
        request.user = UserFactory.create()
        request.session = {}

        self.assertEqual(
            test_psuedo_view(request),
            'Called and returned.',
        )
    def test_logged_in_passes_for_authd_user(self):

        self.assertTrue(
            authaction.conditions.logged_in(UserFactory.create(), {})
        )