diff --git a/pyproject.toml b/pyproject.toml index ad4c8b7..58d1886 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ module = ["cdsapi.*", "multiurl.*", "py.*"] # Same as Black. indent-width = 4 line-length = 88 +target-version = "py38" [tool.ruff.lint] ignore = [ @@ -53,7 +54,9 @@ select = [ # isort "I", # pydocstyle - "D" + "D", + # flake8-future-annotations + "FA" ] [tool.ruff.lint.pycodestyle] diff --git a/tests/integration_test_40_results.py b/tests/integration_test_40_results.py index 13f5968..49ba920 100644 --- a/tests/integration_test_40_results.py +++ b/tests/integration_test_40_results.py @@ -1,5 +1,4 @@ import contextlib -import os import pathlib import random from typing import Any @@ -22,19 +21,6 @@ def test_results_asset(results: Results) -> None: assert results.asset["file:size"] == 1 -@pytest.mark.parametrize("target", ("dummy.grib", None)) -def test_results_download( - monkeypatch: pytest.MonkeyPatch, - results: Results, - tmp_path: pathlib.Path, - target: str | None, -) -> None: - monkeypatch.chdir(tmp_path) - actual_target = results.download(target=target) - assert (actual_target != target) if target is None else (actual_target == target) - assert os.path.getsize(actual_target) == 1 - - @pytest.mark.parametrize("progress", [True, False]) def test_results_progress( api_root_url: str, diff --git a/tests/integration_test_50_profile.py b/tests/integration_test_50_profile.py index 264bd6b..5ebafa9 100644 --- a/tests/integration_test_50_profile.py +++ b/tests/integration_test_50_profile.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Literal import pytest diff --git a/tests/test_40_results.py b/tests/test_40_results.py new file mode 100644 index 0000000..a04ca20 --- /dev/null +++ b/tests/test_40_results.py @@ -0,0 +1,93 @@ +from __future__ import annotations + +import os +import pathlib + +import pytest +import responses + +from cads_api_client import Results + +RESULTS_URL = "http://localhost:8080/api/retrieve/v1/jobs/9bfc1362-2832-48e1-a235-359267420bb2/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 + + +@pytest.mark.parametrize( + "target,expected", + [ + ("dummy.grib", "dummy.grib"), + (None, "1"), + ], +) +def test_results_download( + monkeypatch: pytest.MonkeyPatch, + results: Results, + tmp_path: pathlib.Path, + target: str | None, + expected: str, +) -> None: + monkeypatch.chdir(tmp_path) + actual = results.download(target=target) + assert actual == expected + assert os.path.getsize(actual) == 1 + + +def test_results_asset(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