-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PB-1158: Add package distribution model
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 5.0.9 on 2024-11-27 08:27 | ||
|
||
import utils.fields | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations | ||
from django.db import models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('distributions', '0006_alter_dataset_slug'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PackageDistribution', | ||
fields=[ | ||
( | ||
'id', | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name='ID' | ||
) | ||
), | ||
('slug', utils.fields.CustomSlugField(max_length=100, verbose_name='Slug')), | ||
( | ||
'managed_by_stac', | ||
models.BooleanField(max_length=100, verbose_name='Managed by STAC') | ||
), | ||
( | ||
'dataset', | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to='distributions.dataset' | ||
) | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/tests/distributions/test_package_distribution_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from distributions.models import Attribution | ||
from distributions.models import Dataset | ||
from distributions.models import PackageDistribution | ||
from provider.models import Provider | ||
from pytest import fixture | ||
from pytest import raises | ||
|
||
from django.core.exceptions import ValidationError | ||
|
||
|
||
@fixture(name='provider') | ||
def fixture_provider(db): | ||
yield Provider.objects.create( | ||
acronym_de="BAFU", | ||
acronym_fr="OFEV", | ||
acronym_en="FOEN", | ||
name_de="Bundesamt für Umwelt", | ||
name_fr="Office fédéral de l'environnement", | ||
name_en="Federal Office for the Environment" | ||
) | ||
|
||
|
||
@fixture(name='attribution') | ||
def fixture_attribution(provider): | ||
yield Attribution.objects.create( | ||
name_de="BAFU", | ||
name_fr="OFEV", | ||
name_en="FOEN", | ||
name_it="UFAM", | ||
name_rm="UFAM", | ||
description_de="Bundesamt für Umwelt", | ||
description_fr="Office fédéral de l'environnement", | ||
description_en="Federal Office for the Environment", | ||
description_it="Ufficio federale dell'ambiente", | ||
description_rm="Uffizi federal per l'ambient", | ||
provider=provider | ||
) | ||
|
||
|
||
@fixture(name='dataset') | ||
def fixture_dataset(provider, attribution): | ||
yield Dataset.objects.create( | ||
slug="ch.agroscope.feuchtflaechenpotential-kulturlandschaft", | ||
provider=provider, | ||
attribution=attribution, | ||
) | ||
|
||
|
||
def test_create_package_distribution_in_database(dataset): | ||
PackageDistribution.objects.create( | ||
slug="ch.agroscope.feuchtflaechenpotential-kulturlandschaft", | ||
managed_by_stac=True, | ||
dataset=dataset | ||
) | ||
|
||
distributions = PackageDistribution.objects.all() | ||
|
||
assert len(distributions) == 1 | ||
|
||
distribution = distributions[0] | ||
|
||
assert distribution.slug == "ch.agroscope.feuchtflaechenpotential-kulturlandschaft" | ||
assert distribution.managed_by_stac is True | ||
assert distribution.dataset == dataset | ||
|
||
|
||
def test_raises_exception_when_creating_db_object_with_mandatory_field_null(dataset): | ||
with raises(ValidationError) as e: | ||
PackageDistribution.objects.create(dataset=dataset) |