def test_auth_plugin_invocation_with_v1(self, v1_client, ks_session, url_for): with mock.patch(self.auth_plugin) as mock_auth_plugin: args = 'ticket-list' aflo_shell = openstack_shell.OpenStackClientShell() aflo_shell.main(args.split()) self._assert_auth_plugin_args(mock_auth_plugin)
def test_password_prompted_ctrlD_with_v2(self, mock_getpass, mock_stdin): aflo_shell = openstack_shell.OpenStackClientShell() self.make_env(exclude='OS_PASSWORD') # We should get Command Error because we mock Ctl-D. self.assertRaises(exc.CommandError, aflo_shell.main, ['ticket-list']) # Make sure we are actually prompted. mock_getpass.assert_called_with('OS Password: ')
def setUp(self): super(ShellTest, self).setUp() global _old_env _old_env, os.environ = os.environ, self.auth_env global shell, _shell, assert_called, assert_called_anytime _shell = openstack_shell.OpenStackClientShell() shell = lambda cmd: _shell.main(cmd.split())
def test_auth_plugin_invocation_without_tenant_with_v1(self, v1_client): if 'OS_TENANT_NAME' in os.environ: self.make_env(exclude='OS_TENANT_NAME') if 'OS_PROJECT_ID' in os.environ: self.make_env(exclude='OS_PROJECT_ID') args = 'ticket-list' aflo_shell = openstack_shell.OpenStackClientShell() self.assertRaises(exc.CommandError, aflo_shell.main, args.split())
def test_auth_plugin_invocation_with_unversioned_auth_url_with_v1( self, v1_client, ks_session, url_for): with mock.patch(self.auth_plugin) as mock_auth_plugin: args = '--os-auth-url %s ticket-list' % ( keystone_client_fixtures.BASE_URL) aflo_shell = openstack_shell.OpenStackClientShell() aflo_shell.main(args.split()) self._assert_auth_plugin_args(mock_auth_plugin)
def test_no_auth_with_token_and_ticket_url_with_v1(self, v1_client): # test no authentication is required if both token and endpoint url # are specified args = ('--os-auth-token mytoken --os-aflo-url ' 'https://ticket:1234/v1 ' 'ticket-list') aflo_shell = openstack_shell.OpenStackClientShell() aflo_shell.main(args.split()) assert v1_client.called (args, kwargs) = v1_client.call_args self.assertEqual('mytoken', kwargs['token']) self.assertEqual('https://ticket:1234', args[0])
def test_get_base_parser(self): test_shell = openstack_shell.OpenStackClientShell() actual_parser = test_shell.get_base_parser() description = 'Command-line interface to the OpenStack Aflo API.' expected = argparse.ArgumentParser( prog='aflo', usage=None, description=description, conflict_handler='error', add_help=False, formatter_class=openstack_shell.HelpFormatter, ) # NOTE(guochbo): Can't compare ArgumentParser instances directly # Convert ArgumentPaser to string first. self.assertEqual(str(expected), str(actual_parser))
def test_cert_and_key_args_interchangeable(self, mock_versioned_client): # make sure --os-cert and --os-key are passed correctly args = '--os-cert mycert --os-key mykey ticket-list' self.shell(args) assert mock_versioned_client.called ((api_version, args), kwargs) = mock_versioned_client.call_args self.assertEqual('mycert', args.os_cert) self.assertEqual('mykey', args.os_key) # make sure we get the same thing with --cert-file and --key-file args = '--cert-file mycertfile --key-file mykeyfile ticket-list' aflo_shell = openstack_shell.OpenStackClientShell() aflo_shell.main(args.split()) assert mock_versioned_client.called ((api_version, args), kwargs) = mock_versioned_client.call_args self.assertEqual('mycertfile', args.os_cert) self.assertEqual('mykeyfile', args.os_key)
def shell(self, argstr, exitcodes=(0, )): orig = sys.stdout orig_stderr = sys.stderr try: sys.stdout = six.StringIO() sys.stderr = six.StringIO() _shell = openstack_shell.OpenStackClientShell() _shell.main(argstr.split()) except SystemExit: exc_type, exc_value, exc_traceback = sys.exc_info() self.assertIn(exc_value.code, exitcodes) finally: stdout = sys.stdout.getvalue() sys.stdout.close() sys.stdout = orig stderr = sys.stderr.getvalue() sys.stderr.close() sys.stderr = orig_stderr return (stdout, stderr)
def test_api_discovery_failed_with_unversioned_auth_url( self, ks_session, discover): args = '--os-auth-url %s ticket-list' % ( keystone_client_fixtures.BASE_URL) aflo_shell = openstack_shell.OpenStackClientShell() self.assertRaises(exc.CommandError, aflo_shell.main, args.split())
def test_auth_plugin_invocation_without_auth_url_with_v1(self, v1_client): self.make_env(exclude='OS_AUTH_URL') args = 'ticket-list' aflo_shell = openstack_shell.OpenStackClientShell() self.assertRaises(exc.CommandError, aflo_shell.main, args.split())
def test_help(self): shell = openstack_shell.OpenStackClientShell() argstr = 'help' actual = shell.main(argstr.split()) self.assertEqual(0, actual)
def test_help_unknown_command(self): shell = openstack_shell.OpenStackClientShell() argstr = 'help foofoo' self.assertRaises(exc.CommandError, shell.main, argstr.split())