Example #1
0
def test_connect_version_discovery(requests_mock, versions, expected_url, expected_version):
    requests_mock.get("https://oeo.net/", status_code=404)
    requests_mock.get("https://oeo.net/.well-known/openeo", status_code=200, json={"versions": versions})
    requests_mock.get(expected_url, status_code=200, json={"foo": "bar", "api_version": expected_version})

    conn = connect("https://oeo.net/")
    assert conn.capabilities().capabilities["foo"] == "bar"
Example #2
0
def test_connect_with_session():
    session = mock.Mock()
    response = session.request.return_value
    response.status_code = 200
    response.json.return_value = {"foo": "bar", "api_version": "0.4.0"}
    conn = connect("https://oeo.net/", session=session)
    assert conn.capabilities().capabilities["foo"] == "bar"
    session.request.assert_any_call(
        url="https://oeo.net/", method="get", headers=mock.ANY, stream=mock.ANY, auth=mock.ANY, timeout=None
    )
def test_connection_repr(requests_mock):
    requests_mock.get("https://oeo.test/", status_code=404)
    requests_mock.get("https://oeo.test/.well-known/openeo",
                      status_code=200,
                      json={
                          "versions": [{
                              "api_version": "1.0.0",
                              "url": "https://oeo.test/openeo/1.x/",
                              "production": True
                          }],
                      })
    requests_mock.get("https://oeo.test/openeo/1.x/",
                      status_code=200,
                      json={"api_version": "1.0.0"})
    requests_mock.get("https://oeo.test/openeo/1.x/credentials/basic",
                      json={"access_token": "w3lc0m3"})

    conn = connect("https://oeo.test/")
    assert repr(
        conn) == "<Connection to 'https://oeo.test/openeo/1.x/' with NullAuth>"
    conn.authenticate_basic("foo", "bar")
    assert repr(
        conn
    ) == "<Connection to 'https://oeo.test/openeo/1.x/' with BearerAuth>"
def test_default_timeout(requests_mock):
    requests_mock.get(API_URL, json={"api_version": "1.0.0"})
    requests_mock.get("/foo", json=lambda req, ctx: repr(req.timeout))
    conn = connect(API_URL, default_timeout=2)
    assert conn.get("/foo").json() == '2'
    assert conn.get("/foo", timeout=5).json() == '5'