Skip to content
Snippets Groups Projects
Commit 9c8247a8 authored by Charlotte Hausman's avatar Charlotte Hausman
Browse files

logging for Notification Service

parent fd1c0f5c
No related branches found
No related tags found
1 merge request!195logging for Notification Service
Pipeline #1344 passed
import pytest
import warnings
from sqlalchemy import exc as sa_exc
from workspaces.capability.helpers import CapabilitySequence
from workspaces.capability.schema import CapabilityExecution
from workspaces.capability.services.capability_engine import CapabilityEngine
from workspaces.workflow.schema import WorkflowRequest
from workspaces.workflow.services.workflow_service import WorkflowService
pytest_plugins = ["testing.utils.conftest"]
......@@ -12,27 +13,40 @@ Tests for CapabilityEngine
"""
@pytest.mark.usefixtures("mock_capability_execution", "mock_capability_engine")
@pytest.mark.usefixtures("mock_capability_execution", "mock_capability_engine", "mock_workflow_service")
class TestCapabilityEngine:
@pytest.mark.filterwarnings("ignore::sqlalchemy.exc.SAWarning")
def test_load_engine(
self,
mock_capability_engine: CapabilityEngine,
mock_capability_execution: CapabilityExecution,
):
with warnings.catch_warnings():
# suppress SQLAlchemy warnings
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
engine = mock_capability_engine
engine.load_engine(mock_capability_execution)
engine = mock_capability_engine
engine.load_engine(mock_capability_execution)
assert engine.execution == mock_capability_execution
assert engine.execution == mock_capability_execution
def test_execute(self):
# TODO: test that current step is prepare and run workflow
pass
def test_submit_workflow_request(self):
# TODO: test that workflow id is in updated execution object
@pytest.mark.filterwarnings("ignore::sqlalchemy.exc.SAWarning")
def test_execute(
self,
mock_capability_engine: CapabilityEngine
):
assert mock_capability_engine.execution.steps == 'prepare-and-run-workflow null\nawait-workflow'
assert mock_capability_engine.execution.current_step == 0
steps = mock_capability_engine.execution.steps
step = CapabilitySequence.from_str(steps)[0]
assert step.step_value == 'null'
# Execute is confirmed as getting called with the correct steps at this point.
# TODO: The following line can't be run without mocked steps, but this method also belongs to steps so...
# assert step.execute.call_count == 1
@pytest.mark.filterwarnings("ignore::sqlalchemy.exc.SAWarning")
def test_submit_workflow_request(
self,
mock_capability_execution: CapabilityExecution,
mock_workflow_service: WorkflowService,
mock_workflow_requests: WorkflowRequest
):
# assert mock_workflow_service.create_workflow_request(workflow="null", argument="-g") == mock_workflow_requests[0]
pass
......@@ -78,6 +78,8 @@ class CapabilityService(CapabilityServiceIF):
@on_message(type="execution-complete")
def complete_request(self, **message: Dict):
logger.info(f"RECEIVED CAPABILITY MESSAGE: {message}")
execution = message["subject"]
capability_request = self.capability_info.lookup_capability_request(
execution["capability_request_id"]
......@@ -102,7 +104,7 @@ class CapabilityService(CapabilityServiceIF):
:param message: a delivery-type notification with a workflow request
subject and a delivery field
"""
logger.info("Received delivery notification: %s", message)
logger.info("RECEIVED DELIVERY NOTIFICATION: %s", message)
# retrieve the delivery structure in the message
delivery = message["delivery"]
......@@ -119,12 +121,16 @@ class CapabilityService(CapabilityServiceIF):
@on_message(type="capability-submitted")
def notify_submitted(self, **message: Dict):
logger.info(f"RECEIVED CAPABILITY MESSAGE: {message}")
subject = message["subject"]
request = self.capability_info.lookup_capability_request(subject["id"])
self.notify.notify_submitted(request)
@on_message(type="capability-complete")
def notify_complete(self, **message: Dict):
logger.info(f"RECEIVED CAPABILITY MESSAGE: {message}")
subject = message["subject"]
request = self.capability_info.lookup_capability_request(subject["id"])
self.notify.notify_complete(request)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment