def test_cube_404(cube):
    import oneseismic
    from oneseismic.client.client import http_session
    session = http_session(
        base_url=API_ADDR,
        tokens=AUTH_CLIENT,
    )
    with pytest.raises(requests.HTTPError) as e:
        oneseismic.client.client.cube("not_found", session).slice(0, 1)
        assert e.response.status_code == 404
Beispiel #2
0
def test_slices(w, h, d):
    data = np.ndarray(shape=(w, h, d), dtype=np.float32)
    for i in range(w):
        for j in range(h):
            for k in range(d):
                data[i, j, k] = (i * 1) + (j * 1000) + (k * 1000000)

    guid = upload_cube(data)

    # TODO: use exported interface
    import oneseismic
    from oneseismic.client.client import http_session
    session = http_session(
        base_url=API_ADDR,
        tokens=AUTH_CLIENT,
    )
    cube = oneseismic.client.client.cube(guid, session)

    # test end slices
    np.testing.assert_almost_equal(cube.slice(0, 1).numpy(), data[0, :, :])
    np.testing.assert_almost_equal(cube.slice(1, 1).numpy(), data[:, 0, :])
    np.testing.assert_almost_equal(cube.slice(2, 0).numpy(), data[:, :, 0])
    np.testing.assert_almost_equal(cube.slice(0, w).numpy(), data[w - 1, :, :])
    np.testing.assert_almost_equal(cube.slice(1, h).numpy(), data[:, h - 1, :])
    np.testing.assert_almost_equal(
        cube.slice(2, (d - 1) * 4000).numpy(), data[:, :, d - 1])

    # test end slices between the two first segments
    if w > 64:
        np.testing.assert_almost_equal(
            cube.slice(0, 64).numpy(), data[63, :, :])
        np.testing.assert_almost_equal(
            cube.slice(0, 65).numpy(), data[64, :, :])
    if h > 64:
        np.testing.assert_almost_equal(
            cube.slice(1, 64).numpy(), data[:, 63, :])
        np.testing.assert_almost_equal(
            cube.slice(1, 65).numpy(), data[:, 64, :])
    if d > 64:
        np.testing.assert_almost_equal(
            cube.slice(2, 63 * 4000).numpy(), data[:, :, 63])
        np.testing.assert_almost_equal(
            cube.slice(2, 64 * 4000).numpy(), data[:, :, 64])
def test_invalid_token_should_fail(cube):
    with open('invalid_tokens.json') as f:
        tokens = json.load(f)

    for t in tokens:

        class badauth:
            def headers(self):
                return {"Authorization": f"Bearer {t['jwt']}"}

        import oneseismic
        from oneseismic.client.client import http_session
        session = http_session(
            base_url=API_ADDR,
            tokens=badauth(),
        )

        c = oneseismic.client.client.cube(cube, session)
        with pytest.raises(requests.HTTPError) as e:
            c.slice(0, 1)

            assert e.response.status_code == 401