Skip to content

Commit

Permalink
Merge pull request #308 from geoadmin/develop
Browse files Browse the repository at this point in the history
#patch: Release v1.5.1
  • Loading branch information
ltshb authored Jul 9, 2021
2 parents 679b6dd + ad9129a commit 4615209
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/stac_api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def custom_exception_handler(exc, context):

if (
context['request']._request.method.upper() in ["PATCH", "POST", "PUT"] and
'application/json' in context['request']._request.headers['content-type'].lower()
'application/json' in context['request']._request.headers.get('content-type',
'').lower()
):
extra["request.payload"] = context['request'].data

Expand Down
11 changes: 6 additions & 5 deletions app/stac_api/collection_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def _update_summaries_on_asset_delete(self, asset):
if (
not assets.filter(**{
attribute: attribute_value
}).exists() and attribute_value is not None
}).exists() and attribute_value is not None and
attribute_value in self.summaries[key]
):
logger.info(
'Removing %s %s from collection summaries',
Expand Down Expand Up @@ -146,7 +147,7 @@ def _update_summaries_on_asset_insert(self, asset):
self.summaries["geoadmin:variant"].sort()
updated |= True

if asset.proj_epsg and asset.proj_epsg not in self.summaries["proj:epsg"]:
if asset.proj_epsg is not None and asset.proj_epsg not in self.summaries["proj:epsg"]:
logger.info(
'Adds proj:epsg %s to collection summaries',
asset.proj_epsg,
Expand All @@ -161,7 +162,7 @@ def _update_summaries_on_asset_insert(self, asset):
self.summaries["proj:epsg"].sort()
updated |= True

if asset.eo_gsd and not float_in(asset.eo_gsd, self.summaries["eo:gsd"]):
if asset.eo_gsd is not None and not float_in(asset.eo_gsd, self.summaries["eo:gsd"]):
logger.info(
'Adds eo:gsd %s to collection summaries',
asset.proj_epsg,
Expand Down Expand Up @@ -262,7 +263,7 @@ def _update_summaries_proj_epsg_on_update(self, assets, asset, proj_epsg, origin
'''
updated = False

if proj_epsg and proj_epsg not in self.summaries["proj:epsg"]:
if proj_epsg is not None and proj_epsg not in self.summaries["proj:epsg"]:
logger.info(
'Adds proj:epsg value %s from collection summaries',
proj_epsg,
Expand Down Expand Up @@ -319,7 +320,7 @@ def _update_summaries_eo_gsd_on_update(self, assets, asset, eo_gsd, original_eo_
'''
updated = False

if eo_gsd and not float_in(eo_gsd, self.summaries["eo:gsd"]):
if eo_gsd is not None and not float_in(eo_gsd, self.summaries["eo:gsd"]):
logger.info(
'Adds eo:gsd value %s from collection summaries',
eo_gsd,
Expand Down
23 changes: 23 additions & 0 deletions app/stac_api/migrations/0012_auto_20210709_0734.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.10 on 2021-07-09 07:34

from django.db import migrations
from django.db import models

import stac_api.validators


class Migration(migrations.Migration):

dependencies = [
('stac_api', '0011_auto_20210623_0521'),
]

operations = [
migrations.AlterField(
model_name='asset',
name='eo_gsd',
field=models.FloatField(
blank=True, null=True, validators=[stac_api.validators.validate_eo_gsd]
),
),
]
3 changes: 2 additions & 1 deletion app/stac_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from stac_api.validators import MEDIA_TYPES
from stac_api.validators import validate_asset_name
from stac_api.validators import validate_asset_name_with_media_type
from stac_api.validators import validate_eo_gsd
from stac_api.validators import validate_geoadmin_variant
from stac_api.validators import validate_geometry
from stac_api.validators import validate_item_properties_datetimes
Expand Down Expand Up @@ -591,7 +592,7 @@ def filename(self):
)
# here we need to set blank=True otherwise the field is as required in the admin interface
description = models.TextField(blank=True, null=True, default=None)
eo_gsd = models.FloatField(null=True, blank=True)
eo_gsd = models.FloatField(null=True, blank=True, validators=[validate_eo_gsd])

class Language(models.TextChoices):
# pylint: disable=invalid-name
Expand Down
19 changes: 19 additions & 0 deletions app/stac_api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ def validate_geoadmin_variant(variant):
)


def validate_eo_gsd(value):
'''Validate eo:gsd
Args:
value: float
The value to validate
Raise:
ValidationError: When the value is not valid
'''
if value <= 0:
logger.error("Invalid eo:gsd property \"%f\", value must be > 0", value)
raise ValidationError(
_('Invalid eo:gsd "%(eo_gsd)f", '
'value must be a positive number bigger than 0'),
params={'eo_gsd': value},
code="invalid"
)


def validate_link_rel(value):
invalid_rel = [
'self',
Expand Down
24 changes: 24 additions & 0 deletions app/tests/test_asset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ def test_create_asset_valid_geoadmin_variant(self):
db_create=True,
)

def test_create_asset_invalid_eo_gsd(self):
with self.assertRaises(ValidationError, msg="asset with invalid eo:gsd was accepted."):
self.factory.create_asset_sample(
item=self.item,
eo_gsd=0.0,
db_create=True,
)

def test_create_asset_valid_eo_gsd(self):
asset = self.factory.create_asset_sample(item=self.item, eo_gsd=1.33).model
self.collection.refresh_from_db()
self.assertEqual(
self.collection.summaries, {
'eo:gsd': [1.33, 3.4], 'proj:epsg': [2056], 'geoadmin:variant': ['kgrs']
}
)
asset.delete()
self.collection.refresh_from_db()
self.assertEqual(
self.collection.summaries, {
'eo:gsd': [3.4], 'proj:epsg': [2056], 'geoadmin:variant': ['kgrs']
}
)

def test_create_asset_invalid_geoadmin_variant(self):
# try to create an asset with invalid geoadmin variant.
with self.assertRaises(
Expand Down
9 changes: 3 additions & 6 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ env:
phases:
install:
runtime-versions:
docker: 18
python: 3.7
commands:
- echo "Installing necessary dependencies"
- apt-get update && apt-get install -y docker-compose python3-pip python3-venv gdal-bin pass gnupg2
- echo "Install aws cli v2 for docker login to ECR registry"
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- ./aws/install
- apt-get update
- apt-get install -y gdal-bin
- aws --version
- echo "Login to AWS ECR docker registry"
- aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${REGISTRY}
Expand Down

0 comments on commit 4615209

Please sign in to comment.