def test_get_collection(self): helper = None with patch.object(ConfigdocsHelper, 'get_collection_docs') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) cdr.get_collection(helper, 'apples') mock_method.assert_called_once_with('buffer', 'apples')
def test__validate_deployment_version(self): """Test of the validate deployment version function """ helper = None with patch.object(ConfigdocsHelper, 'check_for_document') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) cdr._validate_deployment_version(helper, 'oranges') mock_method.assert_called_once_with('oranges', DEPLOYMENT_DATA_DOC['name'], DEPLOYMENT_DATA_DOC['schema'])
def test_post_collection(self): """ Tests the post collection method of the ConfigdocsResource """ helper = None collection_id = 'trees' document_data = 'lots of info' with patch.object(ConfigdocsHelper, 'add_collection') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) helper.is_buffer_valid_for_bucket = lambda a, b: True helper.get_deckhand_validation_status = ( lambda a: ConfigdocsHelper._format_validations_to_status([], 0) ) cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) mock_method.assert_called_once_with(collection_id, document_data) with pytest.raises(ApiError): cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) # not valid for bucket helper.is_buffer_valid_for_bucket = lambda a, b: False helper.get_deckhand_validation_status = ( lambda a: ConfigdocsHelper._format_validations_to_status([], 0) ) cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data)
def test_post_collection_not_valid_for_buffer(self): """ Tests the post collection method of the ConfigdocsResource """ CONF.set_override('deployment_version_create', 'Skip', 'validations') helper = None collection_id = 'trees' document_data = 'lots of info' with pytest.raises(ApiError) as apie: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) # not valid for bucket cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) assert apie.value.status == '409 Conflict'
def test_post_collection(self): """ Tests the post collection method of the ConfigdocsResource """ CONF.set_override('deployment_version_create', 'Skip', 'validations') helper = None collection_id = 'trees' document_data = 'lots of info' with patch.object(ConfigdocsHelper, 'add_collection') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) mock_method.assert_called_once_with(collection_id, document_data)
def test_post_collection_not_valid_for_buffer(self): """ Tests the post collection method of the ConfigdocsResource """ helper = None collection_id = 'trees' document_data = 'lots of info' with pytest.raises(ApiError) as apie: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) # not valid for bucket helper.get_deckhand_validation_status = ( lambda a: configdocs_helper._format_validations_to_status([], 0 )) cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) assert apie.value.status == '409 Conflict'
def test_post_collection_deployment_version_missing_info(self): """ Tests the post collection method of the ConfigdocsResource """ # Make sure that the configuration value is handled case-insensitively CONF.set_override('deployment_version_create', 'iNfO', 'validations') helper = None collection_id = 'trees' document_data = 'lots of info' with patch.object(ConfigdocsHelper, 'add_collection') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) status = cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) assert len(status['details']['messageList']) == 1 assert status['details']['messageList'][0]['level'] == 'info' mock_method.assert_called_once_with(collection_id, document_data)
def test_post_collection_deployment_version_missing_error(self): """ Tests the post collection method of the ConfigdocsResource """ # Make sure that the configuration value is handled case-insensitively CONF.set_override('deployment_version_create', 'eRRoR', 'validations') helper = None collection_id = 'trees' document_data = 'lots of info' cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) with pytest.raises(ApiError) as apie: cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) assert apie.value.status == '400 Bad Request' assert apie.value.title == ('Deployment version document missing from ' 'collection')
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_post_collection_not_added(self): """ Tests the post collection method of the ConfigdocsResource """ helper = None collection_id = 'trees' document_data = 'lots of info' with patch.object(ConfigdocsHelper, 'add_collection') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) helper.get_deckhand_validation_status = ( lambda a: configdocs_helper._format_validations_to_status([], 0 )) with pytest.raises(ApiError) as apie: cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) assert apie.value.status == '400 Bad Request' mock_method.assert_called_once_with(collection_id, document_data)
def test_post_collection_not_added(self): """ Tests the post collection method of the ConfigdocsResource """ CONF.set_override('deployment_version_create', 'Skip', 'validations') helper = None collection_id = 'trees' document_data = 'lots of info' with patch.object(ConfigdocsHelper, 'add_collection') as mock_method: cdr = ConfigDocsResource() helper = ConfigdocsHelper(CTX) with pytest.raises(ApiError) as apie: cdr.post_collection(helper=helper, collection_id=collection_id, document_data=document_data) assert apie.value.status == '400 Bad Request' assert apie.value.title == ('Collection {} not added to Shipyard ' 'buffer'.format(collection_id)) mock_method.assert_called_once_with(collection_id, document_data)
def test__validate_version_parameter(self): """ test of the version parameter validation """ cdr = ConfigDocsResource() with pytest.raises(ApiError): cdr._validate_version_parameter('asdfjkl') for version in ('buffer', 'committed'): try: cdr._validate_version_parameter(version) except ApiError: # should not raise an exception. assert False