This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
import pathlib | ||
|
||
import pytest | ||
import responses | ||
|
||
from cads_api_client import Results | ||
|
||
RESULTS_URL = "http://localhost:8080/api/retrieve/v1/jobs/bcfc677f-2a4e-4e83-91da-7d1c0340f407/results" | ||
RESULTS_JSON = { | ||
"asset": { | ||
"value": { | ||
"type": "application/x-grib", | ||
"href": "http://httpbin.org/bytes/1", | ||
"file:size": 1, | ||
} | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def results() -> Results: | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
responses.GET, | ||
RESULTS_URL, | ||
json=RESULTS_JSON, | ||
status=200, | ||
content_type="application/json", | ||
) | ||
results = Results.from_request( | ||
"get", | ||
RESULTS_URL, | ||
headers={}, | ||
session=None, | ||
retry_options={"maximum_tries": 1}, | ||
request_options={}, | ||
download_options={}, | ||
sleep_max=120, | ||
cleanup=False, | ||
log_callback=None, | ||
) | ||
return results | ||
|
||
|
||
def test_results_download(results: Results, tmp_path: pathlib.Path) -> None: | ||
expected = str(tmp_path / "test.grib") | ||
actual = results.download(target=expected) | ||
assert actual == expected | ||
assert os.path.getsize(actual) == 1 | ||
|
||
|
||
def test_results_assert(results: Results) -> None: | ||
assert results.asset == { | ||
"file:size": 1, | ||
"href": "http://httpbin.org/bytes/1", | ||
"type": "application/x-grib", | ||
} | ||
|
||
|
||
def test_results_content_length(results: Results) -> None: | ||
assert results.content_length == 1 | ||
|
||
|
||
def test_results_content_type(results: Results) -> None: | ||
assert results.content_type == "application/x-grib" | ||
|
||
|
||
def test_results_json(results: Results) -> None: | ||
assert results.json == RESULTS_JSON | ||
|
||
|
||
def test_results_location(results: Results) -> None: | ||
assert results.location == "http://httpbin.org/bytes/1" | ||
|
||
|
||
def test_results_url(results: Results) -> None: | ||
assert results.url == RESULTS_URL |