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

Commit

Permalink
add results test
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Oct 18, 2024
1 parent c6c58af commit c0eca09
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/test_20_results.py
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

0 comments on commit c0eca09

Please sign in to comment.