示例#1
0
def test_validation():
    mandatory_args = {'access_key': 'a', 'secret_key': 's'}
    with pytest.raises(ValueError):
        APIConfig(endpoint='/mylocalpath', **mandatory_args)
    cfg = APIConfig(vfolder_mounts='abc', **mandatory_args)
    assert cfg.vfolder_mounts == ('abc', )
    cfg = APIConfig(vfolder_mounts='', **mandatory_args)
    assert cfg.vfolder_mounts == tuple()
    cfg = APIConfig(vfolder_mounts=['abc', 'def'], **mandatory_args)
    assert cfg.vfolder_mounts == ('abc', 'def')
示例#2
0
def test_create_with_config(mocker, api_version):
    mock_req_obj = mock.Mock()
    mock_req_obj.fetch.return_value = AsyncContextMock(status=201,
                                                       json=AsyncMock())
    mock_req = mocker.patch('ai.backend.client.func.session.Request',
                            return_value=mock_req_obj)
    myconfig = APIConfig(
        endpoint='https://localhost:9999',
        access_key='1234',
        secret_key='asdf',
        user_agent='BAIClientTest',
        version=f'v{api_version[0]}.{api_version[1]}',
    )
    with Session(config=myconfig) as session:
        prefix = get_naming(session.api_version, 'path')
        if api_version[0] == 4:
            assert prefix == 'kernel'
        else:
            assert prefix == 'session'
        assert session.config is myconfig
        cs = session.ComputeSession.get_or_create('python')
        mock_req.assert_called_once_with(session, 'POST', f'/{prefix}')
        assert str(cs.session.config.endpoint) == 'https://localhost:9999'
        assert cs.session.config.user_agent == 'BAIClientTest'
        assert cs.session.config.access_key == '1234'
        assert cs.session.config.secret_key == 'asdf'
示例#3
0
def test_set_and_get_config(mocker, cfg_params):
    # Mocking the global variable ``_config``.
    # The value of a global variable will affect other test cases.
    mocker.patch('ai.backend.client.config._config', None)
    cfg = APIConfig(**cfg_params)
    set_config(cfg)
    assert get_config() == cfg
示例#4
0
def defconfig():
    endpoint = os.environ.get('BACKEND_TEST_ENDPOINT', 'http://127.0.0.1:8081')
    access_key = os.environ.get('BACKEND_TEST_ADMIN_ACCESS_KEY',
                                'AKIAIOSFODNN7EXAMPLE')
    secret_key = os.environ.get('BACKEND_TEST_ADMIN_SECRET_KEY',
                                'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY')
    c = APIConfig(endpoint=endpoint,
                  access_key=access_key,
                  secret_key=secret_key)
    set_config(c)
    return c
示例#5
0
def userconfig():
    endpoint = os.environ.get('BACKEND_TEST_ENDPOINT', 'http://127.0.0.1:8081')
    access_key = os.environ.get('BACKEND_TEST_USER_ACCESS_KEY',
                                'AKIANABBDUSEREXAMPLE')
    secret_key = os.environ.get('BACKEND_TEST_USER_SECRET_KEY',
                                'C8qnIo29EZvXkPK_MXcuAakYTy4NYrxwmCEyNPlf')
    c = APIConfig(endpoint=endpoint,
                  access_key=access_key,
                  secret_key=secret_key)
    set_config(c)
    return c
def test_api_config_initialization(cfg_params):
    params = cfg_params
    cfg = APIConfig(**params)

    assert cfg.endpoint == params['endpoint']
    assert cfg.version == params['version']
    assert cfg.user_agent == params['user_agent']
    assert cfg.access_key == params['access_key']
    assert cfg.secret_key == params['secret_key']
    assert cfg.hash_type == params['hash_type']

    assert isinstance(cfg.endpoint, str)
    assert isinstance(cfg.version, str)
    assert isinstance(cfg.user_agent, str)
    assert isinstance(cfg.access_key, str)
    assert isinstance(cfg.secret_key, str)
    assert isinstance(cfg.hash_type, str)
示例#7
0
    def test_create_with_config(self, mocker):
        mock_req_obj = mock.Mock()
        mock_req_obj.fetch.return_value = ContextMagicMock(
            status=201, json=asynctest.CoroutineMock())
        mock_req = mocker.patch('ai.backend.client.kernel.Request',
                                return_value=mock_req_obj)

        myconfig = APIConfig(endpoint='https://localhost:9999',
                             access_key='1234',
                             secret_key='asdf',
                             user_agent='BAIClientTest')
        with Session(config=myconfig) as session:
            assert session.config is myconfig
            k = session.Kernel.get_or_create('python')
            mock_req.assert_called_once_with(session, 'POST', '/kernel/create')
            assert str(k.session.config.endpoint) == 'https://localhost:9999'
            assert k.session.config.user_agent == 'BAIClientTest'
            assert k.session.config.access_key == '1234'
            assert k.session.config.secret_key == 'asdf'
示例#8
0
    def test_api_config_initialization(self, cfg_params):
        params = cfg_params
        cfg = APIConfig(**params)

        assert str(cfg.endpoint) == params['endpoint']
        assert str(cfg.endpoint) == params['endpoint']
        assert cfg.user_agent == params['user_agent']
        assert cfg.access_key == params['access_key']
        assert cfg.secret_key == params['secret_key']
        assert cfg.version == params['version']
        assert cfg.hash_type == params['hash_type']
        assert set(cfg.vfolder_mounts) == set(params['vfolder_mounts'])

        assert isinstance(cfg.endpoint, URL)
        assert isinstance(cfg.version, str)
        assert isinstance(cfg.user_agent, str)
        assert isinstance(cfg.access_key, str)
        assert isinstance(cfg.secret_key, str)
        assert isinstance(cfg.hash_type, str)
        assert isinstance(cfg.vfolder_mounts, list)
示例#9
0
def defconfig():
    c = APIConfig(endpoint='http://127.0.0.1:8081',
                  access_key='AKIAIOSFODNN7EXAMPLE',
                  secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY')
    set_config(c)
    return c
def intgr_config():
    return APIConfig(
        # endpoint='http://localhost:8081',
        access_key='AKIAIOSFODNN7EXAMPLE',
        secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
    )