Skip to content

Commit

Permalink
Issue #134 update api version in some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Mar 7, 2023
1 parent 2696b9b commit 635cc2b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 39 deletions.
113 changes: 80 additions & 33 deletions tests/rest/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,47 +285,83 @@ def test_connect_with_session():
(
[
{"api_version": "0.4.1", "url": "https://oeo.test/openeo/0.4.1/"},
{"api_version": "0.4.2", "url": "https://oeo.test/openeo/0.4.2/"},
{"api_version": "1.0.0", "url": "https://oeo.test/openeo/1.0.0/"},
{"api_version": "1.1.0", "url": "https://oeo.test/openeo/1.1.0/"},
],
"https://oeo.test/openeo/1.1.0/",
"1.1.0",
),
(
[
{"api_version": "0.4.1", "url": "https://oeo.test/openeo/0.4.1/"},
{"api_version": "1.0.0", "url": "https://oeo.test/openeo/1.0.0/"},
{
"api_version": "1.1.0",
"url": "https://oeo.test/openeo/1.1.0/",
"production": False,
},
],
"https://oeo.test/openeo/1.0.0/",
"1.0.0",
),
(
[
{"api_version": "0.4.1", "url": "https://oeo.test/openeo/0.4.1/"},
{"api_version": "0.4.2", "url": "https://oeo.test/openeo/0.4.2/"},
{"api_version": "1.0.0", "url": "https://oeo.test/openeo/1.0.0/", "production": False},
{
"api_version": "0.4.1",
"url": "https://oeo.test/openeo/0.4.1/",
"production": True,
},
{
"api_version": "1.0.0",
"url": "https://oeo.test/openeo/1.0.0/",
"production": True,
},
{
"api_version": "1.1.0",
"url": "https://oeo.test/openeo/1.1.0/",
"production": False,
},
],
"https://oeo.test/openeo/0.4.2/",
"0.4.2",
"https://oeo.test/openeo/1.0.0/",
"1.0.0",
),
(
[
{"api_version": "0.4.1", "url": "https://oeo.test/openeo/0.4.1/", "production": True},
{"api_version": "0.4.2", "url": "https://oeo.test/openeo/0.4.2/", "production": True},
{"api_version": "1.0.0", "url": "https://oeo.test/openeo/1.0.0/", "production": False},
{
"api_version": "0.4.1",
"url": "https://oeo.test/openeo/0.4.1/",
"production": False,
},
{
"api_version": "1.0.0",
"url": "https://oeo.test/openeo/1.0.0/",
"production": False,
},
{
"api_version": "1.1.0",
"url": "https://oeo.test/openeo/1.1.0/",
"production": False,
},
],
"https://oeo.test/openeo/0.4.2/",
"0.4.2",
),
(
"https://oeo.test/openeo/1.1.0/",
"1.1.0",
),
(
[
{"api_version": "0.4.1", "url": "https://oeo.test/openeo/0.4.1/", "production": False},
{"api_version": "0.4.2", "url": "https://oeo.test/openeo/0.4.2/", "production": False},
{"api_version": "1.0.0", "url": "https://oeo.test/openeo/1.0.0/", "production": False},
{
"api_version": "0.1.0",
"url": "https://oeo.test/openeo/0.1.0/",
"production": True,
},
{
"api_version": "1.0.0",
"url": "https://oeo.test/openeo/1.0.0/",
"production": False,
},
],
"https://oeo.test/openeo/1.0.0/",
"1.0.0",
),
(
[
{"api_version": "0.1.0", "url": "https://oeo.test/openeo/0.1.0/", "production": True},
{"api_version": "0.4.2", "url": "https://oeo.test/openeo/0.4.2/", "production": False},
],
"https://oeo.test/openeo/0.4.2/",
"0.4.2",
),
(
[],
"https://oeo.test/",
Expand Down Expand Up @@ -391,10 +427,16 @@ def test_file_formats(requests_mock):


def test_api_error(requests_mock):
requests_mock.get('https://oeo.test/', json={"api_version": "0.4.0"})
requests_mock.get('https://oeo.test/collections/foobar', status_code=404, json={
"code": "CollectionNotFound", "message": "No such thing as a collection 'foobar'", "id": "54321",
})
requests_mock.get("https://oeo.test/", json={"api_version": "1.0.0"})
requests_mock.get(
"https://oeo.test/collections/foobar",
status_code=404,
json={
"code": "CollectionNotFound",
"message": "No such thing as a collection 'foobar'",
"id": "54321",
},
)
with pytest.raises(OpenEoApiError) as exc_info:
Connection(API_URL).describe_collection("foobar")
exc = exc_info.value
Expand All @@ -407,10 +449,15 @@ def test_api_error(requests_mock):


def test_api_error_no_id(requests_mock):
requests_mock.get('https://oeo.test/', json={"api_version": "0.4.0"})
requests_mock.get('https://oeo.test/collections/foobar', status_code=404, json={
"code": "CollectionNotFound", "message": "No such thing as a collection 'foobar'",
})
requests_mock.get("https://oeo.test/", json={"api_version": "1.0.0"})
requests_mock.get(
"https://oeo.test/collections/foobar",
status_code=404,
json={
"code": "CollectionNotFound",
"message": "No such thing as a collection 'foobar'",
},
)
with pytest.raises(OpenEoApiError) as exc_info:
Connection(API_URL).describe_collection("foobar")
exc = exc_info.value
Expand All @@ -423,7 +470,7 @@ def test_api_error_no_id(requests_mock):


def test_api_error_non_json(requests_mock):
requests_mock.get('https://oeo.test/', json={"api_version": "0.4.0"})
requests_mock.get("https://oeo.test/", json={"api_version": "1.0.0"})
conn = Connection(API_URL)
requests_mock.get('https://oeo.test/collections/foobar', status_code=500, text="olapola")
with pytest.raises(OpenEoApiError) as exc_info:
Expand Down
14 changes: 8 additions & 6 deletions tests/test_rest_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ def test_capabilities_api_version_too_old2(self, m):
openeo.connect(self.endpoint)

def test_capabilities_api_version_recent(self, m):
m.register_uri('GET', "{}/".format(self.endpoint), json={'version': '0.4.0'})
m.register_uri("GET", "{}/".format(self.endpoint), json={"version": "1.0.0"})
capabilities = openeo.connect(self.endpoint).capabilities()
assert capabilities.version() == '0.4.0'
assert capabilities.api_version() == '0.4.0'
assert capabilities.version() == "1.0.0"
assert capabilities.api_version() == "1.0.0"

def test_capabilities_api_version_recent2(self, m):
m.register_uri('GET', "{}/".format(self.endpoint), json={'api_version': '0.4.1'})
m.register_uri(
"GET", "{}/".format(self.endpoint), json={"api_version": "1.1.0"}
)
capabilities = openeo.connect(self.endpoint).capabilities()
assert capabilities.version() == '0.4.1'
assert capabilities.api_version() == '0.4.1'
assert capabilities.version() == "1.1.0"
assert capabilities.api_version() == "1.1.0"

def test_capabilities_api_version_check(self, m):
capabilties_url = "{}/".format(self.endpoint)
Expand Down

0 comments on commit 635cc2b

Please sign in to comment.