Esempio n. 1
0
 def test_load_config_io_error(self):
     s = Settings(operation=ListOperation('gid', []),
                  options=self._updated_opts({
                      'config':
                      'tests/resources/test-artifact-cli.conf_no_such_file'
                  }))
     self.assertEqual(s.load_config(), Settings())
Esempio n. 2
0
 def test_parse_args_upload(self):
     s = Settings().parse_args(['art', 'upload', 'gid', '/path/to/xxx'])
     self.assertEqual(
         s,
         Settings(operation=UploadOperation('gid', ['/path/to/xxx'], False,
                                            False),
                  options=self.default_opts))
Esempio n. 3
0
    def test_parse_args_info(self):
        s = Settings().parse_args(['art', 'info', 'gid', 'xxx', '123'])
        self.assertEqual(s, Settings(operation=InfoOperation('gid', ['xxx', '123'], None), options=self.default_opts))

        s = Settings().parse_args(['art', 'info', 'gid', 'xxx', 'latest'])
        self.assertEqual(s, Settings(operation=InfoOperation('gid', ['xxx', 'latest'], None),
                                     options=self.default_opts))
Esempio n. 4
0
    def test_parse_args_download(self):
        s = Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', '123'])
        self.assertEqual(s, Settings(operation=DownloadOperation('gid', ['/path/to/xxx', '123'], False),
                                     options=self.default_opts))

        s = Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', 'latest'])
        self.assertEqual(s, Settings(operation=DownloadOperation('gid', ['/path/to/xxx', 'latest'], False),
                                     options=self.default_opts))
Esempio n. 5
0
 def test_parse_args_download_error(self):
     self.assertEqual(Settings().parse_args(['art', 'download']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', '']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', 'a']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', 'abc']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', '1.0']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'download', 'gid', '/path/to/xxx', 'LATEST']), Settings())
Esempio n. 6
0
 def test_parse_args_list_full(self):
     s = Settings().parse_args([
         'art', 'list', 'gid', '--config', 'xxx', '--check', '--force',
         '--access', 'ACCESS_KEY', '--secret', 'SECRET_KEY', '--bucket',
         'BUCKET', '--debug'
     ])
     self.assertEqual(
         s,
         Settings(operation=ListOperation('gid', []),
                  options=self.full_opts))
Esempio n. 7
0
 def test_load_config_ok(self):
     s = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts({'config': 'tests/resources/test-artifact-cli.conf', 'bucket': 'bucket4art'}))
     t = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts({'config': 'tests/resources/test-artifact-cli.conf', 'bucket': 'bucket4art'}),
         repo=Repository(S3Driver('XXX', 'YYY', 'bucket4art', 'gid'), 'gid')
     )
     self.assertEqual(s.load_config(), t)
Esempio n. 8
0
 def test_load_config_ok(self):
     s = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts({'config': 'tests/resources/test-artifact-cli.conf', 'bucket': 'bucket4art'}))
     t = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts({'config': 'tests/resources/test-artifact-cli.conf', 'bucket': 'bucket4art'}),
         repo=Repository(S3Driver('XXX', 'YYY', 'bucket4art', 'gid'), 'gid')
     )
     self.assertEqual(s.load_config(), t)
Esempio n. 9
0
 def test_parse_args_upload_full(self):
     s = Settings().parse_args([
         'art', 'upload', 'gid', '/path/to/xxx', '--config', 'xxx',
         '--check', '--force', '--access', 'ACCESS_KEY', '--secret',
         'SECRET_KEY', '--bucket', 'BUCKET', '--debug'
     ])
     self.assertEqual(
         s,
         Settings(operation=UploadOperation('gid', ['/path/to/xxx'], True,
                                            True),
                  options=self.full_opts))
Esempio n. 10
0
 def test_load_config_enough(self):
     s = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts(
             {'access_key': 'ACCESS_KEY', 'secret_key': 'SECRET_KEY', 'bucket': 'BUCKET'})
     )
     t = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts(
             {'access_key': 'ACCESS_KEY', 'secret_key': 'SECRET_KEY', 'bucket': 'BUCKET'}),
         repo=Repository(S3Driver('ACCESS_KEY', 'SECRET_KEY', 'BUCKET', 'gid'), 'gid')
     )
     self.assertEqual(s.load_config(), t)
