コード例 #1
0
    def test_should_get_result_for_search(self) -> None:
        result = mock_proxy_results()
        self.mock_proxy.fetch_table_search_results.return_value = SearchResult(
            total_results=1, results=[result])

        response = self.app.test_client().get('/search?query_term=searchterm')

        expected_response = {
            "total_results": 1,
            "results": [mock_json_response()]
        }
        self.assertEqual(response.json, expected_response)
        self.assertEqual(response.status_code, HTTPStatus.OK)
        self.mock_proxy.fetch_table_search_results.assert_called_with(
            query_term='searchterm', page_index=0, index='table_search_index')
コード例 #2
0
    def test_should_get_result_for_search_with_query_params(self) -> None:
        result = mock_proxy_results()
        self.mock_proxy.fetch_table_search_results_with_field.return_value = \
            SearchResult(total_results=1, results=[result])

        response = self.app.test_client()\
            .get('/search/field/field_name/field_val/myvalue?query_term=hello&page_index=3')

        expected_response = {
            "total_results": 1,
            "results": [mock_json_response()]
        }
        self.assertEqual(response.json, expected_response)
        self.assertEqual(response.status_code, HTTPStatus.OK)
        self.mock_proxy.fetch_table_search_results_with_field.assert_called_with(
            query_term='hello',
            field_name='field_name',
            field_value='myvalue',
            page_index=3,
            index='table_search_index'
        )