def test_logs__platform_workspace__stream_logs__unable_to_find_cloudwatch_logs( self, PackerStreamFormatter_mock, paginate_cloudwatch_logs_mock, stream_platform_logs_mock, get_platform_version_mock, get_platform_name_mock): self.setup_platform_workspace() streamer_formatter_mock = mock.MagicMock() PackerStreamFormatter_mock.return_value = streamer_formatter_mock get_platform_name_mock.return_value = 'custom-platform-4' stream_platform_logs_mock.side_effect = logs.NotFoundError with self.assertRaises(logs.NotFoundError) as context_manager: app = EBP(argv=['logs', '1.0.3', '--stream']) app.setup() app.run() self.assertEqual('Unable to find logs in CloudWatch.', str(context_manager.exception)) paginate_cloudwatch_logs_mock.assert_not_called() stream_platform_logs_mock.assert_called_once_with( 'custom-platform-4', '1.0.3', formatter=streamer_formatter_mock, log_name='custom-platform-4/1.0.3') get_platform_version_mock.assert_not_called()
def test_delete__single_platform_version(self, delete_platform_version_mock): app = EBP(argv=['delete', '1.1.1', '--force']) app.setup() app.run() delete_platform_version_mock.assert_called_once_with('1.1.1', True)
def test_delete__all_failed_versions__force( self, validate_action_mock, delete_platform_version_mock, list_custom_platform_versions_mock ): list_custom_platform_versions_mock.return_value = [ 'arn:aws:elasticbeanstalk:us-west-2:123123123123:platform/ibnlempnsr-custom-platform/1.0.1', 'arn:aws:elasticbeanstalk:us-west-2:123123123123:platform/ibnlempnsr-custom-platform/1.0.0' ] validate_action_mock.side_effect = None app = EBP(argv=['delete', '--cleanup', '--all-platforms', '--force']) app.setup() app.run() self.assertEqual(2, delete_platform_version_mock.call_count) validate_action_mock.assert_not_called() delete_platform_version_mock.assert_has_calls( [ mock.call( 'arn:aws:elasticbeanstalk:us-west-2:123123123123:platform/ibnlempnsr-custom-platform/1.0.0', force=True ), mock.call( 'arn:aws:elasticbeanstalk:us-west-2:123123123123:platform/ibnlempnsr-custom-platform/1.0.1', force=True ) ] )
def test_list__application_workspace__verbose_mode( self, echo_mock, list_custom_platform_versions_mock, get_all_solution_stacks_mock ): self.setup_application_workspace() get_all_solution_stacks_mock.return_value = [ SolutionStack('64bit Amazon Linux 2017.09 v4.4.0 running Node.js'), SolutionStack('64bit Amazon Linux 2017.09 v2.6.0 running PHP 5.4') ] list_custom_platform_versions_mock.return_value = [ 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.0.3', 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-5/1.3.6' ] app = EBP(argv=['list', '--verbose']) app.setup() app.run() echo_mock.assert_called_once_with( '64bit Amazon Linux 2017.09 v4.4.0 running Node.js', '64bit Amazon Linux 2017.09 v2.6.0 running PHP 5.4', 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.0.3', 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-5/1.3.6', sep='{linesep}'.format(linesep=os.linesep) )
def test_list__platform_workspace__filter_by_status( self, echo_mock, list_custom_platform_versions_mock, get_platform_name_mock ): self.setup_platform_workspace() list_custom_platform_versions_mock.return_value = [ 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.0.3', 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.3.6' ] app = EBP(argv=['list', '-a', '-s', 'READY']) app.setup() app.run() get_platform_name_mock.assert_not_called() list_custom_platform_versions_mock.assert_called_once_with( platform_name=None, show_status=True, status='READY' ) echo_mock.assert_called_once_with( 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.0.3', 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.3.6', sep='{linesep}'.format(linesep=os.linesep) )
def test_list__neutral_workspace__command_is_not_applicable(self): self.setup_platform_workspace() fileoperations.write_config_setting('global', 'workspace_type', None) app = EBP(argv=['list']) app.setup() app.run()
def test_init__interactive_mode__pass_keyname_in_interactive( self, get_keyname_mock, get_platform_name_and_version_mock, setup_mock, set_region_mock, set_up_credentials_mock, get_region_mock, touch_config_folder_mock, write_keyname_mock, set_workspace_to_latest_mock ): get_region_mock.return_value = 'us-west-2' get_platform_name_and_version_mock.return_value = ('my-custom-platform', '1.0.3') set_up_credentials_mock.return_value = 'us-west-2' app = EBP(argv=['init', '-k', 'keyname']) app.setup() app.run() set_region_mock.assert_has_calls([mock.call(None), mock.call('us-west-2')]) set_up_credentials_mock.assert_called_once_with(None, 'us-west-2', True) setup_mock.assert_called_once_with( 'Custom Platform Builder', 'us-west-2', None, platform_name='my-custom-platform', platform_version='1.0.3', workspace_type='Platform' ) get_region_mock.assert_called_once_with(None, True) touch_config_folder_mock.assert_called_once_with() write_keyname_mock.assert_called_once_with('keyname') set_workspace_to_latest_mock.assert_not_called() get_keyname_mock.assert_not_called()
def test_delete__version_not_specified( self, delete_platform_version_mock ): app = EBP(argv=['delete', '--force']) app.setup() app.run() delete_platform_version_mock.assert_not_called()
def test_logs__application_workspace__command_not_applicable(self): self.setup_application_workspace() with self.assertRaises( ApplicationWorkspaceNotSupportedError) as context_manager: app = EBP(argv=['logs']) app.setup() app.run() self.assertEqual( 'This command is not supported outside Platform workspaces.', str(context_manager.exception))
def test_logs__neutral_workspace__command_not_applicable(self): self.setup_application_workspace() fileoperations.write_config_setting('global', 'workspace', None) with self.assertRaises( ApplicationWorkspaceNotSupportedError) as context_manager: app = EBP(argv=['logs']) app.setup() app.run() self.assertEqual( 'This command is not supported outside Platform workspaces.', str(context_manager.exception))
def test_logs__platform_workspace__version_not_specified__stream_argument_not_specified__print_paginated_logs( self, paginate_cloudwatch_logs_mock, stream_platform_logs_mock, get_platform_version_mock, get_platform_name_mock): self.setup_platform_workspace() get_platform_name_mock.return_value = 'custom-platform-4' get_platform_version_mock.return_value = '1.0.3' app = EBP(argv=['logs']) app.setup() app.run() paginate_cloudwatch_logs_mock.assert_called_once_with( 'custom-platform-4', '1.0.3') stream_platform_logs_mock.assert_not_called()
def test_logs__platform_workspace__version_specified_and_is_valid_short_format( self, paginate_cloudwatch_logs_mock, stream_platform_logs_mock, get_platform_version_mock, get_platform_name_mock): self.setup_platform_workspace() get_platform_name_mock.return_value = 'custom-platform-4' app = EBP(argv=['logs', 'custom-platform-4/1.0.3']) app.setup() app.run() paginate_cloudwatch_logs_mock.assert_called_once_with( 'custom-platform-4', '1.0.3') stream_platform_logs_mock.assert_not_called() get_platform_version_mock.assert_not_called()
def test_logs__platform_workspace__version_specified_and_is_valid_platform_arn( self, paginate_cloudwatch_logs_mock, stream_platform_logs_mock, get_platform_version_mock, get_platform_name_mock): self.setup_platform_workspace() get_platform_name_mock.return_value = 'custom-platform-4' app = EBP(argv=[ 'logs', 'arn:aws:elasticbeanstalk:us-west-2:123123123:platform/custom-platform-4/1.0.3' ]) app.setup() app.run() paginate_cloudwatch_logs_mock.assert_called_once_with( 'custom-platform-4', '1.0.3') stream_platform_logs_mock.assert_not_called() get_platform_version_mock.assert_not_called()
def test_logs__platform_workspace__version_specified_and_is_invalid( self, paginate_cloudwatch_logs_mock, stream_platform_logs_mock, get_platform_version_mock, get_platform_name_mock): self.setup_platform_workspace() get_platform_name_mock.return_value = 'custom-platform-4' with self.assertRaises( logs.InvalidPlatformVersionError) as context_manager: app = EBP(argv=['logs', '1.0.3.5']) app.setup() app.run() self.assertEqual( 'Invalid version format. Only ARNs, version numbers, or platform_name/version formats are accepted.', str(context_manager.exception)) paginate_cloudwatch_logs_mock.assert_not_called() stream_platform_logs_mock.assert_not_called() get_platform_version_mock.assert_not_called()
def test_create__pass_major_minor_and_patch_versions( self, create_platform_version_mock, get_instance_profile_mock): get_instance_profile_mock.return_value = 'my-instance-profile' app = EBP(argv=['create', '1.1.1', '-M', '-m', '-p']) app.setup() app.run() create_platform_version_mock.assert_called_once_with( '1.1.1', True, True, True, None, { 'id': None, 'subnets': None, 'publicip': False }, tags=None, timeout=None)
def test_create__pass_instance_type(self, create_platform_version_mock, get_instance_profile_mock): get_instance_profile_mock.return_value = 'my-instance-profile' app = EBP(argv=['create', '-i', 'c4x.large']) app.setup() app.run() create_platform_version_mock.assert_called_once_with( None, False, False, False, 'c4x.large', { 'id': None, 'subnets': None, 'publicip': False }, tags=None, timeout=None)
def test_logs__platform_workspace__stream_logs( self, PackerStreamFormatter_mock, paginate_cloudwatch_logs_mock, stream_platform_logs_mock, get_platform_version_mock, get_platform_name_mock): self.setup_platform_workspace() streamer_formatter_mock = mock.MagicMock() PackerStreamFormatter_mock.return_value = streamer_formatter_mock get_platform_name_mock.return_value = 'custom-platform-4' app = EBP(argv=['logs', '1.0.3', '--stream']) app.setup() app.run() paginate_cloudwatch_logs_mock.assert_not_called() stream_platform_logs_mock.assert_called_once_with( 'custom-platform-4', '1.0.3', formatter=streamer_formatter_mock, log_name='custom-platform-4/1.0.3') get_platform_version_mock.assert_not_called()
def test_create__pass_instance_type_instance_profile_and_vpc_parameters( self, create_platform_version_mock, get_instance_profile_mock): get_instance_profile_mock.return_value = 'my-instance-profile' app = EBP(argv=[ 'create', '-i', 'c4x.large', '-ip', 'my-instance-profile', '--vpc.id', 'vpc-123124', '--vpc.subnets', 'subnet-123123,subnet-2334545', '--vpc.publicip' ]) app.setup() app.run() create_platform_version_mock.assert_called_once_with( None, False, False, False, 'c4x.large', { 'id': 'vpc-123124', 'subnets': 'subnet-123123,subnet-2334545', 'publicip': True }, tags=None, timeout=None)
def test_events__follow(self, show_platform_events_mock): app = EBP(argv=['events', '--follow']) app.setup() app.run() show_platform_events_mock.assert_called_once_with(True, None)
def test_events(self, show_platform_events_mock): app = EBP(argv=['events']) app.setup() app.run() show_platform_events_mock.assert_called_once_with(False, None)
def test_ebp_help(self): with self.assertRaises(SystemExit): app = EBP(argv=['--help']) app.setup() app.run()