Skip to content

Commit

Permalink
add unit-tests for Collection (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 authored Jan 16, 2025
1 parent 1c55e54 commit a4a1e77
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/test_10_catalogue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from __future__ import annotations

import pytest
import responses

from datapi import Collection

COLLECTION_URL = (
"http://localhost:8080/api/catalogue/v1/collections/reanalysis-era5-pressure-levels"
)
COLLECTION_JSON = {
"id": "reanalysis-era5-pressure-levels",
"extent": {
"spatial": {"bbox": [[0.0, -89.0, 360.0, 89.0]]},
"temporal": {"interval": [["1959-01-01T00:00:00Z", "2025-01-10T00:00:00Z"]]},
},
}


@pytest.fixture
@responses.activate
def collection() -> Collection:
responses.add(
responses.GET,
COLLECTION_URL,
json=COLLECTION_JSON,
status=200,
content_type="application/json",
)
return Collection.from_request(
"get",
COLLECTION_URL,
headers={},
session=None,
retry_options={"maximum_tries": 1},
request_options={},
download_options={},
sleep_max=120,
cleanup=False,
log_callback=None,
)


def test_catalogue_collection_begin_datetime(collection: Collection) -> None:
assert collection.begin_datetime is not None
assert collection.begin_datetime.isoformat() == "1959-01-01T00:00:00+00:00"


def test_catalogue_collection_end_datetime(collection: Collection) -> None:
assert collection.end_datetime is not None
assert collection.end_datetime.isoformat() == "2025-01-10T00:00:00+00:00"


def test_catalogue_collection_bbox(collection: Collection) -> None:
assert collection.bbox == (0, -89, 360, 89)


def test_catalogue_collection_id(collection: Collection) -> None:
assert collection.id == "reanalysis-era5-pressure-levels"


def test_catalogue_collection_json(collection: Collection) -> None:
assert collection.json == COLLECTION_JSON


def test_catalogue_collection_url(collection: Collection) -> None:
assert collection.url == COLLECTION_URL

0 comments on commit a4a1e77

Please sign in to comment.