Beispiel #1
0
def search_query(request):
    form = forms.QueryForm(request.POST)
    if not form.is_valid():
        return http.HttpResponseBadRequest(form.errors)

    api = Query()
    results = api.get(query=form.cleaned_data['query'],
                      indices=form.cleaned_data['indices'])

    return results
Beispiel #2
0
def search_query(request):
    form = forms.QueryForm(request.POST)
    if not form.is_valid():
        return http.HttpResponseBadRequest(form.errors)

    api = Query()
    results = api.get(
        query=form.cleaned_data['query'],
        indices=form.cleaned_data['indices']
    )

    return results
Beispiel #3
0
    def test_search_query(self):
        self.create_custom_query_perm()

        def mocked_query_get(**params):
            assert "query" in params

            return {"hits": []}

        Query.implementation().get.side_effect = mocked_query_get

        url = reverse("supersearch:search_query")
        response = self.client.post(url, {"query": '{"query": {}}'})
        assert response.status_code == 200

        content = json.loads(response.content)
        assert "hits" in content
        assert content["hits"] == []

        # Test a failure.
        response = self.client.post(url)
        assert response.status_code == 400
        assert "query" in smart_text(response.content)
Beispiel #4
0
    def test_search_query(self):
        self.create_custom_query_perm()

        def mocked_query_get(**params):
            ok_('query' in params)

            return {"hits": []}

        Query.implementation().get.side_effect = (mocked_query_get)

        url = reverse('supersearch.search_query')
        response = self.client.post(url, {'query': '{"query": {}}'})
        eq_(response.status_code, 200)

        content = json.loads(response.content)
        ok_('hits' in content)
        eq_(content['hits'], [])

        # Test a failure.
        response = self.client.post(url)
        eq_(response.status_code, 400)
        ok_('query' in response.content)
Beispiel #5
0
    def test_search_query(self):
        self.create_custom_query_perm()

        def mocked_query_get(**params):
            assert 'query' in params

            return {"hits": []}

        Query.implementation().get.side_effect = mocked_query_get

        url = reverse('supersearch:search_query')
        response = self.client.post(url, {'query': '{"query": {}}'})
        assert response.status_code == 200

        content = json.loads(response.content)
        assert 'hits' in content
        assert content['hits'] == []

        # Test a failure.
        response = self.client.post(url)
        assert response.status_code == 400
        assert 'query' in smart_text(response.content)
Beispiel #6
0
    def test_search_query(self):
        self.create_custom_query_perm()

        def mocked_query_get(**params):
            assert 'query' in params

            return {"hits": []}

        Query.implementation().get.side_effect = (
            mocked_query_get
        )

        url = reverse('supersearch.search_query')
        response = self.client.post(url, {'query': '{"query": {}}'})
        assert response.status_code == 200

        content = json.loads(response.content)
        assert 'hits' in content
        assert content['hits'] == []

        # Test a failure.
        response = self.client.post(url)
        assert response.status_code == 400
        assert 'query' in response.content
Beispiel #7
0
    def test_search_query(self):
        self.create_custom_query_perm()

        def mocked_query_get(**params):
            ok_('query' in params)

            return {"hits": []}

        Query.implementation().get.side_effect = (
            mocked_query_get
        )

        url = reverse('supersearch.search_query')
        response = self.client.post(url, {'query': '{"query": {}}'})
        eq_(response.status_code, 200)

        content = json.loads(response.content)
        ok_('hits' in content)
        eq_(content['hits'], [])

        # Test a failure.
        response = self.client.post(url)
        eq_(response.status_code, 400)
        ok_('query' in response.content)