Exemple #1
0
 def test_get_tasks_db(self, mock_get_tasks_by_id):
     action_resource = ActionsStepsResource()
     dag_id = '123456'
     execution_date = DATE_ONE
     action_resource.get_tasks_db(dag_id, execution_date)
     mock_get_tasks_by_id.assert_called_with(dag_id=dag_id,
                                             execution_date=execution_date)
Exemple #2
0
 def test_get_action_step_error_action(self):
     """Validate ApiError, 'Action not found' is raised"""
     action_resource = ActionsStepsResource()
     with patch.object(ActionsStepsResource,
                       'get_action_db') as mock_method:
         mock_method.return_value = None
         with pytest.raises(ApiError) as api_error:
             action_resource.get_action_step(
                 '59bb330a-9e64-49be-a586-d253bb67d443', 'cheese')
         assert 'Action not found' in str(api_error)
Exemple #3
0
    def test_get_action_step_error_step(self):
        """Validate ApiError, 'Step not found' is raised"""
        action_resource = ActionsStepsResource()
        # stubs for db
        action_resource.get_action_db = actions_db
        action_resource.get_tasks_db = tasks_db

        with pytest.raises(ApiError) as api_error:
            step = action_resource.get_action_step(
                '59bb330a-9e64-49be-a586-d253bb67d443', 'cheese')
        assert 'Step not found' in str(api_error)
Exemple #4
0
    def test_get_action_step_success(self):
        """Tests the main response from get all actions"""
        action_resource = ActionsStepsResource()
        # stubs for db
        action_resource.get_action_db = actions_db
        action_resource.get_tasks_db = tasks_db

        step = action_resource.get_action_step(
            '59bb330a-9e64-49be-a586-d253bb67d443', '1c')
        assert step['index'] == 3
        assert step['try_number'] == '3'
        assert step['operator'] == 'smooth'
Exemple #5
0
def start_api():
    middlewares = [
        AuthMiddleware(),
        ContextMiddleware(),
        LoggingMiddleware(),
        CommonParametersMiddleware()
    ]
    control_api = falcon.API(
        request_type=ShipyardRequest, middleware=middlewares)

    control_api.add_route('/versions', VersionsResource())

    # v1.0 of Shipyard API
    v1_0_routes = [
        # API for managing region data
        ('/health', HealthResource()),
        ('/actions', ActionsResource()),
        ('/actions/{action_id}', ActionsIdResource()),
        ('/actions/{action_id}/control/{control_verb}',
         ActionsControlResource()),
        ('/actions/{action_id}/steps/{step_id}',
         ActionsStepsResource()),
        ('/actions/{action_id}/steps/{step_id}/logs',
         ActionsStepsLogsResource()),
        ('/actions/{action_id}/validations/{validation_id}',
         ActionsValidationsResource()),
        ('/configdocs', ConfigDocsStatusResource()),
        ('/configdocs/{collection_id}', ConfigDocsResource()),
        ('/commitconfigdocs', CommitConfigDocsResource()),
        ('/notedetails/{note_id}', NoteDetailsResource()),
        ('/renderedconfigdocs', RenderedConfigDocsResource()),
        ('/workflows', WorkflowResource()),
        ('/workflows/{workflow_id}', WorkflowIdResource()),
        ('/site_statuses', StatusResource()),
    ]

    # Set up the 1.0 routes
    route_v1_0_prefix = '/api/v1.0'
    for path, res in v1_0_routes:
        route = '{}{}'.format(route_v1_0_prefix, path)
        LOG.info(
            'Adding route: %s Handled by %s',
            route,
            res.__class__.__name__
        )
        control_api.add_route(route, res)

    # Error handlers (FILO handling)
    control_api.add_error_handler(Exception, default_exception_handler)
    control_api.add_error_handler(AppError, AppError.handle)

    # built-in error serializer
    control_api.set_error_serializer(default_error_serializer)

    return control_api
Exemple #6
0
 def test_get_action_db(self, mock_get_action_by_id):
     action_resource = ActionsStepsResource()
     action_id = '123456789'
     action_resource.get_action_db(action_id)
     mock_get_action_by_id.assert_called_with(action_id=action_id)