Esempio n. 11
0
 def test_load_config_enough(self):
     s = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts(
             {'access_key': 'ACCESS_KEY', 'secret_key': 'SECRET_KEY', 'bucket': 'BUCKET'})
     )
     t = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts(
             {'access_key': 'ACCESS_KEY', 'secret_key': 'SECRET_KEY', 'bucket': 'BUCKET'}),
         repo=Repository(S3Driver('ACCESS_KEY', 'SECRET_KEY', 'BUCKET', 'gid'), 'gid')
     )
     self.assertEqual(s.load_config(), t)
Esempio n. 12
0
 def test_load_environ_already_set(self):
     opt = {'access_key': 'ACCESS_KEY', 'secret_key': 'SECRET_KEY', 'region': "us-east-1"}
     env = {
         'AWS_ACCESS_KEY_ID': 'AKIAIOSFODNN7EXAMPLE',
         'AWS_SECRET_ACCESS_KEY': 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
         'AWS_DEFAULT_REGION': 'us-west-2'
     }
     exp = {
         'access_key': 'ACCESS_KEY',
         'secret_key': 'SECRET_KEY',
         'region': 'us-east-1'
     }
     ret = Settings(options=opt).load_environ(env)
     self.assertEqual(ret, Settings(options=exp))
Esempio n. 13
0
 def test_load_environ_mixed(self):
     opt = {'access_key': 'ACCESS_KEY', 'region': "us-east-1"}
     env = {
         'AWS_ACCESS_KEY_ID': 'AKIAIOSFODNN7EXAMPLE',
         'AWS_SECRET_ACCESS_KEY': 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
         'XXX': 123,
         'YYY': 456
     }
     exp = {
         'access_key': 'ACCESS_KEY',
         'secret_key': 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
         'region': 'us-east-1'
     }
     ret = Settings(options=opt).load_environ(env)
     self.assertEqual(ret, Settings(options=exp))
