def test_filter_no_specs(self, alchemy_db):
        qs = alchemy_db.query(Place)

        backend = SQLAlchemyFilterBackend(qs)
        backend.bind([])

        assert backend.filter() is qs
Пример #2
0
    def test_filter_no_specs(self, alchemy_db):
        qs = alchemy_db.query(Place)

        backend = SQLAlchemyFilterBackend(qs)
        backend.bind([])

        assert backend.filter() is qs
    def test_filter_already_eagerloaded(self, alchemy_db):
        backend = SQLAlchemyFilterBackend(
            alchemy_db.query(Place).options(joinedload(Place.restaurant).joinedload(Restaurant.waiter_set)),
        )
        backend.bind([
            FilterSpec(['restaurant', 'waiter_set', 'name'], 'exact', 'John', False),
        ])

        filtered = backend.filter()

        sql = six.text_type(filtered)
        assert 'place JOIN one_to_one' not in sql
        assert 'place LEFT OUTER JOIN one_to_one' in sql
    def test_filter_already_eagerloaded(self, alchemy_db):
        backend = SQLAlchemyFilterBackend(
            alchemy_db.query(Place).options(
                joinedload(Place.restaurant).joinedload(
                    Restaurant.waiter_set)), )
        backend.bind([
            FilterSpec(['restaurant', 'waiter_set', 'name'], 'exact', 'John',
                       False),
        ])

        filtered = backend.filter()

        sql = six.text_type(filtered)
        assert 'place JOIN one_to_one' not in sql
        assert 'place LEFT OUTER JOIN one_to_one' in sql
Пример #5
0
    def test_filter(self, alchemy_db):
        backend = SQLAlchemyFilterBackend(alchemy_db.query(Place))
        backend.bind([
            FilterSpec(["restaurant", "waiter_set", "name"], "exact", "John",
                       False)
        ])

        filtered = backend.filter()

        sql = six.text_type(filtered)
        # eagerloads via outerjoin
        assert "LEFT OUTER JOIN one_to_one_restaurant" not in sql
        assert "LEFT OUTER JOIN one_to_one_waiter" not in sql
        # for filtering via inner join
        assert "JOIN one_to_one_restaurant" in sql
        assert "JOIN one_to_one_waiter" in sql
Пример #6
0
    def test_filter(self, alchemy_db):
        backend = SQLAlchemyFilterBackend(alchemy_db.query(Place), )
        backend.bind([
            FilterSpec(['restaurant', 'waiter_set', 'name'], 'exact', 'John',
                       False),
        ])

        filtered = backend.filter()

        assert six.text_type(filtered) == (
            'SELECT one_to_one_place.id AS one_to_one_place_id, '
            'one_to_one_place.name AS one_to_one_place_name, '
            'one_to_one_place.address AS one_to_one_place_address \n'
            'FROM one_to_one_place '
            'JOIN one_to_one_restaurant '
            'ON one_to_one_restaurant.place_id = one_to_one_place.id '
            'JOIN one_to_one_waiter '
            'ON one_to_one_waiter.restaurant_id = one_to_one_restaurant.place_id '
            '\nWHERE one_to_one_waiter.name = :name_1')
    def test_filter(self, alchemy_db):
        backend = SQLAlchemyFilterBackend(
            alchemy_db.query(Place),
        )
        backend.bind([
            FilterSpec(['restaurant', 'waiter_set', 'name'], 'exact', 'John', False),
        ])

        filtered = backend.filter()

        assert six.text_type(filtered) == (
            'SELECT one_to_one_place.id AS one_to_one_place_id, '
            'one_to_one_place.name AS one_to_one_place_name, '
            'one_to_one_place.address AS one_to_one_place_address \n'
            'FROM one_to_one_place '
            'JOIN one_to_one_restaurant '
            'ON one_to_one_restaurant.place_id = one_to_one_place.id '
            'JOIN one_to_one_waiter '
            'ON one_to_one_waiter.restaurant_id = one_to_one_restaurant.place_id '
            '\nWHERE one_to_one_waiter.name = :name_1'
        )