def test_project_create_stack_with_existing_name( self, mock_session_call, mock_botocore_session_call): # GIVEN context = self.__set_up_context() context.config.local_project_settings.project_stack_exists.return_value = False context.config.framework_aws_directory_path = "TEST_AWS_DIRECTORY_PATH" context.config.get_pending_project_stack_id.return_value = None # Creating a new stack context.stack.name_exists.return_value = True args = mock.MagicMock() args.region = 'us-east-1' args.files_only = False args.stack_name = "TESTSTACKNAME" args.create_admin_roles = True mock_botocore_session = mock_botocore_session_call.return_value mock_botocore_session.get_available_regions.return_value = [ args.region ] # WHEN with self.assertRaises(HandledError): project.create_stack(context, args) # THEN self.assertEqual(1, context.stack.name_exists.call_count) context.stack.name_exists.assert_called_with(args.stack_name, args.region)
def test_project_create_stack_in_invalid_region_fails( self, mock_session_call, mock_botocore_session_call): # GIVEN context = self.__set_up_context() args = mock.MagicMock() args.region = 'INVALID_REGION' mock_botocore_session = mock_botocore_session_call.return_value mock_botocore_session.get_available_regions.return_value = [ 'VALID_REGION' ] # WHEN - throws exception with self.assertRaises(HandledError): project.create_stack(context, args) # THEN # Check project creation didn't proceed self.assertEqual(0, context.config.initialize_aws_directory.call_count)
def __ensure_cgp_created(self, version: str, cgp_created: bool, mock_session_call: mock.MagicMock): context = self.__set_up_context(framework_version=version) args = mock.MagicMock() args.region = 'us-east-1' args.files_only = True mock_botocore_session = mock_session_call.return_value mock_botocore_session.get_available_regions.return_value = [ args.region ] # WHEN project.create_stack(context, args) # THEN self.assertEqual(1, context.config.initialize_aws_directory.call_count) self.assertEqual( 0, context.config.local_project_settings.project_stack_exists. call_count) context.stack.set_deploy_cgp.set_deploy_cloud_gem_portal(cgp_created)
def test_project_create_stack_files_only(self, mock_session_call, mock_botocore_session_call): # GIVEN context = self.__set_up_context() args = mock.MagicMock() args.region = 'us-east-1' args.files_only = True mock_botocore_session = mock_botocore_session_call.return_value mock_botocore_session.get_available_regions.return_value = [ args.region ] # WHEN project.create_stack(context, args) # THEN # Check we set-up initial aws project self.assertEqual(1, context.config.initialize_aws_directory.call_count) self.assertEqual( 0, context.config.local_project_settings.project_stack_exists. call_count)
def test_project_create_stack_project_already_created( self, mock_session_call, mock_botocore_session_call): # GIVEN context = self.__set_up_context() context.config.local_project_settings.project_stack_exists.return_value = True args = mock.MagicMock() args.region = 'us-east-1' args.files_only = False mock_botocore_session = mock_botocore_session_call.return_value mock_botocore_session.get_available_regions.return_value = [ args.region ] # WHEN # Throws exception because project stack exists with self.assertRaises(HandledError): project.create_stack(context, args) # THEN # Check we set-up initial aws project self.assertEqual( 1, context.config.local_project_settings.project_stack_exists. call_count)
def __project_create_sets_admin_roles_creates_stack( self, create_admin_roles, mock_session_call, mock_botocore_session_call): # GIVEN project_url = "TEST_URL" mock_botocore_session = mock_botocore_session_call.return_value mock_botocore_session.get_available_regions.return_value = [ 'VALID_REGION' ] context = self.__set_up_context() context.config.local_project_settings.project_stack_exists.return_value = False context.config.framework_aws_directory_path = "TEST_AWS_DIRECTORY_PATH" context.config.get_pending_project_stack_id.return_value = None # Creating a new stack context.stack.name_exists.return_value = False # New stack in region context.config.aws_directory_path = "TEST_AWS_DIRECTORY_PATH" # Small Hack to avoid having to simulate loading/saving of of local_project_settings type(context.config).create_admin_roles = mock.PropertyMock( return_value=True if create_admin_roles else False) args = mock.MagicMock() args.region = 'VALID_REGION' args.files_only = False args.stack_name = "TESTSTACKNAME" args.create_admin_roles = create_admin_roles args.record_cognito_pools = False # WHEN unit_common_utils.make_os_path_patcher([True]) with mock.patch("resource_manager.project.ProjectUploader" ) as mock_uploader_call: mock_uploader = mock_uploader_call.return_value mock_uploader.upload_content.return_value = project_url project.create_stack(context, args) self.assertEqual(1, context.stack.name_exists.call_count) context.stack.name_exists.assert_called_with(args.stack_name, args.region) self.assertEqual(1, context.stack.create_using_template.call_count) context.stack.create_using_template.assert_called_with( args.stack_name, project.bootstrap_template, 'VALID_REGION', created_callback=unit_common_utils.AnyArg(), capabilities=context.stack.confirm_stack_operation(), timeout_in_minutes=30, parameters={ 'CreateAdminRoles': 'true' if args.create_admin_roles else 'false' }, tags=[{ 'Value': args.stack_name, 'Key': 'cloudcanvas:project-name' }]) self.assertEqual(1, context.stack.update.call_count) context.stack.update.assert_called_with( context.config.project_stack_id, project_url, parameters={ 'ProjectName': util.get_stack_name_from_arn(context.config.project_stack_id), 'ConfigurationKey': mock_uploader.key, 'CreateAdminRoles': 'true' if args.create_admin_roles else 'false' }, pending_resource_status=unit_common_utils.AnyArg(), capabilities=context.stack.confirm_stack_operation(), tags=unit_common_utils.AnyArg())