def test_schema(self): class User(venom.Model): username = venom.Properties.String() email = venom.Properties.String() age = venom.Properties.Float() password = venom.Properties.Password(min=5) bio = venom.Properties.String(max=None) login = venom.Query(email == venom.QP, password == venom.QP) def assert_schema(model, prop_name, datastore, indexed_datastore, search): assert model._schema[prop_name].datastore == datastore assert model._schema[ prop_name].indexed_datastore == indexed_datastore assert model._schema[prop_name].search == search assert_schema(User, 'username', True, False, False) assert_schema(User, 'email', True, True, False) assert_schema(User, 'age', True, False, False) assert_schema(User, 'password', True, True, False) assert_schema(User, 'bio', True, False, False) User.bio_contains = venom.Query(User.bio.contains(venom.QP)) User._init_class() assert_schema(User, 'username', True, False, False) assert_schema(User, 'email', True, True, False) assert_schema(User, 'age', True, False, False) assert_schema(User, 'password', True, True, False) assert_schema(User, 'bio', True, False, True) User.bio_contains = venom.Query(User.bio.contains(venom.QP), User.email == 'foo') User._init_class() assert_schema(User, 'username', True, False, False) assert_schema(User, 'email', True, True, True) assert_schema(User, 'age', True, False, False) assert_schema(User, 'password', True, True, False) assert_schema(User, 'bio', True, False, True) User.bio_contains = venom.Query(User.age > 5, User.email != 'foo') User._init_class() assert_schema(User, 'username', True, False, False) assert_schema(User, 'email', True, True, True) assert_schema(User, 'age', True, False, True) assert_schema(User, 'password', True, True, False) assert_schema(User, 'bio', True, False, False)
def test_callable(self): class TestModel(venom.Model): pass foo = QueryTestProp() foo._connect(name='foo') bar = QueryTestProp() bar._connect(name='bar') query = venom.Query(foo == venom.QP, bar == venom.QP) query._connect(name='query', entity=TestModel()) assert query(123, 456) == [] query = venom.Query(foo < venom.QP, bar != venom.QP) query._connect(name='query', entity=TestModel()) assert query(123, bar=456) == []
class Test(venom.Model): auto_migrate_in_dev = False foo = venom.Properties.String() bar = venom.Properties.String() matches = venom.Query(foo == 'foo', bar == 'bar')
class User(venom.Model): username = venom.Properties.String() email = venom.Properties.String() age = venom.Properties.Float() password = venom.Properties.Password(min=5) bio = venom.Properties.String(max=None) login = venom.Query(email == venom.QP, password == venom.QP)
class User(venom.Model): password = venom.Properties.Password(min=3, max=100, required=True) username = venom.Properties.String(min=3, max=100, required=True, unique=True) email = venom.Properties.String(min=3, max=100, required=True, unique=True) created = venom.Properties.DateTime(set_on_creation=True) last_updated = venom.Properties.DateTime(set_on_update=True) last_login = venom.Properties.DateTime() by_username = venom.Query(username == venom.QP) by_email = venom.Query(email == venom.QP) login_by_username = venom.Query(by_username, password == venom.QP) login_by_email = venom.Query(by_email, password == venom.QP)
def test_uses_datastore(self): foo = QueryTestProp() foo._connect(name='foo') bar = QueryTestProp() bar._connect(name='bar') query = venom.Query(foo == 123, bar == 456) query._connect(name='query') assert query.uses_datastore() query = venom.Query(foo == 123, bar != 456) query._connect(name='query') assert query.uses_datastore() query = venom.Query(foo > 123, bar != 456) query._connect(name='query') assert not query.uses_datastore() query = venom.Query(foo > 123, foo != 456) query._connect(name='query') assert query.uses_datastore()
def test_query_inheritance(self): foo = QueryTestProp() foo._connect(name='foo') bar = QueryTestProp() bar._connect(name='bar') query = venom.Query(foo == 123, bar == 456) query._connect(name='query') assert query.to_search_query([]) == '(foo = 123 AND bar = 456)' assert query._name == 'query' assert query._model == None assert query._entity == None
class SessionToken(venom.Model): expiration_hours = 48 def __init__(self, *args, **kwargs): now = datetime.datetime.now() timedelta = datetime.timedelta(hours=self.expiration_hours) expiration = now + timedelta kwargs['expiration'] = expiration super(SessionToken, self).__init__(*args, **kwargs) token = venom.Properties.UUID(required=True) user = venom.Properties.Model(User, required=True) expiration = venom.Properties.DateTime(required=True) find_auth = venom.Query(token == venom.QP, expiration > venom.QP)
class Test(venom.Model): foo = TestProp() bar = TestProp() foo10 = venom.Query(foo == 10) foo34 = venom.Query(foo == 34)