Example #1
0
    def test_add_search_sort_selected(self):
        """Test that when add_search_sorts is called with a sort parameter\
            then the search object does have a sort attribute"""
        q = Q("bool", should=[Q("match", Test="test")], minimum_should_match=1)
        query = XSEQueries('test', 'test')
        query.search = query.search.query(q)

        with patch('es_api.utils.queries.SearchSortOption.objects') as \
                sortOpts:
            sortOption = SearchSortOption(display_name="test",
                                          field_name="test-field",
                                          xds_ui_configuration=None,
                                          active=True)
            sortOpts.filter.return_value = [sortOption]
            filters = {"sort": "test-field"}
            hasSort = False

            query.add_search_sort(filters=filters)
            result = query.search
            result_dict = result.to_dict()

            if 'sort' in result_dict:
                hasSort = True

            self.assertTrue(hasSort)
Example #2
0
    def test_add_search_sort_none(self):
        """Test that when add_search_sorts is called with no sort parameter\
            then the search object does not have a sort attribute"""
        q = Q("bool", should=[Q("match", Test="test")], minimum_should_match=1)
        query = XSEQueries('test', 'test')
        query.search = query.search.query(q)

        with patch('es_api.utils.queries.SearchSortOption.objects') as \
                sortOpts:
            sortOpts.filter.return_value = []
            filters = {"test": "Test"}
            hasSort = False

            query.add_search_sort(filters=filters)
            result = query.search
            result_dict = result.to_dict()

            if 'sort' in result_dict:
                hasSort = True

            self.assertFalse(hasSort)