Skip to content

Commit

Permalink
Merge pull request #41 from hydroshare/rdf_test
Browse files Browse the repository at this point in the history
add review_started and published as HSTERMS
  • Loading branch information
devincowan authored Apr 4, 2023
2 parents dce27c8 + 1a9f009 commit ac6bec4
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 9 deletions.
3 changes: 2 additions & 1 deletion hsmodels/schemas/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class DateType(TermEnum):
created = str(DCTERMS.created)
valid = str(DCTERMS.valid)
available = str(DCTERMS.available)
published = str(DCTERMS.published)
review_started = str(HSTERMS.reviewStarted)
published = str(HSTERMS.published)


class ModelProgramFileType(TermEnum):
Expand Down
4 changes: 4 additions & 0 deletions hsmodels/schemas/rdf/root_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def parse_rdf_dates(cls, values):
dates.append({"type": DateType.modified, "value": values["modified"]})
del values["modified"]

if "review_started" in values and values["review_started"]:
dates.append({"type": DateType.review_started, "value": values["review_started"]})
del values["review_started"]

if "published" in values and values["published"]:
dates.append({"type": DateType.published, "value": values["published"]})
del values["published"]
Expand Down
8 changes: 7 additions & 1 deletion hsmodels/schemas/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Config:
title = 'Resource Metadata'

schema_config = {
'read_only': ['type', 'identifier', 'created', 'modified', 'published', 'url'],
'read_only': ['type', 'identifier', 'created', 'modified', 'review_started', 'published', 'url'],
'dictionary_field': ['additional_metadata'],
}

Expand Down Expand Up @@ -134,6 +134,12 @@ class BaseResourceMetadata(ResourceMetadataIn):
description="A datetime object containing the instant associated with when a resource was last modified",
allow_mutation=False,
)
review_started: datetime = Field(
default=None,
title="Review started date",
description="A datetime object containing the instant associated with when metadata review started on a resource",
allow_mutation=False,
)
published: datetime = Field(
default=None,
title="Published date",
Expand Down
2 changes: 2 additions & 0 deletions hsmodels/schemas/root_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def split_dates(cls, values):
values["created"] = date['value']
elif date['type'] == DateType.modified:
values["modified"] = date['value']
elif date['type'] == DateType.review_started:
values["review_started"] = date['value']
elif date['type'] == DateType.published:
values["published"] = date['value']
del values["dates"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='hsmodels',
version='0.5.4',
version='0.5.5',
packages=find_packages(include=['hsmodels', 'hsmodels.*', 'hsmodels.schemas.*', 'hsmodels.schemas.rdf.*'],
exclude=("tests",)),
install_requires=[
Expand Down
9 changes: 7 additions & 2 deletions tests/data/metadata/resourcemetadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@
</rdf:Description>
</hsterms:extendedMetadata>
<dc:date>
<dcterms:published>
<hsterms:reviewStarted>
<rdf:value>2020-11-12T18:53:19.778819+00:00</rdf:value>
</hsterms:reviewStarted>
</dc:date>
<dc:date>
<hsterms:published>
<rdf:value>2020-11-13T18:53:19.778819+00:00</rdf:value>
</dcterms:published>
</hsterms:published>
</dc:date>
<dc:publisher>
<rdf:Description>
Expand Down
9 changes: 7 additions & 2 deletions tests/data/metadata/resourcemetadata_with_point_coverage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,14 @@
</rdf:Description>
</hsterms:extendedMetadata>
<dc:date>
<dcterms:published>
<hsterms:reviewStarted>
<rdf:value>2020-11-12T18:53:19.778819+00:00</rdf:value>
</hsterms:reviewStarted>
</dc:date>
<dc:date>
<hsterms:published>
<rdf:value>2020-11-13T18:53:19.778819+00:00</rdf:value>
</dcterms:published>
</hsterms:published>
</dc:date>
<dc:publisher>
<rdf:Description>
Expand Down
1 change: 1 addition & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def test_resource_metadata(res_md):

assert res_md.modified == datetime.fromisoformat("2020-11-13T19:40:57.276064+00:00")
assert res_md.created == datetime.fromisoformat("2020-07-09T19:12:21.354703+00:00")
assert res_md.review_started == datetime.fromisoformat("2020-11-12T18:53:19.778819+00:00")
assert res_md.published == datetime.fromisoformat("2020-11-13T18:53:19.778819+00:00")

assert len(res_md.awards) == 2
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
)

read_only_fields = [
(ResourceMetadata, ['type', 'identifier', 'created', 'modified', 'published', 'url']),
(CollectionMetadata, ['type', 'identifier', 'created', 'modified', 'published', 'url']),
(ResourceMetadata, ['type', 'identifier', 'created', 'modified', 'review_started', 'published', 'url']),
(CollectionMetadata, ['type', 'identifier', 'created', 'modified', 'review_started', 'published', 'url']),
(GeographicRasterMetadata, ['type', 'url']),
(ModelProgramMetadata, ['type', 'url']),
(ModelInstanceMetadata, ['type', 'url']),
Expand Down
8 changes: 8 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def test_resource_modified_readonly(res_md):
assert '"modified" has allow_mutation set to False and cannot be assigned' in str(e)


def test_resource_review_readonly(res_md):
try:
res_md.review_started = datetime.now()
assert False, "Should have thrown error"
except TypeError as e:
assert '"review_started" has allow_mutation set to False and cannot be assigned' in str(e)


def test_resource_published_readonly(res_md):
try:
res_md.published = datetime.now()
Expand Down

0 comments on commit ac6bec4

Please sign in to comment.