Beispiel #1
0
def test_jina_workspace():
    uid = random_uuid()
    assert 'JINA_LOG_WORKSPACE' not in os.environ
    assert not os.path.exists(get_workspace_path(uid))
    with jina_workspace(uid):
        assert os.path.exists(get_workspace_path(uid))
        assert get_workspace_path(uid) in os.getcwd()
        assert 'JINA_LOG_WORKSPACE' in os.environ
        assert os.environ['JINA_LOG_WORKSPACE'] in os.getcwd()

    assert 'JINA_LOG_WORKSPACE' not in os.environ
Beispiel #2
0
def test_upload_then_add_success(api, workspace, fastapi_client):
    # Upload files to workspace
    response = fastapi_client.post('/workspaces',
                                   files=[('files',
                                           open(str(cur_dir / d), 'rb'))
                                          for d in deps])
    assert response.status_code == 201
    workspace_id = response.json()
    assert os.path.exists(get_workspace_path(workspace_id))
    for d in deps:
        assert os.path.exists(get_workspace_path(workspace_id, d))

    # Create a Pea/Pod
    response = fastapi_client.post(api,
                                   json={
                                       'uses': 'mwu_encoder.yml',
                                       'workspace_id': workspace_id
                                   })
    assert response.status_code == 201
    _id = response.json()

    # Fetch all Peas/Pods
    response = fastapi_client.get(api)
    assert response.status_code == 200
    assert response.json()['size'] == 1

    # Fetch the Pea/Pod ID
    response = fastapi_client.get(f'{api}/{_id}')
    assert response.status_code == 200
    assert 'time_created' in response.json()
    workdir = response.json()['workdir']
    assert os.path.exists(workdir)
    for d in deps:
        assert os.path.exists(os.path.join(workdir, d))

    # Delete the Pea/Pod along with the workspace parameter.
    # If workspace=True, this should delete all files in workspace except logging.log
    # If workspace=False, this shouldn't delete anything from the workspace
    response = fastapi_client.delete(f'{api}/{_id}?workspace={str(workspace)}')
    assert response.status_code == 200
    if workspace:
        for d in deps:
            if d == 'logging.log':
                assert os.path.exists(os.path.join(workdir, d))
            else:
                assert not os.path.exists(os.path.join(workdir, d))
    else:
        for d in deps:
            assert os.path.exists(os.path.join(workdir, d))

    # Fetch all Peas/Pods & check for
    response = fastapi_client.get(api)
    assert response.status_code == 200
    assert response.json()['size'] == 0
Beispiel #3
0
def test_post_and_delete_workspace(fastapi_client):
    response = fastapi_client.post('/workspaces',
                                   files=[('files',
                                           open(str(cur_dir / d), 'rb'))
                                          for d in deps])
    assert response.status_code == 201
    workspace_id = response.json()
    assert os.path.exists(get_workspace_path(workspace_id))
    for d in deps:
        assert os.path.exists(get_workspace_path(workspace_id, d))

    response = fastapi_client.delete(f'/workspaces/{workspace_id}')
    assert response.status_code == 200
    assert not os.path.exists(get_workspace_path(workspace_id))
Beispiel #4
0
def test_upload(fastapi_client):
    response = fastapi_client.post(
        '/workspaces', files=[('files', open(str(cur_dir / d), 'rb')) for d in deps]
    )
    assert response.status_code == 201
    for d in deps:
        os.path.exists(get_workspace_path(response.json(), d))
Beispiel #5
0
def test_upload_then_add_success(api, payload, fastapi_client):
    response = fastapi_client.post('/workspaces',
                                   files=[('files',
                                           open(str(cur_dir / d), 'rb'))
                                          for d in deps])
    assert response.status_code == 201
    workspace_id = response.json()
    assert os.path.exists(get_workspace_path(workspace_id))
    for d in deps:
        assert os.path.exists(get_workspace_path(workspace_id, d))

    response = fastapi_client.post(api,
                                   json={
                                       'uses': 'mwu_encoder.yml',
                                       'workspace_id': workspace_id,
                                   })
    assert response.status_code == 201
    _id = response.json()

    response = fastapi_client.get(api)
    assert response.status_code == 200
    assert response.json()['size'] == 1

    response = fastapi_client.get(f'{api}/{_id}')
    assert response.status_code == 200
    assert 'time_created' in response.json()
    workdir = response.json()['workdir']
    assert os.path.exists(workdir)
    for d in deps:
        assert os.path.exists(os.path.join(workdir, d))

    response = fastapi_client.delete(f'{api}/{_id}')

    assert response.status_code == 200

    response = fastapi_client.get(api)
    assert response.status_code == 200
    assert response.json()['size'] == 0
    assert not os.path.exists(workdir)
Beispiel #6
0
def setup_module():
    print('setup', get_workspace_path(workspace_id, flow_id))
    os.makedirs(get_workspace_path(workspace_id, flow_id), exist_ok=True)
    _write_to_logfile(log_content)
Beispiel #7
0
def _write_to_logfile(content, append=False):
    with open(
            get_workspace_path(workspace_id, flow_id, 'logging.log'),
            'a' if append else 'w+',
    ) as f:
        f.writelines(content)
Beispiel #8
0
def test_workspace_path():
    uid = random_uuid()
    assert get_workspace_path(uid) == f'{jinad_args.workspace}/{uid}'
    assert get_workspace_path('123',
                              '456') == f'{jinad_args.workspace}/123/456'