示例#1
0
    def test_administrator_admin(self):
        #Arrange
        f = Mock()
        this = Mock()
        this.users.get_current_user.return_value = True
        this.users.is_current_user_admin.return_value = True

        #Act
        decorator = administrator(f)
        result = decorator(this)

        #Assert
        assert this.users.get_current_user.called
        assert f.called
示例#2
0
    def test_administrator_no_user(self):
        #Arrange
        f = Mock()
        this = Mock()
        this.users.get_current_user.return_value = None
        this.users.create_login_url.return_value = '/login'

        #Act
        decorator = administrator(f)
        result = decorator(this)

        #Assert
        assert not f.called
        assert this.users.get_current_user.called
        assert type(result) == Redirect
示例#3
0
    def test_administrator_user(self):
        #Arrange
        f = Mock()
        this = Mock()
        this.users.get_current_user.return_value = True
        this.users.is_current_user_admin.return_value = False

        #Act
        decorator = administrator(f)
        result = decorator(this)

        #Assert
        assert this.users.get_current_user.called
        assert type(result) == Error
        assert result.code == 403