Exemple #1
0
def test_user_not_exist(partially_populated_db):
    init_db_agent(DB_URL)
    api_get_and_compare('/users/3/snapshots', code=404)
    api_get_and_compare('/users/3/snapshots/1', code=404)
    api_get_and_compare('/users/3/snapshots/1/color_image', code=404)
    api_get_and_compare('/users/1/snapshots/1', code=404)
    api_get_and_compare('/users/2/snapshots/1/color_image', code=404)
Exemple #2
0
def test_get_users(populated_db):
    db_data, collection = populated_db
    init_db_agent(DB_URL)
    expected = [{
        'user_id': entry['user_id'],
        'username': entry['username']
    } for entry in db_data]
    res = api_get_and_compare('/users')
    assert res.json == expected
Exemple #3
0
def test_get_result(populated_db):
    db_data, collection = populated_db
    init_db_agent(DB_URL)
    entry = random.choice(db_data)
    user_id = entry['user_id']
    snapshot = random.choice(entry['snapshots'])
    uuid = snapshot['uuid']
    for topic, result in snapshot['results'].items():
        res = api_get_and_compare(f'/users/{user_id}/snapshots/{uuid}/{topic}')
        assert res.json == result
Exemple #4
0
def test_get_snapshots(populated_db):
    db_data, collection = populated_db
    init_db_agent(DB_URL)
    entry = random.choice(db_data)
    user_id = entry['user_id']
    expected = [{
        'uuid': snapshot['uuid'],
        'datetime': snapshot['datetime']
    } for snapshot in entry['snapshots']]
    res = api_get_and_compare(f'/users/{user_id}/snapshots')
    assert res.json == expected
Exemple #5
0
def test_get_user(populated_db):
    db_data, collection = populated_db
    init_db_agent(DB_URL)
    entry = random.choice(db_data)
    user_id = entry['user_id']
    expected = {
        'user_id': user_id,
        'username': entry['username'],
        'birthday': entry['birthday'],
        'gender': entry['gender']
    }
    res = api_get_and_compare(f'/users/{user_id}')
    assert res.json == expected
Exemple #6
0
def test_get_snapshot(populated_db):
    db_data, collection = populated_db
    init_db_agent(DB_URL)
    entry = random.choice(db_data)
    user_id = entry['user_id']
    snapshot = random.choice(entry['snapshots'])
    uuid = snapshot['uuid']
    expected = {
        'uuid': uuid,
        'datetime': snapshot['datetime'],
        'results': list(snapshot['results'].keys())
    }
    res = api_get_and_compare(f'/users/{user_id}/snapshots/{uuid}')
    assert res.json == expected
Exemple #7
0
def test_get_result_data(populated_db):
    db_data, collection = populated_db
    init_db_agent(DB_URL)
    entry = random.choice(db_data)
    user_id = entry['user_id']
    snapshot = random.choice(entry['snapshots'])
    uuid = snapshot['uuid']
    for topic in ['color_image', 'depth_image']:
        with app.test_client() as client:
            res = client.get(f'/users/{user_id}/snapshots/{uuid}/{topic}/data')
            assert res.status_code == 200
            assert res.mimetype == 'image/jpeg'
            result = snapshot['results'][topic]
            file_path = result['path']
            with open(file_path, 'rb') as file:
                file_data = file.read()
            assert res.data == file_data