Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTC-2898 Modify resolution metadata fields #585

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/models/orm/migrations/versions/ef3392e8e054_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""update resolution metadata fields

Revision ID: ef3392e8e054
Revises: d767b6dd2c4c
Create Date: 2024-09-10 14:19:43.424752

"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'ef3392e8e054'
down_revision = 'd767b6dd2c4c'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('dataset_metadata', 'resolution', nullable=True, new_column_name='spatial_resolution')
op.add_column('dataset_metadata', sa.Column('resolution_description', sa.String(), nullable=True))
op.alter_column('version_metadata', 'resolution', nullable=True, new_column_name='spatial_resolution')
op.add_column('version_metadata', sa.Column('resolution_description', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('dataset_metadata', 'spatial_resolution', nullable=True, new_column_name='resolution')
op.drop_column('version_metadata', 'resolution_description')
op.alter_column('version_metadata', 'spatial_resolution', nullable=True, new_column_name='resolution')
op.drop_column('dataset_metadata', 'resolution_description')
# ### end Alembic commands ###
3 changes: 2 additions & 1 deletion app/models/orm/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

class MetadataMixin:
title = db.Column(db.String)
resolution = db.Column(db.Numeric)
spatial_resolution = db.Column(db.Numeric)
resolution_description = db.Column(db.String)
geographic_coverage = db.Column(db.String)
update_frequency = db.Column(db.String)
citation = db.Column(db.String)
Expand Down
6 changes: 4 additions & 2 deletions app/models/pydantic/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@


class CommonMetadata(BaseModel):
resolution: Optional[Union[int, float]]
spatial_resolution: Optional[Union[int, float]]
resolution_description: Optional[str]
geographic_coverage: Optional[str]
update_frequency: Optional[str]
scale: Optional[str]
Expand All @@ -21,7 +22,8 @@ class Config:
schema_extra = {
"examples": [
{
"resolution": 10,
"spatial_resolution": 10,
"resolution_description": "10 meters",
"geographic_coverage": "Amazon Basin",
"update_frequency": "Updated daily, image revisit time every 5 days",
"scale": "regional",
Expand Down
2 changes: 1 addition & 1 deletion tests/crud/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def test_versions(app):
metadata=metadata.dict(by_alias=True),
change_log=[logs.dict(by_alias=True)],
)
assert row.metadata.resolution == version_metadata["resolution"]
assert row.metadata.spatial_resolution == version_metadata["spatial_resolution"]
assert row.change_log[0]["date_time"] == json.loads(logs.json())["date_time"]
assert row.change_log[0]["status"] == logs.dict(by_alias=True)["status"]
assert row.change_log[0]["message"] == logs.dict(by_alias=True)["message"]
Expand Down
9 changes: 6 additions & 3 deletions tests/routes/datasets/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ async def test_versions(async_client: AsyncClient):
assert version_data["data"]["dataset"] == dataset
assert version_data["data"]["version"] == version
assert (
version_data["data"]["metadata"]["resolution"] == version_metadata["resolution"]
version_data["data"]["metadata"]["spatial_resolution"] == version_metadata["spatial_resolution"]
)
assert (
version_data["data"]["metadata"]["resolution_description"] == version_metadata["resolution_description"]
)
assert (
version_data["data"]["metadata"]["content_date_range"]["start_date"]
== version_metadata["content_date_range"]["start_date"]
Expand Down Expand Up @@ -180,8 +183,8 @@ async def test_version_metadata(async_client: AsyncClient):
assert response.status_code == 201

assert (
response.json()["data"]["metadata"]["resolution"]
== version_metadata["resolution"]
response.json()["data"]["metadata"]["spatial_resolution"]
== version_metadata["spatial_resolution"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you fix this case in the deprecated test, maybe also fix the case at line 212 (change resolution to "spatial_resolution", and also probably "title" to "spatial_resolution".

)
assert (
response.json()["data"]["metadata"]["content_date_range"]
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
version_metadata = {
"content_date_range": {"start_date": "2000-01-01", "end_date": "2021-01-01"},
"last_update": "2020-01-03",
"resolution": 10,
"spatial_resolution": 10,
"resolution_description": "10 meters",
}

asset_metadata = {
Expand Down
3 changes: 2 additions & 1 deletion tests_v2/fixtures/metadata/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VERSION_METADATA = {
"content_date_range": {"start_date": "2000-01-01", "end_date": "2021-01-01"},
"last_update": "2020-01-03",
"resolution": 10,
"spatial_resolution": 10,
"resolution_description": "10 meters",
}
Loading