Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PT-5547] Moved ProductGlossary to glossary.py #661

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ You can check your current version with the following command:
```

For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/).
## 2.0.0a5

**Aug 7, 2024**
- Moved `ProductGlossary` and its dependencies to `glossary.py`.
- Published `CollectionType` in the global namespace.

## 2.0.0a4

**Aug 6, 2024**
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "up42-py"
version = "2.0.0a4"
version = "2.0.0a5"
description = "Python SDK for UP42, the geospatial marketplace and developer platform."
authors = ["UP42 GmbH <support@up42.com>"]
license = "https://github.com/up42/up42-py/blob/master/LICENSE"
Expand Down
86 changes: 2 additions & 84 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import dataclasses
import json
import pathlib
from typing import Optional

import geopandas as gpd # type: ignore
import mock
Expand All @@ -10,7 +8,7 @@
import requests_mock as req_mock
import shapely # type: ignore

from up42 import catalog, order, utils
from up42 import catalog, glossary, order

from . import helpers
from .fixtures import fixtures_globals as constants
Expand All @@ -27,96 +25,16 @@
"up42:usageType": {"in": ["DATA", "ANALYTICS"]},
},
}
DATA_PRODUCT = catalog.DataProduct(
name="data-product-name",
title="data-product-title",
description="data-product",
id="data-product-id",
eula_id="eula-id",
)
RESOLUTION_VALUE = catalog.ResolutionValue(minimum=0.0, maximum=1.0, description="resolution value")
COLLECTION_METADATA = catalog.CollectionMetadata(
product_type="OPTICAL",
resolution_class="VERY_HIGH",
resolution_value=RESOLUTION_VALUE,
)
COLLECTION = catalog.Collection(
name="collection-name",
title="collection-title",
description="collection",
type=catalog.CollectionType.ARCHIVE,
integrations=list(catalog.IntegrationValue),
providers=[
catalog.Provider(
name="provider-name",
title="provider-title",
description="provider",
roles=["PRODUCER", "HOST"],
)
],
data_products=[DATA_PRODUCT],
metadata=COLLECTION_METADATA,
)


@pytest.fixture(autouse=True)
def set_status_raising_session():
session = requests.Session()
session.hooks = {"response": lambda response, *args, **kwargs: response.raise_for_status()}
catalog.ProductGlossary.session = session # type: ignore
glossary.ProductGlossary.session = session # type: ignore
catalog.CatalogBase.session = session # type: ignore


class TestProductGlossary:
@pytest.mark.parametrize(
"collection_type",
[None, catalog.CollectionType.ARCHIVE, catalog.CollectionType.TASKING],
)
@pytest.mark.parametrize("sort_by", [None, catalog.CollectionSorting.name])
def test_should_get_collections(
self,
requests_mock: req_mock.Mocker,
collection_type: catalog.CollectionType,
sort_by: Optional[utils.SortingField],
):
collections = [
{
"name": COLLECTION.name,
"description": COLLECTION.description,
"title": COLLECTION.title,
"type": type_value.value,
"integrations": [entry.value for entry in catalog.IntegrationValue],
"providers": [dataclasses.asdict(COLLECTION.providers[0])],
"dataProducts": [
{
"name": DATA_PRODUCT.name,
"title": DATA_PRODUCT.title,
"description": DATA_PRODUCT.description,
"id": DATA_PRODUCT.id,
"eulaId": DATA_PRODUCT.eula_id,
}
],
"metadata": {
"productType": COLLECTION_METADATA.product_type,
"resolutionClass": COLLECTION_METADATA.resolution_class,
"resolutionValue": dataclasses.asdict(RESOLUTION_VALUE),
},
}
for type_value in list(catalog.CollectionType)
]
sorting_param = f"sort={sort_by}&" if sort_by else ""
for page in [0, 1]:
requests_mock.get(
f"{constants.API_HOST}/v2/collections?{sorting_param}page={page}",
json={"content": collections, "totalPages": 2},
)
possible_types = [collection_type] if collection_type else list(catalog.CollectionType)
assert (
list(catalog.ProductGlossary.get_collections(collection_type=collection_type, sort_by=sort_by))
== [dataclasses.replace(COLLECTION, type=possible_type) for possible_type in possible_types] * 2
)


def test_get_data_product_schema(catalog_mock):
data_product_schema = catalog_mock.get_data_product_schema(constants.DATA_PRODUCT_ID)
assert isinstance(data_product_schema, dict)
Expand Down
101 changes: 101 additions & 0 deletions tests/test_glossary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import dataclasses
from typing import Optional

import pytest
import requests
import requests_mock as req_mock

from tests.fixtures import fixtures_globals as constants
from up42 import glossary, utils

DATA_PRODUCT = glossary.DataProduct(
name="data-product-name",
title="data-product-title",
description="data-product",
id="data-product-id",
eula_id="eula-id",
)
RESOLUTION_VALUE = glossary.ResolutionValue(minimum=0.0, maximum=1.0, description="resolution value")
COLLECTION_METADATA = glossary.CollectionMetadata(
product_type="OPTICAL",
resolution_class="VERY_HIGH",
resolution_value=RESOLUTION_VALUE,
)
COLLECTION = glossary.Collection(
name="collection-name",
title="collection-title",
description="collection",
type=glossary.CollectionType.ARCHIVE,
integrations=list(glossary.IntegrationValue),
providers=[
glossary.Provider(
name="provider-name",
title="provider-title",
description="provider",
roles=["PRODUCER", "HOST"],
)
],
data_products=[DATA_PRODUCT],
metadata=COLLECTION_METADATA,
)


@pytest.fixture(autouse=True)
def set_status_raising_session():
session = requests.Session()
session.hooks = {"response": lambda response, *args, **kwargs: response.raise_for_status()}
glossary.ProductGlossary.session = session # type: ignore


class TestProductGlossary:
@pytest.mark.parametrize(
"collection_type",
[
None,
glossary.CollectionType.ARCHIVE,
glossary.CollectionType.TASKING,
],
)
@pytest.mark.parametrize("sort_by", [None, glossary.CollectionSorting.name])
def test_should_get_collections(
self,
requests_mock: req_mock.Mocker,
collection_type: glossary.CollectionType,
sort_by: Optional[utils.SortingField],
):
collections = [
{
"name": COLLECTION.name,
"description": COLLECTION.description,
"title": COLLECTION.title,
"type": type_value.value,
"integrations": [entry.value for entry in glossary.IntegrationValue],
"providers": [dataclasses.asdict(COLLECTION.providers[0])],
"dataProducts": [
{
"name": DATA_PRODUCT.name,
"title": DATA_PRODUCT.title,
"description": DATA_PRODUCT.description,
"id": DATA_PRODUCT.id,
"eulaId": DATA_PRODUCT.eula_id,
}
],
"metadata": {
"productType": COLLECTION_METADATA.product_type,
"resolutionClass": COLLECTION_METADATA.resolution_class,
"resolutionValue": dataclasses.asdict(RESOLUTION_VALUE),
},
}
for type_value in list(glossary.CollectionType)
]
sorting_param = f"sort={sort_by}&" if sort_by else ""
for page in [0, 1]:
requests_mock.get(
f"{constants.API_HOST}/v2/collections?{sorting_param}page={page}",
json={"content": collections, "totalPages": 2},
)
possible_types = [collection_type] if collection_type else list(glossary.CollectionType)
assert (
list(glossary.ProductGlossary.get_collections(collection_type=collection_type, sort_by=sort_by))
== [dataclasses.replace(COLLECTION, type=possible_type) for possible_type in possible_types] * 2
)
4 changes: 3 additions & 1 deletion up42/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from up42.asset import Asset
from up42.auth import Auth
from up42.base import authenticate, get_credits_balance
from up42.catalog import Catalog, CollectionSorting, ProductGlossary
from up42.catalog import Catalog
from up42.glossary import CollectionSorting, CollectionType, ProductGlossary
from up42.initialization import (
initialize_asset,
initialize_catalog,
Expand Down Expand Up @@ -66,6 +67,7 @@
JobSorting,
JobStatus,
CollectionSorting,
CollectionType,
ProductGlossary,
]
]
Loading