示例#1
0
def test_authorized_users_only():
    session = external_requests_client_session()
    endpoints = [
        (session.get, '/api/v1alpha/billing_projects', 401),
        (session.get, '/api/v1alpha/billing_projects/foo', 401),
        (session.post, '/api/v1alpha/billing_projects/foo/users/foo/add', 401),
        (session.post, '/api/v1alpha/billing_projects/foo/users/foo/remove',
         401),
        (session.post, '/api/v1alpha/billing_projects/foo/create', 401),
        (session.post, '/api/v1alpha/billing_projects/foo/close', 401),
        (session.post, '/api/v1alpha/billing_projects/foo/reopen', 401),
        (session.post, '/api/v1alpha/billing_projects/foo/delete', 401),
        (session.post, '/api/v1alpha/billing_limits/foo/edit', 401),
        (session.get, '/api/v1alpha/batches/0/jobs/0', 401),
        (session.get, '/api/v1alpha/batches/0/jobs/0/log', 401),
        (session.get, '/api/v1alpha/batches', 401),
        (session.post, '/api/v1alpha/batches/create', 401),
        (session.post, '/api/v1alpha/batches/0/jobs/create', 401),
        (session.get, '/api/v1alpha/batches/0', 401),
        (session.delete, '/api/v1alpha/batches/0', 401),
        (session.patch, '/api/v1alpha/batches/0/close', 401),
        # redirect to auth/login
        (session.get, '/batches', 302),
        (session.get, '/batches/0', 302),
        (session.post, '/batches/0/cancel', 401),
        (session.get, '/batches/0/jobs/0', 302),
    ]
    for method, url, expected in endpoints:
        full_url = deploy_config.url('batch', url)
        r = retry_response_returning_functions(method,
                                               full_url,
                                               allow_redirects=False)
        assert r.status_code == expected, (full_url, r, expected)
示例#2
0
    def ping(self):
        ping_url = 'http://{}:{}/ping'.format(self.host, self.port)

        up = False
        session = external_requests_client_session()
        while not up:
            try:
                retry_response_returning_functions(session.get, ping_url)
                up = True
            except requests.exceptions.ConnectionError:
                time.sleep(0.01)
示例#3
0
文件: db.py 项目: TileDB-Inc/hail
 def __init__(self,
              *,
              region: str = 'us',
              cloud: str = 'gcp',
              url: Optional[str] = None,
              config: Optional[dict] = None):
     if region not in DB._valid_regions:
         raise ValueError(f'Specify valid region parameter,'
                          f' received: region={repr(region)}.\n'
                          f'Valid regions are {DB._valid_regions}.')
     if cloud not in DB._valid_clouds:
         raise ValueError(f'Specify valid cloud parameter,'
                          f' received: cloud={repr(cloud)}.\n'
                          f'Valid cloud platforms are {DB._valid_clouds}.')
     if (region, cloud) not in DB._valid_combinations:
         raise ValueError(f'The {repr(region)} region is not available for'
                          f' the {repr(cloud)} cloud platform. '
                          f'Valid region, cloud combinations are'
                          f' {DB._valid_combinations}.')
     if config is not None and url is not None:
         raise ValueError(
             f'Only specify one of the parameters url and'
             f' config, received: url={url} and config={config}')
     if config is None:
         if url is None:
             config_path = pkg_resources.resource_filename(
                 __name__, 'datasets.json')
             assert os.path.exists(config_path), \
                 f'{config_path} does not exist'
             with open(config_path) as f:
                 config = json.load(f)
         else:
             session = external_requests_client_session()
             response = retry_response_returning_functions(session.get, url)
             config = response.json()
         assert isinstance(config, dict)
     else:
         if not isinstance(config, dict):
             raise ValueError(f'expected a dict mapping dataset names to '
                              f'configurations, but found {config}')
     config = {k: v for k, v in config.items() if 'annotation_db' in v}
     self.region = region
     self.cloud = cloud
     self.url = url
     self.config = config
     self.__by_name = {
         k: Dataset.from_name_and_json(k, v, region, cloud)
         for k, v in config.items()
         if Dataset.from_name_and_json(k, v, region, cloud) is not None
     }
示例#4
0
def test_batch_create_validation():
    bad_configs = [
        # unexpected field fleep
        {'billing_project': 'foo', 'n_jobs': 5, 'token': 'baz', 'fleep': 'quam'},
        # billing project None/missing
        {'billing_project': None, 'n_jobs': 5, 'token': 'baz'},
        {'n_jobs': 5, 'token': 'baz'},
        # n_jobs None/missing
        {'billing_project': 'foo', 'n_jobs': None, 'token': 'baz'},
        {'billing_project': 'foo', 'token': 'baz'},
        # n_jobs wrong type
        {'billing_project': 'foo', 'n_jobs': '5', 'token': 'baz'},
        # token None/missing
        {'billing_project': 'foo', 'n_jobs': 5, 'token': None},
        {'billing_project': 'foo', 'n_jobs': 5},
        # attribute key/value None
        {'attributes': {'k': None}, 'billing_project': 'foo', 'n_jobs': 5, 'token': 'baz'},
    ]
    url = deploy_config.url('batch', '/api/v1alpha/batches/create')
    headers = service_auth_headers(deploy_config, 'batch')
    session = external_requests_client_session()
    for config in bad_configs:
        r = retry_response_returning_functions(session.post, url, json=config, allow_redirects=True, headers=headers)
        assert r.status_code == 400, (config, r)