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'])
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'))
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)
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))
def search(request): query = FieldSearchQuery(request.GET.copy()) return JsonResponse(query.execute())
def test_bad_offset(self): query = FieldSearchQuery(args={'start': 'invalid'}) result = query.execute() self.assertTrue(result['errors'])
def test_default_sorting_can_not_be_ascending(self): query = FieldSearchQuery(args={'sort': 'asc'}) result = query.execute() self.assertTrue(result['errors'])