def test_commit_configdocs(self): """ Tests the CommitConfigDocsResource method commit_configdocs """ ccdr = CommitConfigDocsResource() commit_resp = None with patch.object(ConfigdocsHelper, 'tag_buffer') as mock_method: helper = ConfigdocsHelper(CTX) helper.is_buffer_empty = lambda: False helper.get_validations_for_revision = lambda x: { 'status': 'Success' } helper.get_revision_id = lambda x: 1 commit_resp = ccdr.commit_configdocs(helper, False, False) mock_method.assert_called_once_with('committed') assert commit_resp['status'] == 'Success' commit_resp = None with patch.object(ConfigdocsHelper, 'tag_buffer') as mock_method: helper = ConfigdocsHelper(CTX) helper.is_buffer_empty = lambda: False helper.get_validations_for_revision = ( lambda x: { 'status': 'Failure', 'code': '400 Bad Request', 'message': 'this is a mock response' }) helper.get_revision_id = lambda x: 1 commit_resp = ccdr.commit_configdocs(helper, False, False) assert '400' in commit_resp['code'] assert commit_resp['message'] is not None assert commit_resp['status'] == 'Failure'
def test_commit_configdocs_buffer_err(self): """ Tests the CommitConfigDocsResource method commit_configdocs """ ccdr = CommitConfigDocsResource() with pytest.raises(ApiError): helper = ConfigdocsHelper(CTX) helper.is_buffer_empty = lambda: True helper.get_validations_for_buffer = lambda: {'status': 'Success'} ccdr.commit_configdocs(helper, False, False)
def test_commit_configdocs_dryrun(self): """ Tests the CommitConfigDocsResource method commit_configdocs """ ccdr = CommitConfigDocsResource() commit_resp = None with patch.object(ConfigdocsHelper, 'tag_buffer') as mock_method: helper = ConfigdocsHelper(CTX) helper.is_buffer_empty = lambda: False helper.get_validations_for_buffer = lambda: {'status': 'Success'} commit_resp = ccdr.commit_configdocs(helper, False, True) assert '200' in commit_resp['code'] assert commit_resp['message'] == 'DRYRUN' assert commit_resp['status'] == 'Success'
def test_commit_configdocs_force(self): """ Tests the CommitConfigDocsResource method commit_configdocs """ ccdr = CommitConfigDocsResource() commit_resp = None with patch.object(ConfigdocsHelper, 'tag_buffer') as mock_method: helper = ConfigdocsHelper(CTX) helper.is_buffer_empty = lambda: False helper.get_validations_for_buffer = lambda: {'status': 'Failure'} commit_resp = ccdr.commit_configdocs(helper, True, False) mock_method.assert_called_once_with('committed') assert '200' in commit_resp['code'] assert 'FORCED' in commit_resp['message'] assert commit_resp['status'] == 'Failure'
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
def test_on_post(self, mock_acquire, mock_release, api_client): queries = ["", "force=true", "dryrun=true"] ccdr = CommitConfigDocsResource() with patch.object(CommitConfigDocsResource, 'commit_configdocs', return_value={}) as mock_method: for q in queries: result = api_client.simulate_post("/api/v1.0/commitconfigdocs", query_string=q, headers=common.AUTH_HEADERS) assert result.status_code == 200 mock_method.assert_has_calls([ mock.call(ANY, False, False), mock.call(ANY, True, False), mock.call(ANY, False, True) ])