Unit Test for WorkflowResource and WorkflowIdResource
test_workflow_api.py contains the unit tests for the WorkflowResource and WorkflowIdResource .coveragerc was modified to omit the unit test files from test coverage tox.ini was modified to generate an HTML report Change-Id: I86c81fbd65739fc8cc2fd089898aad6d87f7fdc0
This commit is contained in:
parent
2af8f143bd
commit
b430de23dc
@ -1,3 +1,5 @@
|
||||
[run]
|
||||
# omit third party code
|
||||
omit = shipyard_airflow/plugins/rest_api_plugin.py
|
||||
# omit third party code and unit tests
|
||||
omit =
|
||||
shipyard_airflow/plugins/rest_api_plugin.py
|
||||
shipyard_client/tests/*
|
||||
|
@ -76,7 +76,7 @@ class WorkflowIdResource(BaseResource):
|
||||
"""
|
||||
Retrieve a workflow by id,
|
||||
:param helper: The WorkflowHelper constructed for this invocation
|
||||
:param workflow_id: a string in {dag_id}T{execution_date} format
|
||||
:param workflow_id: a string in {dag_id}__{execution_date} format
|
||||
identifying a workflow
|
||||
:returns: a workflow detail dictionary including steps
|
||||
"""
|
||||
|
@ -12,54 +12,89 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from shipyard_airflow.control.af_monitoring.workflow_helper import (
|
||||
WorkflowHelper
|
||||
)
|
||||
WorkflowHelper)
|
||||
from shipyard_airflow.control.af_monitoring.workflows_api import (
|
||||
WorkflowIdResource,
|
||||
WorkflowResource
|
||||
)
|
||||
|
||||
WorkflowResource, WorkflowIdResource)
|
||||
from shipyard_airflow.errors import ApiError
|
||||
from tests.unit.control import common
|
||||
|
||||
|
||||
def test_get_all_workflows():
|
||||
"""
|
||||
test that get_all_workflows invokes the helper properly
|
||||
"""
|
||||
wr = WorkflowResource()
|
||||
with patch.object(WorkflowHelper, 'get_workflow_list') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
wr.get_all_workflows(helper, None)
|
||||
mock_method.assert_called_once_with(since_iso8601=None)
|
||||
class TestWorkflowResource():
|
||||
@patch.object(WorkflowResource, 'get_all_workflows', common.str_responder)
|
||||
def test_on_get(self, api_client):
|
||||
"""Validate the on_get method returns 200 on success"""
|
||||
result = api_client.simulate_get(
|
||||
"/api/v1.0/workflows", headers=common.AUTH_HEADERS)
|
||||
assert result.status_code == 200
|
||||
|
||||
def test_get_all_workflows(self):
|
||||
"""
|
||||
test that get_all_workflows invokes the helper properly
|
||||
"""
|
||||
wr = WorkflowResource()
|
||||
with patch.object(WorkflowHelper, 'get_workflow_list') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
wr.get_all_workflows(helper, None)
|
||||
mock_method.assert_called_once_with(since_iso8601=None)
|
||||
|
||||
|
||||
def test_get_workflow_detail():
|
||||
"""
|
||||
test that get_workflow_detail properly invokes the helper
|
||||
"""
|
||||
wir = WorkflowIdResource()
|
||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
wir.get_workflow_detail(helper,
|
||||
'deploy_site__1972-04-03T10:00:00.20123')
|
||||
mock_method.assert_called_once_with(
|
||||
workflow_id='deploy_site__1972-04-03T10:00:00.20123'
|
||||
)
|
||||
class TestWorkflowIdResource():
|
||||
@patch.object(WorkflowIdResource, 'get_workflow_detail',
|
||||
common.str_responder)
|
||||
def test_on_get(self, api_client):
|
||||
"""Validate the on_get method returns 200 on success"""
|
||||
result = api_client.simulate_get(
|
||||
"/api/v1.0/workflows/123456789", headers=common.AUTH_HEADERS)
|
||||
assert result.status_code == 200
|
||||
|
||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
with pytest.raises(ApiError):
|
||||
wir.get_workflow_detail(helper, None)
|
||||
with pytest.raises(ApiError):
|
||||
wir.get_workflow_detail(helper, 'this is a bad id')
|
||||
with pytest.raises(ApiError):
|
||||
wir.get_workflow_detail(helper, 'dag_idTexecution_date')
|
||||
with pytest.raises(ApiError):
|
||||
wir.get_workflow_detail(helper, 'dag_id_execution_date')
|
||||
def test_get_workflow_detail_success(self):
|
||||
"""
|
||||
test that get_workflow_detail properly invokes the helper
|
||||
"""
|
||||
wir = WorkflowIdResource()
|
||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
wir.get_workflow_detail(helper,
|
||||
'deploy_site__1972-04-03T10:00:00.20123')
|
||||
mock_method.assert_called_once_with(
|
||||
workflow_id='deploy_site__1972-04-03T10:00:00.20123')
|
||||
|
||||
wir.get_workflow_detail(helper, 'dag_id__execution_date')
|
||||
mock_method.assert_called_once_with(workflow_id='dag_id__execution_date')
|
||||
def test_get_workflow_detail_invalid_format(self):
|
||||
"""
|
||||
Assert ApiError 'Invalid Workflow ID specified' is raised when
|
||||
workflow ID is not a valid format, otherwise the error is not raised.
|
||||
"""
|
||||
wir = WorkflowIdResource()
|
||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
with pytest.raises(ApiError) as expected_exc:
|
||||
wir.get_workflow_detail(helper, None)
|
||||
assert "Invalid Workflow ID specified" in str(expected_exc)
|
||||
with pytest.raises(ApiError) as expected_exc:
|
||||
wir.get_workflow_detail(helper, 'this is a bad id')
|
||||
assert "Invalid Workflow ID specified" in str(expected_exc)
|
||||
with pytest.raises(ApiError) as expected_exc:
|
||||
wir.get_workflow_detail(helper, 'dag_idTexecution_date')
|
||||
assert "Invalid Workflow ID specified" in str(expected_exc)
|
||||
with pytest.raises(ApiError) as expected_exc:
|
||||
wir.get_workflow_detail(helper, 'dag_id_execution_date')
|
||||
assert "Invalid Workflow ID specified" in str(expected_exc)
|
||||
wir.get_workflow_detail(helper, 'dag_id__execution_date')
|
||||
mock_method.assert_called_once_with(
|
||||
workflow_id='dag_id__execution_date')
|
||||
|
||||
def test_get_workflow_detail_not_found(self):
|
||||
"""
|
||||
Assert ApiError 'Workflow not found' is raised when get_workflow
|
||||
returns None.
|
||||
"""
|
||||
wir = WorkflowIdResource()
|
||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
||||
helper = WorkflowHelper('')
|
||||
mock_method.return_value = None
|
||||
with pytest.raises(ApiError) as expected_exc:
|
||||
wir.get_workflow_detail(helper, 'dag_id__execution_date')
|
||||
assert "Workflow not found" in str(expected_exc)
|
||||
|
Loading…
Reference in New Issue
Block a user