Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Oct 18, 2024
1 parent c0eca09 commit 5b79765
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
19 changes: 0 additions & 19 deletions tests/integration_test_40_results.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import contextlib
import os
import pathlib
import random
from typing import Any
Expand All @@ -17,24 +16,6 @@ def results(api_anon_client: ApiClient) -> Results:
return api_anon_client.submit_and_wait_on_results("test-adaptor-dummy", size=1)


def test_results_asset(results: Results) -> None:
assert results.asset["type"] == "application/x-grib"
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,
Expand Down
56 changes: 37 additions & 19 deletions tests/test_20_results.py → tests/test_40_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
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:
def make_results(size: int = 1) -> Results:
results_json = {
"asset": {
"value": {
"type": "application/x-grib",
"href": f"http://httpbin.org/bytes/{size}",
"file:size": size,
}
}
}
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
RESULTS_URL,
json=RESULTS_JSON,
json=results_json,
status=200,
content_type="application/json",
)
Expand All @@ -43,14 +42,25 @@ def results() -> Results:
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
@pytest.fixture
def results() -> Results:
return make_results()


@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

def test_results_assert(results: Results) -> None:

def test_results_asset(results: Results) -> None:
assert results.asset == {
"file:size": 1,
"href": "http://httpbin.org/bytes/1",
Expand All @@ -67,7 +77,15 @@ def test_results_content_type(results: Results) -> None:


def test_results_json(results: Results) -> None:
assert results.json == RESULTS_JSON
assert results.json == {
"asset": {
"value": {
"type": "application/x-grib",
"href": "http://httpbin.org/bytes/1",
"file:size": 1,
}
}
}


def test_results_location(results: Results) -> None:
Expand Down

0 comments on commit 5b79765

Please sign in to comment.