Пример #1
0
    def test_zzzz_search_with_single_query(self):

        search = Search(self.Donkey, "people", self.session)
        session = self.session
        search.add_query('name < ? and not email.email like ?', values = ["popp02", "popi%"])

        people_class = self.Donkey.get_class(u"people")
        email_class = self.Donkey.get_class(u"email")

        assert set(search.search().all()).symmetric_difference(
               set(session.query(people_class).outerjoin(["_rel_email"]).\
                   filter(and_(people_class.name < u"popp02", or_(email_class.email == None, not_(email_class.email.like(u"popi%"))))).all())) == set()

        assert len(search.search()[0:15]) == 15
Пример #2
0
    def test_search_with_union(self):

        search = Search(self.Donkey, u"people", self.session)
        session = self.session

        search.add_query('name < popp005 and email.email like "popi%"')

        search.add_query('donkey.name in (poo, fine)')


        assert len(search.search().all()) == 6

        search.add_query('donkey_sponsership.amount > 248')

        assert len(search.search().all()) == 8
Пример #3
0
    def test_zz_search_with_limit(self):

        search = Search(self.Donkey, "people", self.session)

        search.add_query('email.email like "popi%"')
        search.add_query('people.name = "david"', exclude = "true")

        assert len(search.search()[0:2]) == 2
Пример #4
0
    def test_search_custom(self):

        search = Search(self.Donkey, "people", self.session, "id>0", extra_inner = ["email>email"])

        print str(search.search())


        assert str(search.search()) ==  """SELECT people.town AS people_town, people.name AS people_name, people.country AS people_country, people._core_id AS people__core_id, people._version AS people__version, people.gender_id AS people_gender_id, people._modified_by AS people__modified_by, people.postcode AS people_postcode, people._modified_date AS people__modified_date, people.over_18_id AS people_over_18_id, people.address_line_2 AS people_address_line_2, people.address_line_3 AS people_address_line_3, people.address_line_1 AS people_address_line_1, people.id AS people_id, email_1.active_email AS email_1_active_email, email_1._version AS email_1__version, email_1._modified_by AS email_1__modified_by, email_1._modified_date AS email_1__modified_date, email_1.people_id AS email_1_people_id, email_1.email AS email_1_email, email_1.id AS email_1_id
FROM people JOIN email AS email_2 ON people.id = email_2.people_id LEFT OUTER JOIN email AS email_1 ON people.id = email_1.people_id
WHERE people.id > ? AND people.id IS NOT NULL ORDER BY email_1.email"""


        search = Search(self.Donkey, "people", self.session, "id>0", extra_outer = ["gender>code", "over_18>code"])
        print search.search()
        assert str(search.search()) == """SELECT people.town AS people_town, people.name AS people_name, people.country AS people_country, people._core_id AS people__core_id, people._version AS people__version, people.gender_id AS people_gender_id, people._modified_by AS people__modified_by, people.postcode AS people_postcode, people._modified_date AS people__modified_date, people.over_18_id AS people_over_18_id, people.address_line_2 AS people_address_line_2, people.address_line_3 AS people_address_line_3, people.address_line_1 AS people_address_line_1, people.id AS people_id, email_1.active_email AS email_1_active_email, email_1._version AS email_1__version, email_1._modified_by AS email_1__modified_by, email_1._modified_date AS email_1__modified_date, email_1.people_id AS email_1_people_id, email_1.email AS email_1_email, email_1.id AS email_1_id
Пример #5
0
    def test_z_search_with_except_exclude(self):

        search = Search(self.Donkey, "people", self.session)

        search.add_query('name < popp007 and name <>  david' )

        search.add_query('email.email like "popi%"', exclude = True)

        assert len(search.search(exclude_mode = "except").all()) == 4

        search.add_query('donkey_sponsership.amount < 3', exclude = True)

        assert len(search.search(exclude_mode = "except").all()) == 3


        search.add_query('donkey_sponsership.amount between ? and ?', values = [11,13])


        assert len(search.search(exclude_mode = "except").all()) == 6

        search.add_query('donkey_sponsership.amount between 15 and 19')

        assert len(search.search(exclude_mode = "except").all()) == 11

        search.add_query('donkey_sponsership.amount between 15 and 16', exclude = True)
        search.add_query('donkey_sponsership.amount between 17 and 18', exclude = True)

        assert len(search.search(exclude_mode = "except").all()) == 7

        search.add_query('donkey_sponsership.amount between 15 and 19')

        assert len(search.search(exclude_mode = "except").all()) == 11
Пример #6
0
    def test_search_with_joined_exclude(self):

        search = Search(self.Donkey, "people", self.session)

        search.add_query('name < popp007 and name <> david' )

        search.add_query('email.email like "popi%"', exclude = True)

        assert len(search.search().all()) == 4

        search.add_query('donkey_sponsership.amount < 3', exclude = True)

        assert len(search.search().all()) == 3

        search.add_query('donkey_sponsership.amount between 11 and 13')

        assert len(search.search().all()) == 6

        search.add_query('donkey_sponsership.amount between 15 and 19')

        assert len(search.search().all()) == 11

        search.add_query('donkey_sponsership.amount between 15 and 16', exclude = True)
        search.add_query('donkey_sponsership.amount between 17 and 18', exclude = True)

        assert len(search.search().all()) == 7

        search.add_query('donkey_sponsership.amount between 15 and 19')

        assert len(search.search().all()) == 11