def test_filter_search(self, search):

    def get_expected():
        'Return expected data items sorted by id'
        items = [(item['_id'], item['_source']['first_name'], item['_source']['is_active']) for item in DATA]
        items = sorted(items, key=(lambda tup: (tup[1], (not tup[2]))))
        return items
    es_ordering_fields = (('first_name', 'first_name'), ('is_active', '-active'))
    view = self.create_view(es_ordering_fields)
    request = rf.get('/test/')
    request.query_params = {'ordering': 'first_name,active'}
    search = self.backend.filter_search(request, search, view)
    result = [(item.meta.id, item.first_name, item.is_active) for item in search[:len(DATA)].execute()]
    assert (result == get_expected())
def test_filter_search(self, search):

    def get_expected():
        'Return expected data items sorted by id'
        items = [(item['_id'], item['_source']['first_name'], item['_source']['is_active']) for item in DATA]
        items = sorted(items, key=(lambda tup: (tup[1], (not tup[2]))))
        return items
    es_ordering_fields = (('first_name', 'first_name'), ('is_active', '-active'))
    view = self.create_view(es_ordering_fields)
    request = rf.get('/test/')
    request.query_params = {'ordering': 'first_name,active'}
    search = self.backend.filter_search(request, search, view)
    result = [(item.meta.id, item.first_name, item.is_active) for item in search[:len(DATA)].execute()]
    assert (result == get_expected())