Exemplo n.º 1
0
def client(host, port, email, dev_key):
    client = Client(host, port, email, dev_key)

    yield client

    if client.proj is not None:
        utils.delete_project(client.proj.id, client._conn)
Exemplo n.º 2
0
    def test_no_auth(self, host):
        client = verta.Client(host)

        # it's just been revoked
        client._conn.auth = None

        assert client.set_project()
        utils.delete_project(client.proj.id, client._conn)
Exemplo n.º 3
0
    def test_config_file(self):
        PROJECT_NAME = "test_project"
        DATASET_NAME = "test_dataset"
        EXPERIMENT_NAME = "test_experiment"
        CONFIG_FILENAME = "verta_config.json"

        HOST = "app.verta.ai"
        EMAIL_KEY, DEV_KEY_KEY = "VERTA_EMAIL", "VERTA_DEV_KEY"

        EMAIL, DEV_KEY = os.environ[EMAIL_KEY], os.environ[DEV_KEY_KEY]
        try:
            del os.environ[EMAIL_KEY], os.environ[DEV_KEY_KEY]

            try:
                with open(CONFIG_FILENAME, 'w') as f:
                    json.dump(
                        {
                            'host': HOST,
                            'email': EMAIL,
                            'dev_key': DEV_KEY,
                            'project': PROJECT_NAME,
                            'experiment': EXPERIMENT_NAME,
                            'dataset': DATASET_NAME,
                        },
                        f,
                    )

                client = verta.Client()
                conn = client._conn

                assert conn.socket == HOST
                assert conn.auth['Grpc-Metadata-email'] == EMAIL
                assert conn.auth['Grpc-Metadata-developer_key'] == DEV_KEY

                try:
                    assert client.set_experiment_run()
                    assert client.proj.name == PROJECT_NAME
                    assert client.expt.name == EXPERIMENT_NAME
                finally:
                    if client.proj is not None:
                        utils.delete_project(client.proj.id, conn)

                dataset = client.set_dataset()
                try:
                    assert dataset.name == DATASET_NAME
                finally:
                    utils.delete_datasets([dataset.id], conn)

            finally:
                if os.path.exists(CONFIG_FILENAME):
                    os.remove(CONFIG_FILENAME)
        finally:
            os.environ[EMAIL_KEY], os.environ[DEV_KEY_KEY] = EMAIL, DEV_KEY
Exemplo n.º 4
0
def test_delete_project_fail(temp_app, temp_db):
    '''Tests various failure cases when trying to delete a project'''

    # Tests trying to delete a nonexistent project'''
    login_res = login_mackland(temp_app)
    auth_token = login_res['accessToken']
    res = delete_project(0, auth_token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 400
    assert res_data['error'] == 'Project does not exist'

    # Tests trying to delete a project created by a different user
    res = delete_project(1, auth_token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 403
    assert res_data['error'] == 'Forbidden: project belongs to another user'

    # Tests trying to delete project with no auth header
    res = temp_app.delete('/project/1')
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'No authentication provided'

    # Tests trying to delete project with no auth token
    res = temp_app.delete('/project/1', headers=dict(Authorization='Bearer '))
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'No authentication provided'

    # Tests trying to delete project with an expired token
    token = generate_expired_token('access',
                                   temp_app.application.config['SECRET_KEY'])
    res = delete_project(1, token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'Invalid token'

    # Tests trying to delete project with a token signed with the wrong key
    token = generate_invalid_token('access')
    res = delete_project(1, token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'Invalid token'

    # Tests trying to use a refresh token to access projects
    token = encode_auth_token('refresh', 1, datetime.timedelta(days=3),
                              temp_app.application.config['SECRET_KEY'])
    res = delete_project(1, token.decode(), temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'Invalid token type'
Exemplo n.º 5
0
def test_delete_project(temp_app, temp_db):
    '''Tests deleting a project'''
    login_res = login_hello(temp_app)
    auth_token = login_res['accessToken']
    res = delete_project(1, auth_token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 200
    assert res_data['message'] == 'Success'

    cursor = temp_db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cursor.execute('SELECT * FROM projects WHERE id = %s', (1, ))
    db_project = cursor.fetchall()
    assert not db_project
Exemplo n.º 6
0
def tear_down(token, projects, domain):
    for project_id in projects:
        utils.disable_project(token, project_id)
        utils.delete_project(token, project_id)
    utils.disable_domain(token, domain)
    utils.delete_domain(token, domain)
def tear_down(token, projects, domain):
    for project_id in projects:
        utils.disable_project(token, project_id)
        utils.delete_project(token, project_id)
    utils.disable_domain(token, domain)
    utils.delete_domain(token, domain)