def test_like(self, session): filter = {'name': {'like': 'b%'}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 2 filter = {'name': {'!like': 'b%'}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1
def test_in(self, session): filter = {'name': {'IN': ['foo', 'hoge']}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1 filter = {'name': {'!in': ['foo', 'hoge']}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 2 filter = {'name': {'in': 'foo'}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1
def test_filter(self, session): filter = { 'parent.name': 'me', } res = querybuilder(base_query(session), filter).all() assert len(res) == 2 assert set([r.name for r in res]) == {'daughter', 'son'} filter = { 'child.name': 'me', } res = querybuilder(base_query(session), filter).all() assert len(res) == 1 assert set([r.name for r in res]) == {'mother'}
def test_fk(self, session): filter = { 'addresses.email': { '==': '*****@*****.**' }, } res = querybuilder(session.query(User), filter).all() assert len(res) == 1
def query(query_order: dict = None): if query_order is None: return orm.Store.query.all() else: try: query = orm.Store.query.join(orm.Pet, isouter=True) return querybuilder(query, query_order).all() except (KeyError, ValueError, AttributeError) as ex: raise BadRequest(str(ex))
def test_boolean_op(self, session): filter = { 'name': ['OR', { '==': 'bar' }, { 'like': 'baz%' }], } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 2 filter = { 'name': ['and', { '==': 'bar' }, { 'like': 'ba%' }], } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1
def test_no_relationship(self, session): filter = { 'scores.score': { '==': 31 }, } res = querybuilder( session.query(User, Score).join(Score, User.id == Score.user_id), filter).all() assert len(res) == 1 filter = { 'scores.score': { '>=': 50 }, } res = querybuilder( session.query(User, Score).join(Score, User.id == Score.user_id), filter).all() assert len(res) == 0
def test_arithmetic(self, session): filter = {'age': {'==': 20}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1 assert res[0].name == 'bar' filter = {'age': {'>': 20}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1 filter = {'age': {'>=': 20}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 2 filter = {'age': {'<': 20}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1 filter = {'age': {'<=': 20}} res = querybuilder(session.query(Basic), filter).all() assert len(res) == 2
def test_equal(self, session): filter = { 'name': { '==': 'foo' }, } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1 filter = { 'name': { '!=': 'foo' }, } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 2 filter = { 'name': 'foo', } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1 filter = { 'name': 'foo', 'age': 20, } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 0 filter = { 'name': 'foo', 'age': 10.0, } res = querybuilder(session.query(Basic), filter).all() assert len(res) == 1
def test_union(self, session): filters = [ { 'name': { 'like': 'ba%' }, }, { 'name': { 'in': ['foo', 'baz'] }, }, ] res = querybuilder(session.query(Basic), filters).all() assert len(res) == 3 assert set([r.name for r in res]) == {'foo', 'bar', 'baz'}
def test_relation(self, session): filter = { # no filter } res = querybuilder(base_query(session), filter).all() assert len(res) == 5