Skip to content

Commit

Permalink
Read modified data of CS from env (& fix its type)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalito committed Oct 30, 2023
1 parent 8066dd6 commit eb4e352
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/voc4cat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def creator_must_be_from_list(cls, v):
return v

@validator("modified")
def set_modified_date_if_missing(cls, v):
if os.getenv("VOC4CAT_VERSION") is not None:
v = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d")
def set_modified_date_from_env(cls, v):
if os.getenv("VOC4CAT_MODIFIED") is not None:
v = datetime.date.fromisoformat(os.getenv("VOC4CAT_MODIFIED"))
return v

@validator("publisher")
Expand Down
26 changes: 22 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,31 @@ def test_vocabulary_valid_in_ci():
custodian="Vance Kelly",
pid="http://pid.geoscience.gov.au/dataset/ga/114541",
)
assert cs.modified == datetime.date(2020, 4, 4)
assert cs.version == "automatic"


@mock.patch.dict(
os.environ,
{"CI": "", "VOC4CAT_VERSION": "v2023-08-15", "VOC4CAT_MODIFIED": "2023-08-15"},
)
def test_vocabulary_valid_modified_via_envvar():
cs = ConceptScheme(
uri="https://linked.data.gov.au/def/borehole-start-point",
title="Borehole Start Point",
description="Indicates the nature of the borehole start point location",
created="2020-04-02",
modified="2020-04-04",
creator="GSQ",
publisher="GSQ",
version="1.0",
provenance="Derived from the 2011-09 version of CGI Borehole start point list",
custodian="Vance Kelly",
pid="http://pid.geoscience.gov.au/dataset/ga/114541",
)
assert cs.modified == datetime.date(2023, 8, 15)
assert cs.version == "v2023-08-15"


@mock.patch.dict(os.environ, {"CI": "", "VOC4CAT_VERSION": "v2023-08-15"})
def test_vocabulary_valid_version_via_envvar():
cs = ConceptScheme(
Expand All @@ -138,9 +159,6 @@ def test_vocabulary_valid_version_via_envvar():
custodian="Vance Kelly",
pid="http://pid.geoscience.gov.au/dataset/ga/114541",
)
assert cs.modified == datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d"
)
assert cs.version == "v2023-08-15"


Expand Down

0 comments on commit eb4e352

Please sign in to comment.