Use a mock when making external calls in tests.

This commit is contained in:
Dan 2023-02-08 13:14:42 -05:00
parent 84c74e010a
commit f9372effd9
1 changed files with 7 additions and 3 deletions

View File

@ -1,8 +1,8 @@
"""Test_various_bpmn_constructs.""" """Test_various_bpmn_constructs."""
import pytest import pytest
from flask.app import Flask from flask.app import Flask
from unittest.mock import Mock, patch
from tests.spiffworkflow_backend.helpers.base_test import BaseTest from tests.spiffworkflow_backend.helpers.base_test import BaseTest
from spiffworkflow_backend.services.secret_service import SecretService from spiffworkflow_backend.services.secret_service import SecretService
from spiffworkflow_backend.services.service_task_service import ConnectorProxyError from spiffworkflow_backend.services.service_task_service import ConnectorProxyError
from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate
@ -37,6 +37,10 @@ class TestServiceTaskDelegate(BaseTest):
def test_invalid_call_returns_good_error_message( def test_invalid_call_returns_good_error_message(
self, app: Flask, with_db_and_bpmn_file_cleanup: None self, app: Flask, with_db_and_bpmn_file_cleanup: None
) -> None: ) -> None:
with patch('requests.post') as mock_post:
mock_post.return_value.status_code = 404
mock_post.return_value.ok = True
mock_post.return_value.json.return_value = ""
with pytest.raises(ConnectorProxyError) as ae: with pytest.raises(ConnectorProxyError) as ae:
ServiceTaskDelegate.call_connector("my_invalid_operation", {}, {}) ServiceTaskDelegate.call_connector("my_invalid_operation", {}, {})
assert "404" in str(ae) assert "404" in str(ae)