示例#1
0
    def test_in_operator(self):
        """ test operator in """
        query_string = '{"filter" : {"name" : {"in" : ["Jhon", "Peter", "Iron"] } } }'
        assert (elastic_query(User, query_string, session).count() == 2)

        query_string = '{"filter" : {"name" : {"in" :["Jhon", "Peter", "Iron"]}, "lastname" : "Galt" } }'
        assert (elastic_query(User, query_string, session).count() == 1)
示例#2
0
    def test_in_operator(self):
        """ test operator in """
        query_string = '{"filter" : {"name" : {"in" : ["Jhon", "Peter", "Iron"] } } }'
        assert(elastic_query(User, query_string, session).count() == 2)

        query_string = '{"filter" : {"name" : {"in" :["Jhon", "Peter", "Iron"]}, "lastname" : "Galt" } }'
        assert(elastic_query(User, query_string, session).count() == 1)
示例#3
0
    def test_search_for_levels(self):
        """ test search for levels """
        query_string = \
            '{"filter" : {"or" : { "city.name" : "New York", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
        results = elastic_query(User, query_string, session).all()
        assert(results[0].name == 'Iron')

        query_string = '{"filter" : { "city.name" : "New York" } }'
        results = elastic_query(User, query_string, session).all()
        assert(results[0].name == 'Steve')

        query_string = '{"filter" : { "city.name" : {"like" : "%New%"} } }'
        results = elastic_query(User, query_string, session).all()
        assert(results[0].name == 'Steve')
示例#4
0
    def test_search_for_levels(self):
        """ test search for levels """
        query_string = \
            '{"filter" : {"or" : { "city.name" : "New York", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
        results = elastic_query(User, query_string, session).all()
        assert (results[0].name == 'Iron')

        query_string = '{"filter" : { "city.name" : "New York" } }'
        results = elastic_query(User, query_string, session).all()
        assert (results[0].name == 'Steve')

        query_string = '{"filter" : { "city.name" : {"like" : "%New%"} } }'
        results = elastic_query(User, query_string, session).all()
        assert (results[0].name == 'Steve')
示例#5
0
    def test_flask(self):
        app = Flask(__name__)
        db = SQLAlchemy(app)
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'

        class Cities(db.Model):
            __tablename__ = 'users'

            id = Column(Integer, primary_key=True)
            name = Column(String)
            population = Column(Integer)

            def __init__(self, name, population):
                self.name = name
                self.population = population
                
        app.config['TESTING'] = True
        app = app.test_client()
        db.create_all()

        city = Cities("Cordoba", 1000000)
        db.session.add(city)
        city = Cities("Rafaela", 99000)
        db.session.add(city)
        db.session.commit()

        query_string = '{ "sort": { "population" : "desc" } }'
        results = elastic_query(Cities, query_string)
        assert(results[0].name == 'Cordoba')
示例#6
0
    def test_flask(self):
        app = Flask(__name__)
        db = SQLAlchemy(app)
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'

        class Cities(db.Model):
            __tablename__ = 'users'

            id = Column(Integer, primary_key=True)
            name = Column(String)
            population = Column(Integer)

            def __init__(self, name, population):
                self.name = name
                self.population = population

        app.config['TESTING'] = True
        app = app.test_client()
        db.create_all()

        city = Cities("Cordoba", 1000000)
        db.session.add(city)
        city = Cities("Rafaela", 99000)
        db.session.add(city)
        db.session.commit()

        query_string = '{ "sort": { "population" : "desc" } }'
        results = elastic_query(Cities, query_string)
        assert (results[0].name == 'Cordoba')
示例#7
0
 def test_allow_fields_option(self):
     """ test allow_fields option """
     query_string = '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
     enabled_fields = ['name']
     results = elastic_query(User,
                             query_string,
                             session,
                             enabled_fields=enabled_fields).all()
     assert (results[0].name == 'Jhon')
示例#8
0
 def test_sorting(self):
     """ test operator levels """
     query_string = \
         '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
     results = elastic_query(User, query_string, session).all()
     assert(results[0].name == 'Iron')
示例#9
0
 def test_or_and_operator(self):
     """ test or and operator """
     query_string = \
         '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Galt" }, "and" : { "uid" : "19571957" } } }'
     assert(elastic_query(User, query_string, session).count() == 1)
示例#10
0
 def test_or_operator(self):
     """ test or operator """
     query_string = \
         '{"filter" : {"or" : { "name" : "Jobs", "lastname" : "Man", "uid" : "19571957" } } }'
     assert(elastic_query(User, query_string, session).count() == 2)
示例#11
0
 def test_and_operator(self):
     """ test and operator """
     query_string = \
         '{"filter" : {"and" : {"name" : {"like" : "%Jho%"}, "lastname" : "Galt", "uid" : {"like" : "%1957%"} } } }'
     assert(elastic_query(User, query_string, session).count() == 1)
示例#12
0
 def test_simple_query(self):
     """ test simple query """
     query_string = '{"filter" : {"uid" : {"like" : "%1957%"} } }'
     assert(elastic_query(User, query_string, session).count() == 2)
     query_string = '{"filter" : {"name" : {"like" : "%Jho%"}, "lastname" : "Galt" } }'
     assert(elastic_query(User, query_string, session).count() == 1)
示例#13
0
 def test_simple_query(self):
     """ test simple query """
     query_string = '{"filter" : {"uid" : {"like" : "%1957%"} } }'
     assert (elastic_query(User, query_string, session).count() == 2)
     query_string = '{"filter" : {"name" : {"like" : "%Jho%"}, "lastname" : "Galt" } }'
     assert (elastic_query(User, query_string, session).count() == 1)
示例#14
0
 def test_allow_fields_option(self):
     """ test allow_fields option """
     query_string = '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
     enabled_fields = ['name']
     results = elastic_query(User, query_string, session, enabled_fields=enabled_fields).all()
     assert(results[0].name == 'Jhon')
示例#15
0
 def test_and_operator(self):
     """ test and operator """
     query_string = \
         '{"filter" : {"and" : {"name" : {"like" : "%Jho%"}, "lastname" : "Galt", "uid" : {"like" : "%1957%"} } } }'
     assert (elastic_query(User, query_string, session).count() == 1)
示例#16
0
 def test_sorting(self):
     """ test operator levels """
     query_string = \
         '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
     results = elastic_query(User, query_string, session).all()
     assert (results[0].name == 'Iron')
示例#17
0
 def test_or_and_operator(self):
     """ test or and operator """
     query_string = \
         '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Galt" }, "and" : { "uid" : "19571957" } } }'
     assert (elastic_query(User, query_string, session).count() == 1)
示例#18
0
 def test_or_operator(self):
     """ test or operator """
     query_string = \
         '{"filter" : {"or" : { "name" : "Jobs", "lastname" : "Man", "uid" : "19571957" } } }'
     assert (elastic_query(User, query_string, session).count() == 2)