class User(Model, metaclass=ModelMeta): global_namespace = True id = IdField(required=True) username = StringField(required=True, unique=True) email = StringField(required=False, unique=True) password = PasswordField(required=True) organization = RelationField(required=True, remote_class_name='Organization') created_at = DatetimeField(default=datetime.utcnow) role = StringField(required=True) active = BoolField(required=True) metadata = JSONField(required=False) auth = StringField() @property def namespace(self): """ Get namespace from organization. Returns: str: Namespace (from organization) """ return self.organization.namespace
class TestModel(Model, metaclass=ModelMeta): if global_ns: global_namespace = global_ns id = IdField(required=required, encrypted=encrypted, unique=unique) string = StringField(required=required, encrypted=encrypted, unique=unique) json = JSONField(required=required, encrypted=encrypted, unique=unique) password = PasswordField(required=required, encrypted=encrypted, unique=unique) relation = RelationField(required=required, encrypted=encrypted, unique=unique) datetime = DatetimeField(required=required, encrypted=encrypted, unique=unique) boolean = BoolField(required=required, encrypted=encrypted, unique=unique) _required = required _global_ns = global_ns _encrypted = encrypted if _global_ns: _namespace = None else: _namespace = namespace
class TestModel(Model, metaclass=ModelMeta): if global_ns: global_namespace = global_ns id = IdField(required=required) string = StringField(required=required) json = JSONField(required=required) secret = SecretField(required=required) relation = RelationField(required=required) datetime = DatetimeField(required=required) boolean = BoolField(required=required)
class User(Model, metaclass=ModelMeta): global_namespace = True id = IdField(required=True) username = StringField(required=True) email = StringField(required=False) password = SecretField(required=True) organization = RelationField(required=True) created_at = DatetimeField() active = BoolField(required=True) @property def namespace(self): """ Get namespace from organization. Returns: str: Namespace (from organization) """ return self.organization.namespace
def setup(self): self.boolean = False self.field = BoolField()
class TestBoolField: def setup(self): self.boolean = False self.field = BoolField() def test_serialization(self): req = 'false' self.field.set_value(self.boolean) assert self.field.serialize() == req def test_serialization_none(self): self.field.set_value(None) assert self.field.serialize() is None @pytest.mark.parametrize('serialized, req', [ ('false', False), ('true', True), ]) def test_deserialization(self, serialized, req): self.field.deserialize(serialized) assert self.field.value == req def test_dict_value_returns_boolean(self): self.field.set_value(self.boolean) assert self.field.dict_value() == self.boolean