class User(Document): class Options(object): roles_to_propagate = not_(PARTIAL_RESPONSE_ROLE) with Scope(DB_ROLE) as db: db._id = StringField(required=True) db.version = StringField(required=True) with Scope(lambda r: r.startswith(RESPONSE_ROLE) or r == REQUEST_ROLE) as response: response.id = StringField(required=when_not(PARTIAL_RESPONSE_ROLE)) with Scope(not_(REQUEST_ROLE)) as not_request: not_request.messages = ArrayField(DocumentField(Message), required=when_not(PARTIAL_RESPONSE_ROLE))
def test_scope(): scope = Scope(DB_ROLE) f = StringField() scope.login = f assert scope.login == f assert scope.__fields__ == { 'login': f, } with pytest.raises(AttributeError): scope.gsomgsom
class Message(Document): with Scope(DB_ROLE) as db: db.uuid = StringField(required=True) created_at = IntField( required=when_not(PARTIAL_RESPONSE_ROLE, REQUEST_ROLE)) text = StringField(required=when_not(PARTIAL_RESPONSE_ROLE)) field_that_is_never_present = Var( {'NEVER': StringField(required=True)})
class X(Document): with Scope('role_1') as s_1: s_1.name = StringField() with Scope('role_2') as s_2: s_2.name = StringField()
class Test(Document): class Options(object): definition_id = 'test' with Scope('test') as test: test.field = DocumentField(RECURSIVE_REFERENCE_CONSTANT)
class Message(Document): with Scope(DB_ROLE) as db: db.uuid = StringField(required=True) created_at = IntField( required=when_not(PARTIAL_RESPONSE_ROLE, REQUEST_ROLE)) text = StringField(required=when_not(PARTIAL_RESPONSE_ROLE))