From 7dc9ac73cd0f7c0414595df955fbf62b95ed270d Mon Sep 17 00:00:00 2001 From: Kostis-S-Z Date: Thu, 6 Aug 2026 12:10:41 +0300 Subject: [PATCH 1/2] Add currency field that is autocomputed if isPaid=True --- src/datacollective/models.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/datacollective/models.py b/src/datacollective/models.py index 47b303a..087ab30 100644 --- a/src/datacollective/models.py +++ b/src/datacollective/models.py @@ -3,7 +3,14 @@ from enum import Enum from typing import Any, ClassVar -from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator +from pydantic import ( + BaseModel, + ConfigDict, + Field, + computed_field, + field_validator, + model_validator, +) class UploadPart(BaseModel): @@ -284,6 +291,13 @@ def _validate_pricing(self) -> DatasetSubmission: ) return self + @computed_field( # type: ignore[prop-decorator] + description="Currency for `basePriceCents`. Always `usd`, the only currency the platform currently supports." + ) + @property + def currency(self) -> str | None: + return "usd" if self.isPaid else None + class DatasetDetails(Dataset): """ @@ -377,6 +391,7 @@ def get(self, key: str, default: Any = None) -> Any: "exclusivityOptOut", "isPaid", "basePriceCents", + "currency", } SUBMIT_FIELDS = {"agreeToSubmit"} From 8b7809fbd4040b218a8b4ed6f91c2fdeacd24c26 Mon Sep 17 00:00:00 2001 From: Kostis-S-Z Date: Thu, 6 Aug 2026 12:10:52 +0300 Subject: [PATCH 2/2] Add unit tests --- tests/test_models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index 56f7d90..cdcf989 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -184,6 +184,21 @@ def test_price_requires_paid_dataset() -> None: DatasetSubmission(isPaid=False, basePriceCents=25_000) +def test_currency_is_set_only_when_paid() -> None: + free = DatasetSubmission(name="Free") + assert free.currency is None + assert "currency" not in free.model_dump(exclude_none=True) + + paid = DatasetSubmission(isPaid=True, basePriceCents=25_000) + assert paid.currency == "usd" + assert paid.model_dump(mode="json", exclude_none=True)["currency"] == "usd" + + +def test_currency_is_not_a_settable_field() -> None: + with pytest.raises(ValidationError): + DatasetSubmission(isPaid=True, basePriceCents=25_000, currency="eur") + + def test_dataset_details_requires_id() -> None: with pytest.raises(ValidationError): DatasetDetails.model_validate({"filename": "dataset.tar.gz"})