Exemple #1
0
 def test_configure_from_config_file(self):
     # this is not a known configuration so this is ignored.
     config_file_vars = {
         'foo': 'bar',
         CDP_ACCESS_KEY_ID_KEY_NAME: 'key_id',
         CDP_PRIVATE_KEY_KEY_NAME: 'mysecretkey'
     }
     context = FakeContext(
         all_variables={'config_file': '/config/location'},
         config_file_vars=config_file_vars)
     context.context_var_map = {'region': ('region', "CDP_REGION")}
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(rendered,
                              'profile\\s+<not set>\\s+None\\s+None')
     self.assertRegexpMatches(
         rendered, 'cdp_access_key_id\\s+\\*+y_id\\s+config-file')
     self.assertRegexpMatches(rendered,
                              'cdp_private_key\\s+\\*+tkey\\s+config-file')
Exemple #2
0
 def test_no_generate_json_skeleton(self):
     parsed_args = FakeArgs(generate_cli_skeleton=False)
     with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
         rc = self.argument._generate_json_skeleton(parsed_args=parsed_args)
         # Ensure nothing is printed to standard output
         self.assertEqual('', mock_stdout.getvalue())
         # Ensure True is returned because it was never called.
         self.assertEqual(rc, True)
Exemple #3
0
 def test_configure_get_command(self):
     context = FakeContext({})
     context.config['region'] = 'us-west-2'
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['region'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'us-west-2')
Exemple #4
0
 def test_dotted_get(self):
     context = FakeContext({})
     context.full_config = {'preview': {'foo': 'true'}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['preview.foo'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'true')
Exemple #5
0
 def test_generate_json_skeleton(self):
     parsed_args = mock.Mock()
     parsed_args.generate_cli_skeleton = True
     with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
         rc = self.argument._generate_json_skeleton(parsed_args=parsed_args)
         # Ensure the contents printed to standard output are correct.
         self.assertEqual(self.ref_json_output, mock_stdout.getvalue())
         # Ensure it is the correct return code of zero.
         self.assertEqual(rc, 0)
 def setUp(self):
     styler = Styler()
     self.table = MultiTable(initial_section=False,
                             column_separator='|',
                             styler=styler,
                             auto_reformat=False)
     self.formatter = TableFormatter(Object(color='off'))
     self.formatter.table = self.table
     self.stream = six.StringIO()
Exemple #7
0
 def test_get_nested_attribute_from_default_does_not_exist(self):
     context = FakeContext({})
     context.full_config = {'profiles': {}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['default.s3.signature_version'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), '')
Exemple #8
0
 def test_get_from_profile(self):
     context = FakeContext({})
     context.full_config = \
         {'profiles': {'testing': {'cdp_access_key_id': 'access_key'}}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['profile.testing.cdp_access_key_id'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'access_key')
Exemple #9
0
 def test_configure_get_command_no_exist(self):
     no_vars_defined = {}
     context = FakeContext(no_vars_defined)
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     rc = config_get(context, args=['region'], parsed_globals=None)
     rendered = stream.getvalue()
     # If a config value does not exist, we don't print any output.
     self.assertEqual(rendered, '')
     # And we exit with an rc of 1.
     self.assertEqual(rc, 1)
Exemple #10
0
 def test_generate_json_skeleton_no_input_shape(self):
     parsed_args = FakeArgs(generate_cli_skeleton=True)
     # Set the input shape to ``None``.
     self.argument = GenerateCliSkeletonArgument(
         mock.Mock(input_shape=None))
     with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
         rc = self.argument._generate_json_skeleton(parsed_args=parsed_args)
         # Ensure the contents printed to standard output are correct,
         # which should be an empty dictionary.
         self.assertEqual('{}\n', mock_stdout.getvalue())
         # Ensure False is returned because it was called.
         self.assertEqual(rc, False)
Exemple #11
0
 def test_dotted_not_in_full_config_get(self):
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'dev': {
                 'someconf': {
                     'foobar': 'true'
                 }
             }
         }
     }
     stream = six.StringIO()
     context.variables['profile'] = 'dev'
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['someconf.foobar'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'true')
Exemple #12
0
 def test_get_nested_attribute(self):
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'testing': {
                 's3': {
                     'signature_version': 's3v4'
                 }
             }
         }
     }
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['profile.testing.s3.signature_version'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 's3v4')
Exemple #13
0
 def test_configure_list_command_nothing_set(self):
     # Test the case where the user only wants to change a single_value.
     context = FakeContext(
         all_variables={'config_file': '/config/location'})
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(rendered, 'profile\\s+<not set>')
     self.assertRegexpMatches(rendered, 'cdp_access_key_id\\s+<not set>')
     self.assertRegexpMatches(rendered, 'cdp_private_key\\s+<not set>')
Exemple #14
0
 def test_dotted_get_with_profile(self):
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'thu-dev': {
                 'thu': {
                     'instance_profile': 'my_ip'
                 }
             }
         }
     }
     context.config = {'thu': {'instance_profile': 'my_ip'}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['thu-dev.thu.instance_profile'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'my_ip')
Exemple #15
0
 def test_configure_from_env(self):
     env_vars = {'profile': 'myprofilename'}
     context = FakeContext(
         all_variables={'config_file': '/config/location'},
         environment_vars=env_vars)
     context.context_var_map = {'profile': (None, "PROFILE_ENV_VAR")}
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(
         rendered, 'profile\\s+myprofilename\\s+env\\s+PROFILE_ENV_VAR')
Exemple #16
0
 def test_predefined_section_with_profile(self):
     # Test that we retrieve the predefined section config var even if it's
     # under a profile.
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'thu-dev': {
                 'thu': {
                     'instance_profile': 'my_ip'
                 }
             },
             'preview': {
                 'foo': 'true'
             }
         }
     }
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['preview.foo'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'true')
Exemple #17
0
 def test_configure_from_multiple_sources(self):
     # Here the profile is from an env var, the
     # region is from the config file, and the credentials
     # are from an iam-role.
     env_vars = {'profile': 'myprofilename'}
     credentials = mock.Mock()
     credentials.access_key_id = 'access_key'
     credentials.private_key = 'private_key'
     credentials.method = 'foobar'
     context = FakeContext(
         all_variables={'config_file': '/config/location'},
         environment_vars=env_vars,
         config_file_vars={},
         credentials=credentials)
     context.context_var_map = {
         'region': ('region', 'CDP_REGION'),
         'profile': ('profile', 'CDP_DEFAULT_PROFILE')
     }
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     # The profile came from an env var.
     self.assertRegexpMatches(
         rendered, 'profile\\s+myprofilename\\s+env\\s+CDP_DEFAULT_PROFILE')
     # The credentials came from 'foobar'.  Note how we're
     # also checking that the access_key/private_key are masked
     # with '*' chars except for the last 4 chars.
     self.assertRegexpMatches(rendered,
                              r'cdp_access_key_id\s+\*+_key\s+foobar')
     self.assertRegexpMatches(rendered,
                              r'cdp_private_key\s+\*+_key\s+foobar')
Exemple #18
0
 def setUp(self):
     self.input_patch = mock.patch('cdpcli.compat.raw_input')
     self.mock_raw_input = self.input_patch.start()
     self.stdout = six.StringIO()
     self.stdout_patch = mock.patch('sys.stdout', self.stdout)
     self.stdout_patch.start()