示例#1
0
    def test_query_response_size(self):
        query = FieldSearchQuery(args={'q': 'aceite'})

        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = query.execute()

        self.assertEqual(len(result['data']), result['count'])
示例#2
0
    def test_no_querystring_is_valid(self):
        query = FieldSearchQuery(args={})

        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = query.execute()

        self.assertFalse(result.get('errors'))
示例#3
0
    def test_enhanced_meta(self):
        q = FieldSearchQuery(args={'q': 'a'})

        mock_search = get_mock_search()
        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = q.execute()

        self.assertTrue(result['data'][0]['field']['frequency'], mock_search.periodicity)
        self.assertTrue(result['data'][0]['field']['time_index_start'], mock_search.start_date)
        self.assertTrue(result['data'][0]['field']['time_index_end'], mock_search.end_date)
示例#4
0
    def test_response_params(self):
        limit = '10'
        offset = '15'
        query = FieldSearchQuery(args={'q': 'aceite',
                                       'limit': limit,
                                       'start': offset})

        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = query.execute()

        self.assertEqual(result['limit'], int(limit))
        self.assertEqual(result['start'], int(offset))
示例#5
0
def search(request):
    query = FieldSearchQuery(request.GET.copy())

    return JsonResponse(query.execute())
示例#6
0
    def test_bad_offset(self):
        query = FieldSearchQuery(args={'start': 'invalid'})

        result = query.execute()

        self.assertTrue(result['errors'])
示例#7
0
    def test_default_sorting_can_not_be_ascending(self):
        query = FieldSearchQuery(args={'sort': 'asc'})

        result = query.execute()

        self.assertTrue(result['errors'])