Example #1
0
 def test_index_returns_no_result(self, mock_index):
     """Test returns 'DOWN' + status 500 when index returns no results."""
     mock_index.search.return_value = dict(metadata={}, results=[])
     response, status_code, _ = health_check()
     self.assertEqual(response, 'DOWN', "Response content should be DOWN")
     self.assertEqual(status_code, status.HTTP_500_INTERNAL_SERVER_ERROR,
                      "Should return 500 status code.")
Example #2
0
 def test_index_returns_result(self, mock_index):
     """Test returns 'OK' + status 200 when index returns results."""
     mock_index.search.return_value = dict(metadata={}, results=[dict()])
     response, status_code, _ = health_check()
     self.assertEqual(response, 'OK', "Response content should be OK")
     self.assertEqual(status_code, status.HTTP_200_OK,
                      "Should return 200 status code.")
Example #3
0
 def test_index_is_down(self, mock_index):
     """Test returns 'DOWN' + status 500 when index raises an exception."""
     mock_index.search.side_effect = RuntimeError
     response, status_code, _ = health_check()
     self.assertEqual(response, 'DOWN', "Response content should be DOWN")
     self.assertEqual(status_code, status.HTTP_500_INTERNAL_SERVER_ERROR,
                      "Should return 500 status code.")
Example #4
0
def service_status() -> Union[str, Response]:
    """
    Health check endpoint for search.

    Exercises the search index connection with a real query.
    """
    return health_check()  # type: ignore
Example #5
0
 def test_index_returns_result(self, mock_index):
     """Test returns 'OK' + status 200 when index returns results."""
     mock_index.search.return_value = {"metadata": {}, "results": [{}]}
     response, status_code, _ = health_check()
     self.assertEqual(response, "OK", "Response content should be OK")
     self.assertEqual(status_code, HTTPStatus.OK,
                      "Should return 200 status code.")
Example #6
0
 def test_index_returns_no_result(self, mock_index):
     """Test returns 'DOWN' + status 500 when index returns no results."""
     mock_index.search.return_value = {"metadata": {}, "results": []}
     response, status_code, _ = health_check()
     self.assertEqual(response, "DOWN", "Response content should be DOWN")
     self.assertEqual(
         status_code,
         HTTPStatus.INTERNAL_SERVER_ERROR,
         "Should return 500 status code.",
     )
Example #7
0
def service_status() -> _Response:
    """
    Health check endpoint for search.

    Exercises the search index connection with a real query.
    """
    content, code, hdrs = health_check()
    response: Response = make_response(content)
    response.status_code = code
    for key, value in hdrs.items():
        response.headers[key] = value
    return response