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]
|
[run]
|
||||||
# omit third party code
|
# omit third party code and unit tests
|
||||||
omit = shipyard_airflow/plugins/rest_api_plugin.py
|
omit =
|
||||||
|
shipyard_airflow/plugins/rest_api_plugin.py
|
||||||
|
shipyard_client/tests/*
|
||||||
|
@ -76,7 +76,7 @@ class WorkflowIdResource(BaseResource):
|
|||||||
"""
|
"""
|
||||||
Retrieve a workflow by id,
|
Retrieve a workflow by id,
|
||||||
:param helper: The WorkflowHelper constructed for this invocation
|
: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
|
identifying a workflow
|
||||||
:returns: a workflow detail dictionary including steps
|
:returns: a workflow detail dictionary including steps
|
||||||
"""
|
"""
|
||||||
|
@ -12,54 +12,89 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from shipyard_airflow.control.af_monitoring.workflow_helper import (
|
from shipyard_airflow.control.af_monitoring.workflow_helper import (
|
||||||
WorkflowHelper
|
WorkflowHelper)
|
||||||
)
|
|
||||||
from shipyard_airflow.control.af_monitoring.workflows_api import (
|
from shipyard_airflow.control.af_monitoring.workflows_api import (
|
||||||
WorkflowIdResource,
|
WorkflowResource, WorkflowIdResource)
|
||||||
WorkflowResource
|
|
||||||
)
|
|
||||||
|
|
||||||
from shipyard_airflow.errors import ApiError
|
from shipyard_airflow.errors import ApiError
|
||||||
|
from tests.unit.control import common
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_workflows():
|
class TestWorkflowResource():
|
||||||
"""
|
@patch.object(WorkflowResource, 'get_all_workflows', common.str_responder)
|
||||||
test that get_all_workflows invokes the helper properly
|
def test_on_get(self, api_client):
|
||||||
"""
|
"""Validate the on_get method returns 200 on success"""
|
||||||
wr = WorkflowResource()
|
result = api_client.simulate_get(
|
||||||
with patch.object(WorkflowHelper, 'get_workflow_list') as mock_method:
|
"/api/v1.0/workflows", headers=common.AUTH_HEADERS)
|
||||||
helper = WorkflowHelper('')
|
assert result.status_code == 200
|
||||||
wr.get_all_workflows(helper, None)
|
|
||||||
mock_method.assert_called_once_with(since_iso8601=None)
|
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():
|
class TestWorkflowIdResource():
|
||||||
"""
|
@patch.object(WorkflowIdResource, 'get_workflow_detail',
|
||||||
test that get_workflow_detail properly invokes the helper
|
common.str_responder)
|
||||||
"""
|
def test_on_get(self, api_client):
|
||||||
wir = WorkflowIdResource()
|
"""Validate the on_get method returns 200 on success"""
|
||||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
result = api_client.simulate_get(
|
||||||
helper = WorkflowHelper('')
|
"/api/v1.0/workflows/123456789", headers=common.AUTH_HEADERS)
|
||||||
wir.get_workflow_detail(helper,
|
assert result.status_code == 200
|
||||||
'deploy_site__1972-04-03T10:00:00.20123')
|
|
||||||
mock_method.assert_called_once_with(
|
|
||||||
workflow_id='deploy_site__1972-04-03T10:00:00.20123'
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
def test_get_workflow_detail_success(self):
|
||||||
helper = WorkflowHelper('')
|
"""
|
||||||
with pytest.raises(ApiError):
|
test that get_workflow_detail properly invokes the helper
|
||||||
wir.get_workflow_detail(helper, None)
|
"""
|
||||||
with pytest.raises(ApiError):
|
wir = WorkflowIdResource()
|
||||||
wir.get_workflow_detail(helper, 'this is a bad id')
|
with patch.object(WorkflowHelper, 'get_workflow') as mock_method:
|
||||||
with pytest.raises(ApiError):
|
helper = WorkflowHelper('')
|
||||||
wir.get_workflow_detail(helper, 'dag_idTexecution_date')
|
wir.get_workflow_detail(helper,
|
||||||
with pytest.raises(ApiError):
|
'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='deploy_site__1972-04-03T10:00:00.20123')
|
||||||
|
|
||||||
wir.get_workflow_detail(helper, 'dag_id__execution_date')
|
def test_get_workflow_detail_invalid_format(self):
|
||||||
mock_method.assert_called_once_with(workflow_id='dag_id__execution_date')
|
"""
|
||||||
|
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)
|
||||||
|
3
tox.ini
3
tox.ini
@ -50,5 +50,6 @@ commands =
|
|||||||
--cov-branch \
|
--cov-branch \
|
||||||
--cov-report term-missing:skip-covered \
|
--cov-report term-missing:skip-covered \
|
||||||
--cov-config .coveragerc \
|
--cov-config .coveragerc \
|
||||||
|
--cov=shipyard_airflow \
|
||||||
--cov=shipyard_client \
|
--cov=shipyard_client \
|
||||||
--cov=shipyard_airflow
|
--cov-report=html
|
||||||
|
Loading…
Reference in New Issue
Block a user