Пример #1
0
 def test_api_url(self):
     plain_config = random_config()
     api_url = os.environ.get('ABEJA_API_URL', 'https://api.dev.abeja.io')
     config = Config(**plain_config, api_url=api_url)
     assert config.api_url == api_url
     d = config.asdict()
     assert d['abeja-api-url'] == config.api_url
Пример #2
0
 def test_contains(self, config_set):
     assert 'A' not in config_set
     config_set.add(Config(**random_config(), name='A'))
     assert 'A' in config_set
     config_set.add(Config(**random_config(), name='B'))
     assert 'B' in config_set
     config_set.add(Config(**random_config()))
     assert None in config_set
Пример #3
0
    def test_remove(self, config_set):
        config_set.add(Config(**random_config()))
        config_set.add(Config(**random_config(), name='A'))
        config_set.add(Config(**random_config(), name='B'))

        config_set.remove('A')
        assert 'A' not in config_set
        config_set.remove('B')
        assert 'B' not in config_set
        config_set.remove(None)
        assert None not in config_set
        with pytest.raises(KeyError):
            config_set.remove('C')
Пример #4
0
    def test_without_env(self):
        plain_config = random_config()
        config = Config(**plain_config)

        assert config.name is None
        assert config.user == ('user-' + plain_config['user'])
        assert config.token == plain_config['token']
        assert config.organization == plain_config['organization']
        assert config.asdict() == {
            'abeja-platform-user': plain_config['user'],
            'personal-access-token': plain_config['token'],
            'organization-name': plain_config['organization']
        }
Пример #5
0
    def test_with_environ(self, fake_environ):
        with mock.patch.dict(os.environ, fake_environ):
            plain_config = random_config()
            config = Config(**plain_config)

            assert config.name is None
            assert config.user == fake_environ['ABEJA_CLI_USER']
            assert config.token == fake_environ['ABEJA_CLI_TOKEN']
            assert config.organization == fake_environ[
                'ABEJA_CLI_ORGANIZATION']
            assert config.asdict() == {
                'abeja-platform-user': plain_config['user'],
                'personal-access-token': plain_config['token'],
                'organization-name': plain_config['organization']
            }
Пример #6
0
    def test_activation(self, config_set):
        assert config_set.active_config_name is None
        with pytest.raises(KeyError):
            config_set.active_config_name = 'A'

        config_set.add(Config(**random_config()))
        config_set.active_config_name = None
        assert config_set.active_config_name is None
        assert config_set.active_config
        assert config_set.active_config.name is None

        config_set.add(Config(**random_config(), name='A'))
        config_set.active_config_name = 'A'
        assert config_set.active_config_name == 'A'
        assert config_set.active_config
        assert config_set.active_config.name == 'A'
Пример #7
0
    def test_iter(self, config_set):
        assert len(list(config_set)) == 0

        config_set.add(Config(**random_config(), name='A'))
        for c in config_set:
            assert c.name == 'A'

        config_set.add(Config(**random_config(), name='B'))
        config_set.add(Config(**random_config(), name='C'))

        # order must be preserved
        it = iter(config_set)
        assert it.__next__().name == 'A'
        assert it.__next__().name == 'B'
        assert it.__next__().name == 'C'
        with pytest.raises(StopIteration):
            it.__next__()
Пример #8
0
    def test_with_environ_platform_auth_token(self, fake_environ_auth_token):
        with mock.patch.dict(os.environ, fake_environ_auth_token):
            config = Config(None, None, None)

            assert config
            assert config.name is None
            assert config.user is None
            assert config.token is None
            assert config.organization == fake_environ_auth_token[
                'ABEJA_CLI_ORGANIZATION']
            assert config.platform_auth_token == fake_environ_auth_token[
                'PLATFORM_AUTH_TOKEN']
            assert config.asdict() == {
                'abeja-platform-user': None,
                'personal-access-token': None,
                'organization-name': None
            }
Пример #9
0
    def test_with_environ_deprecated(self, fake_environ_deprecated):
        with mock.patch.dict(os.environ, fake_environ_deprecated):
            plain_config = random_config()
            config = Config(**plain_config)

            assert config
            assert config.name is None
            assert config.user == fake_environ_deprecated[
                'ABEJA_PLATFORM_USER']
            assert config.token == fake_environ_deprecated[
                'PERSONAL_ACCESS_TOKEN']
            assert config.organization == fake_environ_deprecated[
                'ORGANIZATION_NAME']
            assert config.asdict() == {
                'abeja-platform-user': plain_config['user'],
                'personal-access-token': plain_config['token'],
                'organization-name': plain_config['organization']
            }
