From 013d137c954bdf6c6181fef8cc8b87496a1366c4 Mon Sep 17 00:00:00 2001 From: pkdash Date: Tue, 5 Mar 2024 17:15:09 -0500 Subject: [PATCH] Revert "Merge pull request #79 from I-GUIDE/78-file-level-metadata" --- api/models/management/generate_schema.py | 4 +- api/models/schema.py | 74 - api/models/schemas/schema.json | 1873 ---------------------- tests/test_core_schema.py | 354 +--- 4 files changed, 18 insertions(+), 2287 deletions(-) diff --git a/api/models/management/generate_schema.py b/api/models/management/generate_schema.py index f0b9b35..a93cc9e 100644 --- a/api/models/management/generate_schema.py +++ b/api/models/management/generate_schema.py @@ -15,12 +15,12 @@ def main(output_name: str = "api/models/schemas/schema.json"): class_definition = schema["definitions"][definition] # replace allOf with a single definition json_schema = json_schema.replace( - f'"allOf": [{{"$ref": "#/definitions/{definition}"}}]', + f'"allOf": [{{"$ref": "#/definitions/{definition}"}}]', json.dumps(class_definition)[1:-1] ) #replace definition directly json_schema = json_schema.replace( - f'"$ref": "#/definitions/{definition}"', + f'"$ref": "#/definitions/{definition}"', json.dumps(class_definition)[1:-1] ) embedded_schema = json.loads(json_schema) diff --git a/api/models/schema.py b/api/models/schema.py index b304fc1..634b789 100644 --- a/api/models/schema.py +++ b/api/models/schema.py @@ -107,10 +107,6 @@ class PublisherOrganization(Organization): ) -class MediaObjectSourceOrganization(Organization): - name: str = Field(description="Name of the organization that created the media object.") - - class DefinedTerm(SchemaBaseModel): type: str = Field(alias="@type", default="DefinedTerm") name: str = Field(description="The name of the term or item being defined.") @@ -308,50 +304,6 @@ def validate_box(cls, v): return v -class PropertyValueBase(SchemaBaseModel): - type: str = Field( - alias="@type", - default="PropertyValue", - const="PropertyValue", - description="A property-value pair.", - ) - propertyID: Optional[str] = Field( - title="Property ID", description="The ID of the property." - ) - name: str = Field(description="The name of the property.") - value: str = Field(description="The value of the property.") - unitCode: Optional[str] = Field( - title="Measurement unit", description="The unit of measurement for the value." - ) - description: Optional[str] = Field(description="A description of the property.") - minValue: Optional[float] = Field( - title="Minimum value", description="The minimum allowed value for the property." - ) - maxValue: Optional[float] = Field( - title="Maximum value", description="The maximum allowed value for the property." - ) - - class Config: - title = "PropertyValue" - - @root_validator - def validate_min_max_values(cls, values): - min_value = values.get("minValue", None) - max_value = values.get("maxValue", None) - if min_value is not None and max_value is not None: - if min_value > max_value: - raise ValueError("Minimum value must be less than or equal to maximum value") - - return values - - -class PropertyValue(PropertyValueBase): - # using PropertyValueBase model instead of PropertyValue model as one of the types for the value field - # in order for the schema generation (schema.json) to work. Self referencing nested models leads to - # infinite loop in our custom schema generation code when trying to replace dict with key '$ref' - value: Union[str, PropertyValueBase, List[PropertyValueBase]] = Field(description="The value of the property.") - - class Place(SchemaBaseModel): type: str = Field(alias="@type", default="Place", description="Represents the focus area of the record's content.") name: Optional[str] = Field(description="Name of the place.") @@ -360,12 +312,6 @@ class Place(SchemaBaseModel): "or area coverage extent." ) - additionalProperty: Optional[List[PropertyValue]] = Field( - title="Additional properties", - default=[], - description="Additional properties of the place." - ) - @root_validator def validate_geo_or_name_required(cls, values): name = values.get('name', None) @@ -390,26 +336,6 @@ class MediaObject(SchemaBaseModel): "unit of measurement." ) name: str = Field(description="The name of the media object (file).") - additionalProperty: Optional[List[PropertyValue]] = Field( - title="Additional properties", - default=[], - description="Additional properties of the media object." - ) - variableMeasured: Optional[List[Union[str, PropertyValue]]] = Field( - title="Variables measured", description="Measured variables." - ) - spatialCoverage: Optional[Place] = Field( - title="Spatial coverage", - description="The spatial coverage of the media object." - ) - temporalCoverage: Optional[TemporalCoverage] = Field( - title="Temporal coverage", - description="The temporal coverage of the media object." - ) - sourceOrganization: Optional[MediaObjectSourceOrganization] = Field( - title="Source organization", - description="The organization that provided the media object." - ) @validator('contentSize') def validate_content_size(cls, v): diff --git a/api/models/schemas/schema.json b/api/models/schemas/schema.json index 5b2b26b..0971e8b 100644 --- a/api/models/schemas/schema.json +++ b/api/models/schemas/schema.json @@ -720,175 +720,6 @@ ] } ] - }, - "additionalProperty": { - "title": "Additional properties", - "description": "Additional properties of the place.", - "default": [], - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } } } }, @@ -1013,648 +844,6 @@ "title": "Name", "description": "The name of the media object (file).", "type": "string" - }, - "additionalProperty": { - "title": "Additional properties", - "description": "Additional properties of the media object.", - "default": [], - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - }, - "variableMeasured": { - "title": "Variables measured", - "description": "Measured variables.", - "type": "array", - "items": { - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - ] - } - }, - "spatialCoverage": { - "title": "Place", - "description": "The spatial coverage of the media object.", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "Represents the focus area of the record's content.", - "default": "Place", - "type": "string" - }, - "name": { - "title": "Name", - "description": "Name of the place.", - "type": "string" - }, - "geo": { - "title": "Geo", - "description": "Specifies the geographic coordinates of the place in the form of a point location, line, or area coverage extent.", - "anyOf": [ - { - "title": "GeoCoordinates", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "Geographic coordinates that represent a specific location on the Earth's surface. GeoCoordinates typically consists of two components: latitude and longitude.", - "default": "GeoCoordinates", - "type": "string" - }, - "latitude": { - "title": "Latitude", - "description": "Represents the angular distance of a location north or south of the equator, measured in degrees and ranges from -90 to +90 degrees.", - "type": "number" - }, - "longitude": { - "title": "Longitude", - "description": "Represents the angular distance of a location east or west of the Prime Meridian, measured in degrees and ranges from -180 to +180 degrees.", - "type": "number" - } - }, - "required": [ - "latitude", - "longitude" - ] - }, - { - "title": "GeoShape", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A structured representation that describes the coordinates of a geographic feature.", - "default": "GeoShape", - "type": "string" - }, - "box": { - "title": "Box", - "description": "A box is a rectangular region defined by a pair of coordinates representing the southwest and northeast corners of the box.", - "type": "string" - } - }, - "required": [ - "box" - ] - } - ] - }, - "additionalProperty": { - "title": "Additional properties", - "description": "Additional properties of the place.", - "default": [], - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - } - }, - "temporalCoverage": { - "title": "TemporalCoverage", - "description": "The temporal coverage of the media object.", - "type": "object", - "properties": { - "startDate": { - "title": "Start date", - "description": "A date/time object containing the instant corresponding to the commencement of the time interval (ISO8601 formatted date - YYYY-MM-DDTHH:MM).", - "type": "string", - "format": "date-time" - }, - "endDate": { - "title": "End date", - "description": "A date/time object containing the instant corresponding to the termination of the time interval (ISO8601 formatted date - YYYY-MM-DDTHH:MM). If the ending date is left off, that means the temporal coverage is ongoing.", - "type": "string", - "format": "date-time" - } - }, - "required": [ - "startDate" - ] - }, - "sourceOrganization": { - "title": "MediaObjectSourceOrganization", - "description": "The organization that provided the media object.", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "default": "Organization", - "const": "Organization", - "type": "string" - }, - "name": { - "title": "Name", - "description": "Name of the organization that created the media object.", - "type": "string" - }, - "url": { - "title": "URL", - "description": "A URL to the homepage for the organization.", - "minLength": 1, - "maxLength": 2083, - "type": "string", - "pattern": "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$", - "errorMessage": { - "pattern": "must match format \"url\"" - } - }, - "address": { - "title": "Address", - "description": "Full address for the organization - e.g., \u201c8200 Old Main Hill, Logan, UT 84322-8200\u201d.", - "type": "string" - } - }, - "required": [ - "name" - ] } }, "required": [ @@ -2252,221 +1441,6 @@ "box" ] }, - "PropertyValueBase": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - "PropertyValue": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, "Place": { "title": "Place", "type": "object", @@ -2533,175 +1507,6 @@ ] } ] - }, - "additionalProperty": { - "title": "Additional properties", - "description": "Additional properties of the place.", - "default": [], - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } } } }, @@ -2777,42 +1582,6 @@ "name" ] }, - "MediaObjectSourceOrganization": { - "title": "MediaObjectSourceOrganization", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "default": "Organization", - "const": "Organization", - "type": "string" - }, - "name": { - "title": "Name", - "description": "Name of the organization that created the media object.", - "type": "string" - }, - "url": { - "title": "URL", - "description": "A URL to the homepage for the organization.", - "minLength": 1, - "maxLength": 2083, - "type": "string", - "pattern": "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$", - "errorMessage": { - "pattern": "must match format \"url\"" - } - }, - "address": { - "title": "Address", - "description": "Full address for the organization - e.g., \u201c8200 Old Main Hill, Logan, UT 84322-8200\u201d.", - "type": "string" - } - }, - "required": [ - "name" - ] - }, "MediaObject": { "title": "MediaObject", "type": "object", @@ -2848,648 +1617,6 @@ "title": "Name", "description": "The name of the media object (file).", "type": "string" - }, - "additionalProperty": { - "title": "Additional properties", - "description": "Additional properties of the media object.", - "default": [], - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - }, - "variableMeasured": { - "title": "Variables measured", - "description": "Measured variables.", - "type": "array", - "items": { - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - ] - } - }, - "spatialCoverage": { - "title": "Place", - "description": "The spatial coverage of the media object.", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "Represents the focus area of the record's content.", - "default": "Place", - "type": "string" - }, - "name": { - "title": "Name", - "description": "Name of the place.", - "type": "string" - }, - "geo": { - "title": "Geo", - "description": "Specifies the geographic coordinates of the place in the form of a point location, line, or area coverage extent.", - "anyOf": [ - { - "title": "GeoCoordinates", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "Geographic coordinates that represent a specific location on the Earth's surface. GeoCoordinates typically consists of two components: latitude and longitude.", - "default": "GeoCoordinates", - "type": "string" - }, - "latitude": { - "title": "Latitude", - "description": "Represents the angular distance of a location north or south of the equator, measured in degrees and ranges from -90 to +90 degrees.", - "type": "number" - }, - "longitude": { - "title": "Longitude", - "description": "Represents the angular distance of a location east or west of the Prime Meridian, measured in degrees and ranges from -180 to +180 degrees.", - "type": "number" - } - }, - "required": [ - "latitude", - "longitude" - ] - }, - { - "title": "GeoShape", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A structured representation that describes the coordinates of a geographic feature.", - "default": "GeoShape", - "type": "string" - }, - "box": { - "title": "Box", - "description": "A box is a rectangular region defined by a pair of coordinates representing the southwest and northeast corners of the box.", - "type": "string" - } - }, - "required": [ - "box" - ] - } - ] - }, - "additionalProperty": { - "title": "Additional properties", - "description": "Additional properties of the place.", - "default": [], - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "anyOf": [ - { - "type": "string" - }, - { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - }, - { - "type": "array", - "items": { - "title": "PropertyValue", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "description": "A property-value pair.", - "default": "PropertyValue", - "const": "PropertyValue", - "type": "string" - }, - "propertyID": { - "title": "Property ID", - "description": "The ID of the property.", - "type": "string" - }, - "name": { - "title": "Name", - "description": "The name of the property.", - "type": "string" - }, - "value": { - "title": "Value", - "description": "The value of the property.", - "type": "string" - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - ] - }, - "unitCode": { - "title": "Measurement unit", - "description": "The unit of measurement for the value.", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the property.", - "type": "string" - }, - "minValue": { - "title": "Minimum value", - "description": "The minimum allowed value for the property.", - "type": "number" - }, - "maxValue": { - "title": "Maximum value", - "description": "The maximum allowed value for the property.", - "type": "number" - } - }, - "required": [ - "name", - "value" - ] - } - } - } - }, - "temporalCoverage": { - "title": "TemporalCoverage", - "description": "The temporal coverage of the media object.", - "type": "object", - "properties": { - "startDate": { - "title": "Start date", - "description": "A date/time object containing the instant corresponding to the commencement of the time interval (ISO8601 formatted date - YYYY-MM-DDTHH:MM).", - "type": "string", - "format": "date-time" - }, - "endDate": { - "title": "End date", - "description": "A date/time object containing the instant corresponding to the termination of the time interval (ISO8601 formatted date - YYYY-MM-DDTHH:MM). If the ending date is left off, that means the temporal coverage is ongoing.", - "type": "string", - "format": "date-time" - } - }, - "required": [ - "startDate" - ] - }, - "sourceOrganization": { - "title": "MediaObjectSourceOrganization", - "description": "The organization that provided the media object.", - "type": "object", - "properties": { - "@type": { - "title": "@Type", - "default": "Organization", - "const": "Organization", - "type": "string" - }, - "name": { - "title": "Name", - "description": "Name of the organization that created the media object.", - "type": "string" - }, - "url": { - "title": "URL", - "description": "A URL to the homepage for the organization.", - "minLength": 1, - "maxLength": 2083, - "type": "string", - "pattern": "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$", - "errorMessage": { - "pattern": "must match format \"url\"" - } - }, - "address": { - "title": "Address", - "description": "Full address for the organization - e.g., \u201c8200 Old Main Hill, Logan, UT 84322-8200\u201d.", - "type": "string" - } - }, - "required": [ - "name" - ] } }, "required": [ diff --git a/tests/test_core_schema.py b/tests/test_core_schema.py index 6be4bad..e752f8a 100644 --- a/tests/test_core_schema.py +++ b/tests/test_core_schema.py @@ -63,9 +63,7 @@ async def test_core_schema_creator_cardinality(core_data, core_model, multiple_c ] else: if creator_type == "person": - core_data["creator"] = [ - {"@type": "Person", "name": "John Doe", "email": "john.doe@gmail.com"} - ] + core_data["creator"] = [{"@type": "Person", "name": "John Doe", "email": "john.doe@gmail.com"}] else: core_data["creator"] = [ { @@ -351,9 +349,7 @@ async def test_core_schema_associated_media_cardinality(core_data, core_model, m ], ) @pytest.mark.asyncio -async def test_core_schema_associated_media_content_size( - core_data, core_model, content_size_format -): +async def test_core_schema_associated_media_content_size(core_data, core_model, content_size_format): """Test that a core metadata pydantic model can be created from core metadata json. Purpose of the test is to validate core metadata schema as defined by the pydantic model where we are testing valid values for the contentSize attribute of the associatedMedia property. @@ -376,236 +372,9 @@ async def test_core_schema_associated_media_content_size( # validate the data model core_model_instance = await utils.validate_data_model(core_data, core_model) assert core_model_instance.associatedMedia[0].contentSize == content_size_format - assert core_model_instance.associatedMedia[0].additionalProperty == [] -@pytest.mark.parametrize("set_additional_property", [True, False]) -@pytest.mark.asyncio -async def test_core_schema_associated_media_additional_property( - core_data, core_model, set_additional_property -): - """Test that a core metadata pydantic model can be created from core metadata json. - Purpose of the test is to validate core metadata schema as defined by the pydantic model where we are testing - valid values for the additionalProperty attribute of the associatedMedia property. - Note: This test does not add a record to the database. - """ - - core_data = core_data - core_model = core_model - content_size_format = "100.17 KB" - core_data["associatedMedia"] = [ - { - "@type": "MediaObject", - "contentUrl": "https://www.hydroshare.org/resource/51d1539bf6e94b15ac33f7631228118c/data/contents/USGS_Harvey_gages_TxLaMsAr.csv", - "encodingFormat": "text/csv", - "contentSize": content_size_format, - "name": "USGS gage locations within the Harvey-affected areas in Texas", - } - ] - if set_additional_property: - core_data["associatedMedia"][0]["additionalProperty"] = [ - { - "@type": "PropertyValue", - "name": "Feature Count", - "value": 7, - }, - { - "@type": "PropertyValue", - "name": "Field Count", - "value": 10, - }, - ] - - # validate the data model - core_model_instance = await utils.validate_data_model(core_data, core_model) - assert core_model_instance.associatedMedia[0].contentSize == content_size_format - if set_additional_property: - assert len(core_model_instance.associatedMedia[0].additionalProperty) == 2 - assert ( - core_model_instance.associatedMedia[0].additionalProperty[0].name - == "Feature Count" - ) - assert core_model_instance.associatedMedia[0].additionalProperty[0].value == "7" - assert ( - core_model_instance.associatedMedia[0].additionalProperty[1].name - == "Field Count" - ) - assert core_model_instance.associatedMedia[0].additionalProperty[1].value == '10' - else: - assert core_model_instance.associatedMedia[0].additionalProperty == [] - - -@pytest.mark.parametrize("set_spatial_coverage", [True, False]) -@pytest.mark.parametrize("spatial_coverage_with_additional_property", [True, False]) -@pytest.mark.asyncio -async def test_core_schema_associated_media_spatial_coverage( - core_data, - core_model, - set_spatial_coverage, - spatial_coverage_with_additional_property, -): - """Test that a core metadata pydantic model can be created from core metadata json. - Purpose of the test is to validate core metadata schema as defined by the pydantic model where we are testing - valid values for the spatialCoverage attribute of the associatedMedia property. - Note: This test does not add a record to the database. - """ - - core_data = core_data - core_model = core_model - content_size_format = "100.17 KB" - coverage_value = { - "@type": "Place", - "name": "CUAHSI Office", - "geo": {"@type": "GeoCoordinates", "latitude": 42.4127, "longitude": -71.1197}, - } - core_data["associatedMedia"] = [ - { - "@type": "MediaObject", - "contentUrl": "https://www.hydroshare.org/resource/51d1539bf6e94b15ac33f7631228118c/data/contents/USGS_Harvey_gages_TxLaMsAr.csv", - "encodingFormat": "text/csv", - "contentSize": content_size_format, - "name": "USGS gage locations within the Harvey-affected areas in Texas", - } - ] - if set_spatial_coverage: - core_data["associatedMedia"][0]["spatialCoverage"] = coverage_value - if spatial_coverage_with_additional_property: - core_data["associatedMedia"][0]["spatialCoverage"]["additionalProperty"] = [ - { - "@type": "PropertyValue", - "name": "Geographic Coordinate System", - "value": "WGS 84 EPSG:4326", - }, - ] - - # validate the data model - core_model_instance = await utils.validate_data_model(core_data, core_model) - assert core_model_instance.associatedMedia[0].contentSize == content_size_format - if set_spatial_coverage: - special_coverage = core_model_instance.associatedMedia[0].spatialCoverage - assert special_coverage.type == coverage_value["@type"] - assert special_coverage.name == coverage_value["name"] - geo = special_coverage.geo - assert geo.type == coverage_value["geo"]["@type"] - assert geo.latitude == coverage_value["geo"]["latitude"] - assert geo.longitude == coverage_value["geo"]["longitude"] - if spatial_coverage_with_additional_property: - assert len(core_model_instance.associatedMedia[0].spatialCoverage.additionalProperty) == 1 - additional_property = core_model_instance.associatedMedia[0].spatialCoverage.additionalProperty[0] - assert additional_property.type == "PropertyValue" - assert additional_property.name == "Geographic Coordinate System" - assert additional_property.value == "WGS 84 EPSG:4326" - else: - assert core_model_instance.associatedMedia[0].spatialCoverage.additionalProperty == [] - else: - assert core_model_instance.associatedMedia[0].spatialCoverage is None - - -@pytest.mark.parametrize("set_temporal_coverage", [True, False]) -@pytest.mark.asyncio -async def test_core_schema_associated_media_temporal_coverage( - core_data, core_model, set_temporal_coverage -): - """Test that a core metadata pydantic model can be created from core metadata json. - Purpose of the test is to validate core metadata schema as defined by the pydantic model where we are testing - valid values for the temporalCoverage attribute of the associatedMedia property. - Note: This test does not add a record to the database. - """ - - core_data = core_data - core_model = core_model - content_size_format = "100.17 KB" - coverage_value = { - "startDate": "2007-03-01T13:00:00", - "endDate": "2008-05-11T15:30:00", - } - - core_data["associatedMedia"] = [ - { - "@type": "MediaObject", - "contentUrl": "https://www.hydroshare.org/resource/51d1539bf6e94b15ac33f7631228118c/data/contents/USGS_Harvey_gages_TxLaMsAr.csv", - "encodingFormat": "text/csv", - "contentSize": content_size_format, - "name": "USGS gage locations within the Harvey-affected areas in Texas", - } - ] - if set_temporal_coverage: - core_data["associatedMedia"][0]["temporalCoverage"] = coverage_value - - # validate the data model - core_model_instance = await utils.validate_data_model(core_data, core_model) - assert core_model_instance.associatedMedia[0].contentSize == content_size_format - if set_temporal_coverage: - temporal_coverage = core_model_instance.associatedMedia[0].temporalCoverage - assert temporal_coverage.startDate == datetime.datetime(2007, 3, 1, 13, 0, 0) - assert temporal_coverage.endDate == datetime.datetime(2008, 5, 11, 15, 30, 0) - else: - assert core_model_instance.associatedMedia[0].temporalCoverage is None - - -@pytest.mark.parametrize("set_source_organization", [True, False]) -@pytest.mark.asyncio -async def test_core_schema_associated_media_source_organization( - core_data, core_model, set_source_organization -): - """Test that a core metadata pydantic model can be created from core metadata json. - Purpose of the test is to validate core metadata schema as defined by the pydantic model where we are testing - valid values for the sourceOrganization attribute of the associatedMedia property. - Note: This test does not add a record to the database. - """ - - core_data = core_data - core_model = core_model - content_size_format = "100.17 KB" - source_organization = { - "@type": "Organization", - "name": "National Hydrography Dataset", - "url": "https://www.usgs.gov/national-hydrography/national-hydrography-dataset", - } - - if set_source_organization: - core_data["associatedMedia"] = [ - { - "@type": "MediaObject", - "contentUrl": "https://www.hydroshare.org/resource/51d1539bf6e94b15ac33f7631228118c/data/contents/USGS_Harvey_gages_TxLaMsAr.csv", - "encodingFormat": "text/csv", - "contentSize": content_size_format, - "name": "USGS gage locations within the Harvey-affected areas in Texas", - "sourceOrganization": source_organization, - } - ] - else: - core_data["associatedMedia"] = [ - { - "@type": "MediaObject", - "contentUrl": "https://www.hydroshare.org/resource/51d1539bf6e94b15ac33f7631228118c/data/contents/USGS_Harvey_gages_TxLaMsAr.csv", - "encodingFormat": "text/csv", - "contentSize": content_size_format, - "name": "USGS gage locations within the Harvey-affected areas in Texas", - } - ] - - # validate the data model - core_model_instance = await utils.validate_data_model(core_data, core_model) - assert core_model_instance.associatedMedia[0].contentSize == content_size_format - if set_source_organization: - assert ( - core_model_instance.associatedMedia[0].sourceOrganization.type - == source_organization["@type"] - ) - assert ( - core_model_instance.associatedMedia[0].sourceOrganization.name - == source_organization["name"] - ) - assert ( - core_model_instance.associatedMedia[0].sourceOrganization.url - == source_organization["url"] - ) - else: - assert core_model_instance.associatedMedia[0].sourceOrganization is None - - -@pytest.mark.parametrize("include_coverage", [True, False]) +@pytest.mark.parametrize('include_coverage', [True, False]) @pytest.mark.asyncio async def test_core_schema_temporal_coverage_optional(core_data, core_model, include_coverage): """Test that a core metadata pydantic model can be created from core metadata json. @@ -615,10 +384,7 @@ async def test_core_schema_temporal_coverage_optional(core_data, core_model, inc """ core_data = core_data core_model = core_model - coverage_value = { - "startDate": "2007-03-01T13:00:00", - "endDate": "2008-05-11T15:30:00", - } + coverage_value = {"startDate": "2007-03-01T13:00:00", "endDate": "2008-05-11T15:30:00"} core_data.pop("temporalCoverage", None) if not include_coverage: core_data.pop("temporalCoverage", None) @@ -700,79 +466,35 @@ async def test_core_schema_spatial_coverage_optional(core_data, core_model, incl @pytest.mark.parametrize( - "data_format", + 'data_format', [ - {"@type": "Place", "name": "CUAHSI Office"}, - { - "@type": "Place", - "geo": { - "@type": "GeoCoordinates", - "latitude": 39.3280, - "longitude": 120.1633, - }, - }, { "@type": "Place", - "geo": {"@type": "GeoShape", "box": "39.3280 120.1633 40.445 123.7878"}, + "name": "CUAHSI Office" }, { "@type": "Place", - "name": "Logan Watershed", "geo": { - "@type": "GeoShape", - "box": "41.70049003694901 -111.78438452093438 42.102360645589236 -111.51208495002092", - }, - "additionalProperty": [ - { - "@type": "PropertyValue", - "name": "Geographic Coordinate System", - "value": "WGS 84 EPSG:4326", - }, - { - "@type": "PropertyValue", - "name": "Geographic Coordinate System", - "value": { - "@type": "PropertyValue", - "name": "Coordinate System", - "value": "WGS 84 EPSG:4326", - }, - }, - ], + "@type": "GeoCoordinates", + "latitude": 39.3280, + "longitude": 120.1633 + } }, { "@type": "Place", - "name": "Logan Watershed", "geo": { "@type": "GeoShape", - "box": "41.70049003694901 -111.78438452093438 42.102360645589236 -111.51208495002092", - }, - "additionalProperty": [ - { - "@type": "PropertyValue", - "name": "Projected Coordinate System", - "value": [ - { - "@type": "PropertyValue", - "name": "Coordinate Reference System", - "value": "WGS_1984_UTM_Zone_12N", - }, - { - "@type": "PropertyValue", - "name": "Datum", - "value": "WGS_1984", - }, - ], - }, - ], - }, + "box": "39.3280 120.1633 40.445 123.7878" + } + } ], ) @pytest.mark.asyncio async def test_core_schema_spatial_coverage_value_type(core_data, core_model, data_format): """Test that a core metadata pydantic model can be created from core metadata json. Purpose of the test is to validate core metadata schema as defined by the pydantic model where we are testing - valid values for spatial coverage with optional additionalProperty attribute. - Note: This test does not add a record to the database. + valid values for spatial coverage. + Note: This test does nat add a record to the database. """ core_data = core_data core_model = core_model @@ -788,51 +510,7 @@ async def test_core_schema_spatial_coverage_value_type(core_data, core_model, da assert core_model_instance.spatialCoverage.geo.latitude == data_format["geo"]["latitude"] assert core_model_instance.spatialCoverage.geo.longitude == data_format["geo"]["longitude"] elif data_format["geo"]["@type"] == "GeoShape": - assert ( - core_model_instance.spatialCoverage.geo.box == data_format["geo"]["box"] - ) - if "additionalProperty" in data_format: - if len(core_model_instance.spatialCoverage.additionalProperty) == 1: - assert ( - core_model_instance.spatialCoverage.additionalProperty[0].name - == "Projected Coordinate System" - ) - assert ( - core_model_instance.spatialCoverage.additionalProperty[0].type - == "PropertyValue" - ) - # test that the value of the first item is a PropertyValue object - assert len(core_model_instance.spatialCoverage.additionalProperty[0].value) == 2 - - property_value_obj = core_model_instance.spatialCoverage.additionalProperty[0].value[0] - assert property_value_obj.type == "PropertyValue" - assert property_value_obj.name == "Coordinate Reference System" - assert property_value_obj.value == "WGS_1984_UTM_Zone_12N" - property_value_obj = core_model_instance.spatialCoverage.additionalProperty[0].value[1] - assert property_value_obj.type == "PropertyValue" - assert property_value_obj.name == "Datum" - assert property_value_obj.value == "WGS_1984" - else: - assert len(core_model_instance.spatialCoverage.additionalProperty) == 2 - assert ( - core_model_instance.spatialCoverage.additionalProperty[0].name - == "Geographic Coordinate System" - ) - assert ( - core_model_instance.spatialCoverage.additionalProperty[0].value - == "WGS 84 EPSG:4326" - ) - assert ( - core_model_instance.spatialCoverage.additionalProperty[1].name - == "Geographic Coordinate System" - ) - # test that the value of the 2nd item is a PropertyValue object - property_value_obj = core_model_instance.spatialCoverage.additionalProperty[1].value - assert property_value_obj.type == "PropertyValue" - assert property_value_obj.name == "Coordinate System" - assert property_value_obj.value == "WGS 84 EPSG:4326" - else: - assert core_model_instance.spatialCoverage.additionalProperty == [] + assert core_model_instance.spatialCoverage.geo.box == data_format["geo"]["box"] @pytest.mark.parametrize('include_creative_works', [True, False])