Exemplo n.º 1
0
def test_authenticated_decorator_checks_for_user():
    clear_expectations()
    clear()

    class TestController(Controller):
        @authenticated
        def some_action(self):
            pass

    ctrl = TestController()

    fake_server = Fake('server')
    ctrl.server = fake_server
    ctrl.server.context = Fake('context')

    ctrl.server.expects('publish').with_args('on_before_user_authentication', arg.any_value())
    ctrl.server.next_call('publish').with_args('on_user_authentication_failed', arg.any_value())

    ctrl.some_action()
Exemplo n.º 2
0
def test_authenticated_decorator_executes_function_when_user_exists():
    clear_expectations()
    clear()

    class TestController(Controller):
        @authenticated
        def some_action(self):
            return "some_action_result"

    ctrl = TestController()

    fake_server = Fake('server')
    ctrl.server = fake_server
    ctrl.server.context = Fake('context')

    ctrl.server.expects('publish').with_args('on_before_user_authentication', arg.any_value())
    ctrl.server.next_call('publish').with_args('on_user_authentication_successful', arg.any_value())

    result = ctrl.some_action()

    assert result == "some_action_result"