Пример #10
0
    def test_get_item(self, config_set):
        with pytest.raises(KeyError):
            config_set['A']

        config1 = Config(**random_config(), name='A')
        config_set.add(config1)
        assert config_set['A'] == config1
        with pytest.raises(KeyError):
            config_set['B']
Пример #11
0
    def test_build_config_wo_user_prefix(self, plain_config_without_user_prefix):
        loader = ConfigSetLoader()
        config = loader.build_config(plain_config_without_user_prefix)

        assert config
        assert config.name is None
        assert config.user == Config.prefixed_user(
            plain_config_without_user_prefix['abeja-platform-user'])
        assert config.token == plain_config_without_user_prefix['personal-access-token']
        assert config.organization == plain_config_without_user_prefix['organization-name']
Пример #12
0
    def build_config(self, plain_config: Dict[str, str]) -> Config:
        name = plain_config.get('configuration-name')
        user = plain_config.get('abeja-platform-user')
        token = plain_config.get('personal-access-token')
        organization = plain_config.get('organization-name')
        api_url = plain_config.get('abeja-api-url')

        config = Config(user=user,
                        token=token,
                        organization=organization,
                        api_url=api_url,
                        name=name)

        if config.organization is None:
            raise InvalidConfigException(
                'missing config value: {}'.format('organization-name'))
        if (config.user is None or
                config.token is None) and config.platform_auth_token is None:
            raise InvalidConfigException(
                'missing config value: {} or {}'.format(
                    'abeja-platform-user', 'personal-access-token'))

        return config
Пример #13
0
    create_job_definition, create_training_job, create_training_model,
    create_training_version, describe_jobs, describe_training_models,
    describe_training_versions, download_training_model, initialize_training,
    unarchive_job, unarchive_training_model, unarchive_version,
    update_training_model)
from tests import get_tmp_training_file_name
from tests.unit import ConfigPatcher

TEST_CONFIG_FILE_ROOT = '/tmp/.abeja'
TEST_CONFIG_FILE_PATH = os.path.join(TEST_CONFIG_FILE_ROOT, 'config')

TEST_CONFIG_USER_ID = '12345'
TEST_CONFIG_TOKEN = 'ntoken12345'
TEST_CONFIG_ORG_NAME = 'test-inc'
TEST_CONFIG = {
    'abeja-platform-user': Config.prefixed_user(TEST_CONFIG_USER_ID),
    'personal-access-token': TEST_CONFIG_TOKEN,
    'organization-name': TEST_CONFIG_ORG_NAME
}

TEST_CONFIG_USER_ID_2 = '2039587479106'
TEST_CONFIG_TOKEN_2 = '34676abf4875998fbe7fd4637'
TEST_CONFIG_ORG_NAME_2 = 'banana-fish'
TEST_CONFIG_2 = {
    'abeja-platform-user': Config.prefixed_user(TEST_CONFIG_USER_ID_2),
    'personal-access-token': TEST_CONFIG_TOKEN_2,
    'organization-name': TEST_CONFIG_ORG_NAME_2
}

TEST_ORGANIZATION_DOMAIN = 'http://apidomain/organizations/test'
yaml = YAML()
Пример #14
0
 def add(self, *args, **kwargs):
     self.config_set.add(Config(*args, **kwargs))
     return self
Пример #15
0
 def test_len(self, config_set):
     assert len(config_set) == 0
     config_set.add(Config(**random_config(), name='A'))
     assert len(config_set) == 1
     config_set.add(Config(**random_config(), name='B'))
     assert len(config_set) == 2
Пример #16
0
def config():
    return Config(user='******',
                  token='1935793145984317957049835709',
                  organization='abeja-inc')
Пример #17
0
 def test_name(self):
     plain_config = random_config()
     config = Config(**plain_config, name='A')
     assert config.name == 'A'
     d = config.asdict()
     assert d['configuration-name'] == config.name
Пример #18
0
 def test_get(self, config_set):
     assert not config_set.get('A')
     config1 = Config(**random_config(), name='A')
     config_set.add(config1)
     assert config_set.get('A') == config1
     assert config_set.get('B') is None
Пример #19
0
 def test_unnamed_config(self, config_set):
     config = Config(**random_config())
     config_set.add(config)
     assert len(config_set) == 1
     assert config_set.get(None) == config