Skip to content

Commit

Permalink
Merge pull request #5 from hydroshare/hidden-url
Browse files Browse the repository at this point in the history
Hidden url
  • Loading branch information
sblack-usu authored Sep 7, 2021
2 parents 8e866d1 + e4d7628 commit 4d64f74
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 43 deletions.
14 changes: 7 additions & 7 deletions hsmodels/schemas/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class GeographicRasterMetadata(BaseAggregationMetadata):
class Config:
title = 'Geographic Raster Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand Down Expand Up @@ -120,7 +120,7 @@ class GeographicFeatureMetadata(BaseAggregationMetadata):
class Config:
title = 'Geographic Feature Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand Down Expand Up @@ -159,7 +159,7 @@ class MultidimensionalMetadata(BaseAggregationMetadata):
class Config:
title = 'Multidimensional Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand Down Expand Up @@ -196,7 +196,7 @@ class ReferencedTimeSeriesMetadata(BaseAggregationMetadata):
class Config:
title = 'Referenced Time Series Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand All @@ -219,7 +219,7 @@ class FileSetMetadata(BaseAggregationMetadata):
class Config:
title = 'File Set Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand All @@ -241,7 +241,7 @@ class SingleFileMetadata(BaseAggregationMetadata):
class Config:
title = 'Single File Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand All @@ -266,7 +266,7 @@ class TimeSeriesMetadata(BaseAggregationMetadata):
class Config:
title = 'Time Series Aggregation Metadata'

schema_config = {'read_only': ['type'], 'exclude': ['url']}
schema_config = {'read_only': ['type', 'url']}

type: AggregationType = Field(
const=True,
Expand Down
5 changes: 0 additions & 5 deletions hsmodels/schemas/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ def schema_extra(schema: Dict[str, Any], model) -> None:
for field in schema_config["read_only"]:
schema['properties'][field]['readOnly'] = True

if "exclude" in schema_config:
# remove excluded fields from schema
for field in schema_config["exclude"]:
schema["properties"].pop(field, None)


class BaseCoverage(BaseMetadata):
def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion hsmodels/schemas/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ResourceMetadata(BaseMetadata):
class Config:
title = 'Resource Metadata'

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

type: str = Field(
const=True,
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.2.0',
version='0.2.1',
packages=find_packages(include=['hsmodels', 'hsmodels.*', 'hsmodels.schemas.*', 'hsmodels.schemas.rdf.*'],
exclude=("tests",)),
install_requires=[
Expand Down
42 changes: 13 additions & 29 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def change_test_dir(request):


read_only_fields = [
(ResourceMetadata, ['type', 'identifier', 'created', 'modified', 'published']),
(GeographicRasterMetadata, ['type']),
(GeographicFeatureMetadata, ['type']),
(MultidimensionalMetadata, ['type']),
(ReferencedTimeSeriesMetadata, ['type']),
(FileSetMetadata, ['type']),
(SingleFileMetadata, ['type']),
(TimeSeriesMetadata, ['type']),
(ResourceMetadata, ['type', 'identifier', 'created', 'modified', 'published', 'url']),
(GeographicRasterMetadata, ['type', 'url']),
(GeographicFeatureMetadata, ['type', 'url']),
(MultidimensionalMetadata, ['type', 'url']),
(ReferencedTimeSeriesMetadata, ['type', 'url']),
(FileSetMetadata, ['type', 'url']),
(SingleFileMetadata, ['type', 'url']),
(TimeSeriesMetadata, ['type', 'url']),
(Creator, ['description']),
(Contributor, ['description']),
(BoxCoverage, ['type']),
Expand All @@ -52,25 +52,9 @@ def change_test_dir(request):
def test_readonly(read_only_field):
clazz, fields = read_only_field
s = schema([clazz])["definitions"][clazz.__name__]
for field in fields:
assert s["properties"][field]["readOnly"] is True


exclude_fields = [
(ResourceMetadata, ['url']),
(GeographicRasterMetadata, ['url']),
(GeographicFeatureMetadata, ['url']),
(MultidimensionalMetadata, ['url']),
(ReferencedTimeSeriesMetadata, ['url']),
(FileSetMetadata, ['url']),
(SingleFileMetadata, ['url']),
(TimeSeriesMetadata, ['url']),
]


@pytest.mark.parametrize("exclude_field", exclude_fields)
def test_exclude(exclude_field):
clazz, fields = exclude_field
s = schema([clazz])["definitions"][clazz.__name__]
for field in fields:
assert field not in s["properties"]
for prop in s["properties"]:
if prop in fields:
assert "readOnly" in s["properties"][prop] and s["properties"][prop]["readOnly"] is True
else:
assert "readOnly" not in s["properties"][prop]

0 comments on commit 4d64f74

Please sign in to comment.