import unittest from mock import Mock from cellardoor.authorization import * from cellardoor.model import Model, Text, Link from cellardoor.storage import Storage model = Model(storage=Storage()) class Foo(model.Entity): bar = Link('Bar') baz = Text() class Bar(model.Entity): pass model.freeze() class TestAuthorization(unittest.TestCase): def test_auth_expr_abstract(self): """A base auth expression can't be called""" expr = AuthorizationExpression() with self.assertRaises(NotImplementedError): expr({})
from cellardoor import errors from cellardoor.authorization import ObjectProxy identity = ObjectProxy('identity') item = ObjectProxy('item') class CopyingMock(Mock): def __call__(self, *args, **kwargs): args = deepcopy(args) kwargs = deepcopy(kwargs) return super(CopyingMock, self).__call__(*args, **kwargs) storage = Storage() model = Model(storage=storage) api = API(model) class Foo(model.Entity): stuff = Text(required=True) optional_stuff = Text() bars = InverseLink('Bar', 'foo') bazes = ListOf(Link('Baz')) embedded_bazes = ListOf(Link('Baz', embeddable=True)) embedded_foos = ListOf( Link('Foo', embeddable=True, embed_by_default=False, embedded_fields=('stuff', ))) secret = Text(hidden=True)
import unittest import json import msgpack from mock import Mock import urllib from flask import Flask from cellardoor import errors from cellardoor.api import API from cellardoor.wsgi.flask_integration import create_blueprint from cellardoor.model import Model, Entity, Text, Link, ListOf from cellardoor.storage import Storage from cellardoor.api.interface import ALL, LIST, GET, CREATE model = Model(storage=Storage()) api = API(model) class Foo(model.Entity): name = Text(required=True) bar = Link('Bar') bazes = ListOf(Link('Baz')) class Bar(model.Entity): pass class Baz(model.Entity): pass
import unittest from mock import Mock from cellardoor.authorization import * from cellardoor.model import Model, Text, Link from cellardoor.storage import Storage model = Model(storage=Storage()) class Foo(model.Entity): bar = Link('Bar') baz = Text() class Bar(model.Entity): pass model.freeze() class TestAuthorization(unittest.TestCase): def test_auth_expr_abstract(self): """A base auth expression can't be called""" expr = AuthenticationExpression() with self.assertRaises(NotImplementedError): expr({}) def test_auth_expr_and_fail(self): """An auth expression and'd with an expression of another type raises an exception"""