Esempio n. 14
0
 def test_read_aws_config_default_full(self):
     s = StringIO('\n'.join([
         '[default]',
         'aws_access_key_id = abcdefghijklmnopqrstuvwxyz',
         'aws_secret_access_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
         'bucket = bucket-name',
         'region= ap-northeast-1',
     ]))
     self.assertEqual(Settings._read_aws_config(s, 'mogproject'),
                      ('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'bucket-name', 'ap-northeast-1'))
Esempio n. 15
0
 def test_parse_args_unknown_option(self):
     try:
         Settings().parse_args(['art', '-x'])
     except SystemExit as e:
         self.assertEqual(type(e), type(SystemExit()))
         self.assertEqual(e.code, 2)
     except Exception as e:
         self.fail('unexpected exception: %s' % e)
     else:
         self.fail('SystemExit exception expected')
Esempio n. 16
0
 def test_read_aws_config_default_full(self):
     s = StringIO('\n'.join([
         '[default]',
         'aws_access_key_id = abcdefghijklmnopqrstuvwxyz',
         'aws_secret_access_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
         'bucket = bucket-name',
         'region= ap-northeast-1',
     ]))
     self.assertEqual(Settings._read_aws_config(s, 'mogproject'),
                      ('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'bucket-name', 'ap-northeast-1'))
Esempio n. 17
0
    def test_parse_args_info_full(self):
        s = Settings().parse_args([
            'art', 'info', 'gid', 'xxx', '123', '--config', 'xxx', '--check',
            '--force', '--access', 'ACCESS_KEY', '--secret', 'SECRET_KEY',
            '--bucket', 'BUCKET', '--output', 'text', '--debug'
        ])
        o = self._updated_opts({
            'access_key': 'ACCESS_KEY',
            'force': True,
            'bucket': 'BUCKET',
            'print_only': True,
            'secret_key': 'SECRET_KEY',
            'config': 'xxx',
            'output': 'text',
            'log_level': logging.DEBUG
        })
        self.assertEqual(
            s,
            Settings(operation=InfoOperation('gid', ['xxx', '123'], 'text'),
                     options=o))

        s = Settings().parse_args([
            'art', 'info', 'gid', 'xxx', 'latest', '--config', 'xxx',
            '--check', '--force', '--access', 'ACCESS_KEY', '--secret',
            'SECRET_KEY', '--bucket', 'BUCKET', '--debug'
        ])
        o = self._updated_opts({
            'access_key': 'ACCESS_KEY',
            'force': True,
            'bucket': 'BUCKET',
            'print_only': True,
            'secret_key': 'SECRET_KEY',
            'config': 'xxx',
            'output': None,
            'log_level': logging.DEBUG
        })
        self.assertEqual(
            s,
            Settings(operation=InfoOperation('gid', ['xxx', 'latest'], None),
                     options=o))

        s = Settings().parse_args([
            'art', 'info', 'gid', 'xxx', 'latest', '--config', 'xxx',
            '--check', '--force', '--access', 'ACCESS_KEY', '--secret',
            'SECRET_KEY', '--bucket', 'BUCKET', '--output', 'json', '--debug'
        ])
        o = self._updated_opts({
            'access_key': 'ACCESS_KEY',
            'force': True,
            'bucket': 'BUCKET',
            'print_only': True,
            'secret_key': 'SECRET_KEY',
            'config': 'xxx',
            'output': 'json',
            'log_level': logging.DEBUG
        })
        self.assertEqual(
            s,
            Settings(operation=InfoOperation('gid', ['xxx', 'latest'], 'json'),
                     options=o))
Esempio n. 18
0
 def test_read_config_fallback(self):
     s = StringIO('\n'.join([
         '[default]',
         'aws_access_key_id = abcdefghijklmnopqrstuvwxyz',
         'aws_secret_access_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
         'bucket = bucket-name',
         '[my.group.id]',
         'aws_access_key_id = zyxwvutsrqponmlkjihgfedcba',
         'aws_secret_access_key=ZYXWVUTSRQPONMLKJIHGFEDCBA',
         'bucket = bucket-name-123',
     ]))
     self.assertEqual(Settings._read_aws_config(s, 'mogproject'),
                      ('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'bucket-name', None))
Esempio n. 19
0
 def test_read_config_fallback(self):
     s = StringIO('\n'.join([
         '[default]',
         'aws_access_key_id = abcdefghijklmnopqrstuvwxyz',
         'aws_secret_access_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
         'bucket = bucket-name',
         '[my.group.id]',
         'aws_access_key_id = zyxwvutsrqponmlkjihgfedcba',
         'aws_secret_access_key=ZYXWVUTSRQPONMLKJIHGFEDCBA',
         'bucket = bucket-name-123',
     ]))
     self.assertEqual(Settings._read_aws_config(s, 'mogproject'),
                      ('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'bucket-name', None))
Esempio n. 20
0
 def test_read_aws_config_non_default_full(self):
     s = StringIO('\n'.join([
         '[default]',
         'aws_access_key_id = abcdefghijklmnopqrstuvwxyz',
         'aws_secret_access_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
         'bucket = bucket-name',
         'region= ap-northeast-1',
         '[my.group.id]',
         'aws_access_key_id = zyxwvutsrqponmlkjihgfedcba',
         'aws_secret_access_key=ZYXWVUTSRQPONMLKJIHGFEDCBA',
         'bucket = bucket-name-123',
         'region= us-west-1',
     ]))
     self.assertEqual(Settings._read_aws_config(s, 'my.group.id'),
                      ('zyxwvutsrqponmlkjihgfedcba', 'ZYXWVUTSRQPONMLKJIHGFEDCBA', 'bucket-name-123', 'us-west-1'))
Esempio n. 21
0
 def test_read_aws_config_non_default_full(self):
     s = StringIO('\n'.join([
         '[default]',
         'aws_access_key_id = abcdefghijklmnopqrstuvwxyz',
         'aws_secret_access_key=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
         'bucket = bucket-name',
         'region= ap-northeast-1',
         '[my.group.id]',
         'aws_access_key_id = zyxwvutsrqponmlkjihgfedcba',
         'aws_secret_access_key=ZYXWVUTSRQPONMLKJIHGFEDCBA',
         'bucket = bucket-name-123',
         'region= us-west-1',
     ]))
     self.assertEqual(Settings._read_aws_config(s, 'my.group.id'),
                      ('zyxwvutsrqponmlkjihgfedcba', 'ZYXWVUTSRQPONMLKJIHGFEDCBA', 'bucket-name-123', 'us-west-1'))
Esempio n. 22
0
 def test_load_config_missing(self):
     s = Settings(
         operation=ListOperation('gid', []),
         options=self._updated_opts({'config': 'tests/resources/test-artifact-cli.conf'}))
     self.assertEqual(s.load_config(), Settings())
Esempio n. 23
0
 def test_parse_args_upload_error(self):
     self.assertEqual(Settings().parse_args(['art', 'upload']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'upload', 'gid']),
                      Settings())
Esempio n. 24
0
 def test_load_environ_none(self):
     ret = Settings().load_environ({})
     self.assertEqual(ret, Settings())
Esempio n. 25
0
 def test_parse_args_delete_error(self):
     self.assertEqual(Settings().parse_args(['art', 'delete']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'delete', 'gid']),
                      Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx']), Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx', '']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx', 'a']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx', 'abc']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx', '1.0']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx', 'latest']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'delete', 'gid', 'xxx', 'LATEST']),
         Settings())
Esempio n. 26
0
 def test_read_aws_config_default_some(self):
     s = StringIO("""[default]\naws_access_key_id = abcdefghijklmnopqrstuvwxyz""")
     self.assertEqual(Settings._read_aws_config(s, 'mogproject'),
                      ('abcdefghijklmnopqrstuvwxyz', None, None, None))
Esempio n. 27
0
 def test_parse_args_delete(self):
     s = Settings().parse_args(['art', 'delete', 'gid', 'xxx', '123'])
     self.assertEqual(
         s,
         Settings(operation=DeleteOperation('gid', ['xxx', '123'], False),
                  options=self.default_opts))
Esempio n. 28
0
 def test_parse_args_list(self):
     s = Settings().parse_args(['art', 'list', 'gid'])
     self.assertEqual(
         s,
         Settings(operation=ListOperation('gid', []),
                  options=self.default_opts))
Esempio n. 29
0
 def test_read_aws_config_default_some(self):
     s = StringIO(
         """[default]\naws_access_key_id = abcdefghijklmnopqrstuvwxyz""")
     self.assertEqual(Settings._read_aws_config(s, 'mogproject'),
                      ('abcdefghijklmnopqrstuvwxyz', None, None, None))
Esempio n. 30
0
 def test_read_aws_config_empty(self):
     s = StringIO('')
     self.assertEqual(Settings._read_aws_config(s, ''),
                      (None, None, None, None))
Esempio n. 31
0
 def test_load_config_attribute_error(self):
     s = Settings(options=self.default_opts)
     self.assertEqual(s.load_config(), Settings())
Esempio n. 32
0
 def test_parse_args_empty(self):
     self.assertEqual(Settings().parse_args(['art']), Settings())
Esempio n. 33
0
 def test_load_config_attribute_error(self):
     s = Settings(options=self.default_opts)
     self.assertEqual(s.load_config(), Settings())
Esempio n. 34
0
 def test_read_aws_config_empty(self):
     s = StringIO('')
     self.assertEqual(Settings._read_aws_config(s, ''), (None, None, None, None))
Esempio n. 35
0
 def test_parse_args_unknown_option(self):
     try:
         Settings().parse_args(['art', '-x'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 2)
Esempio n. 36
0
 def test_parse_args_list_error(self):
     self.assertEqual(Settings().parse_args(['art', 'list']), Settings())
Esempio n. 37
0
 def test_load_config_none(self):
     ret = Settings().load_config()
     self.assertEqual(ret, Settings())
Esempio n. 38
0
 def test_parse_args_info_error(self):
     self.assertEqual(Settings().parse_args(['art', 'info']), Settings())
     self.assertEqual(Settings().parse_args(['art', 'info', 'gid']),
                      Settings())
     self.assertEqual(Settings().parse_args(['art', 'info', 'gid', 'xxx']),
                      Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'info', 'gid', 'xxx', '']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'info', 'gid', 'xxx', 'a']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'info', 'gid', 'xxx', 'abc']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'info', 'gid', 'xxx', '1.0']),
         Settings())
     self.assertEqual(
         Settings().parse_args(['art', 'info', 'gid', 'xxx', 'LATEST']),
         Settings())
Esempio n. 39
0
 def test_parse_args_command_error(self):
     self.assertEqual(Settings().parse_args(['art', 'xxx', 'gid']),
                      Settings())