Ejemplo n.º 1
0
    def test_get_post_data_instance_prediction(self, mock_request_json):
        mock_model = mock.Mock()
        mock_model.predict.return_value = [1]

        # Succeed
        mock_request_json.return_value = {'id': None}
        prediction_service = PredictionService(
            model=mock_model,
            name=mock.MagicMock(),
            api_version=mock.MagicMock(),
            meta={},
            preprocessor=None,
            postprocessor=None,
            batch_prediction=False,
            additional_checks=None
        )
        _ = prediction_service._predict()
Ejemplo n.º 2
0
 def test_serve_no_processing_single(self, mock_request_json):
     # make sure it doesn't break when processors are None
     model = mock.Mock()
     model_name = api_version = mock.MagicMock()
     mock_request_json.return_value = {'id': None}
     model.predict.return_value = [1]
     prediction_service = PredictionService(
         model=model,
         name=model_name,
         api_version=api_version,
         meta={},
         preprocessor=None,
         postprocessor=None,
         batch_prediction=False,
         additional_checks=None
     )
     _ = prediction_service._predict()
Ejemplo n.º 3
0
    def test_get_post_data_batch_prediction(self, mock_request_json):
        mock_model = mock.Mock()
        mock_model.predict.return_value = []
        mock_name = mock_version = mock.MagicMock()

        # Succeed
        mock_request_json.return_value = [{'id': 1}]
        prediction_service = PredictionService(
            model=mock_model,
            name=mock_name,
            api_version=mock_version,
            meta={},
            preprocessor=None,
            postprocessor=None,
            batch_prediction=True,
            additional_checks=None
        )
        _ = prediction_service._predict()
Ejemplo n.º 4
0
 def test__predict_additional_checks(self, mock_request_json):
     model = mock.Mock()
     model_name = api_version = mock.MagicMock()
     mock_request_json.return_value = {'id': 1}
     model.predict.return_value = [1]
     mock_additional_checks = mock.Mock()
     prediction_service = PredictionService(
         model=model,
         name=model_name,
         api_version=api_version,
         meta={},
         preprocessor=None,
         postprocessor=None,
         batch_prediction=False,
         additional_checks=mock_additional_checks
     )
     _ = prediction_service._predict()
     mock_additional_checks.assert_called()
Ejemplo n.º 5
0
 def test__predict_additional_checks_raises_422(self, mock_request_json):
     model = mock.Mock()
     model_name = api_version = mock.MagicMock()
     mock_request_json.return_value = {'id': 1}
     model.predict.return_value = [1]
     mock_additional_checks = mock.Mock()
     mock_additional_checks.side_effect = ValueError('verify user message is passed on')
     prediction_service = PredictionService(
         model=model,
         name=model_name,
         api_version=api_version,
         meta={},
         preprocessor=None,
         postprocessor=None,
         batch_prediction=False,
         additional_checks=mock_additional_checks
     )
     with self.assertRaisesRegex(werkzeug_exc.UnprocessableEntity, '.*verify user message is passed on.*'):
         _ = prediction_service._predict()
     mock_additional_checks.assert_called()
Ejemplo n.º 6
0
 def test_serve_with_processing_single(self, mock_request_json):
     model = mock.Mock()
     model_name = api_version = mock.MagicMock()
     mock_request_json.return_value = {'id': None}
     model.predict.return_value = [1]
     mock_preprocessor = mock.Mock()
     mock_preprocessor.process.return_value = {}
     mock_postprocessor = mock.Mock()
     mock_postprocessor.process.return_value = [1]
     prediction_service = PredictionService(
         model=model,
         name=model_name,
         api_version=api_version,
         meta={},
         preprocessor=mock_preprocessor,
         postprocessor=mock_postprocessor,
         batch_prediction=False,
         additional_checks=None
     )
     _ = prediction_service._predict()
     mock_preprocessor.process.assert_called()
     mock_postprocessor.process.assert_called()