Skip to content

Commit

Permalink
TP2000-143: 500 on Measure Detail view (#497)
Browse files Browse the repository at this point in the history
* add custom sid validation in Measure.clean and call full_clean in Measure.save

* add vanilla UniqueIdentifyingFields business rule to models with sid as only identifying field

* specify markupsafe version

* remove uniqueidentifyingfields where rule already exists
  • Loading branch information
gabelton authored and kintisheff committed Feb 21, 2022
1 parent 0c077e0 commit df62e18
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions additional_codes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from additional_codes import business_rules
from additional_codes import validators
from common.business_rules import UniqueIdentifyingFields
from common.business_rules import UpdateValidity
from common.fields import LongDescription
from common.fields import ShortDescription
Expand Down Expand Up @@ -91,6 +92,7 @@ class AdditionalCode(TrackedModel, ValidityMixin, DescribedMixin):
business_rules.ACN14,
business_rules.ACN17,
UpdateValidity,
UniqueIdentifyingFields,
)

def __str__(self):
Expand Down
5 changes: 3 additions & 2 deletions commodities/models/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from commodities import business_rules
from commodities import validators
from commodities.querysets import GoodsNomenclatureIndentQuerySet
from common.business_rules import UniqueIdentifyingFields
from common.business_rules import UpdateValidity
from common.fields import LongDescription
from common.models import NumericSID
Expand Down Expand Up @@ -250,7 +251,7 @@ class GoodsNomenclatureIndent(TrackedModel, ValidityStartMixin):
)

indirect_business_rules = (business_rules.NIG11,)
business_rules = (business_rules.NIG2, UpdateValidity)
business_rules = (business_rules.NIG2, UniqueIdentifyingFields, UpdateValidity)

validity_over = "indented_goods_nomenclature"

Expand Down Expand Up @@ -329,7 +330,7 @@ class GoodsNomenclatureDescription(DescriptionMixin, TrackedModel):
description = LongDescription()

indirect_business_rules = (business_rules.NIG12,)
business_rules = (UpdateValidity,)
business_rules = (UniqueIdentifyingFields, UpdateValidity)

class Meta:
ordering = ("validity_start",)
Expand Down
2 changes: 2 additions & 0 deletions common/models/mixins/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.urls import reverse

from common.business_rules import NoBlankDescription
from common.business_rules import UniqueIdentifyingFields
from common.business_rules import UpdateValidity
from common.exceptions import NoDescriptionError
from common.models.managers import TrackedModelManager
Expand All @@ -22,6 +23,7 @@ class DescriptionMixin(ValidityStartMixin):

business_rules = (
NoBlankDescription,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down
2 changes: 2 additions & 0 deletions geo_areas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models import Q
from polymorphic.managers import PolymorphicManager

from common.business_rules import UniqueIdentifyingFields
from common.business_rules import UpdateValidity
from common.fields import ShortDescription
from common.fields import SignedIntSID
Expand Down Expand Up @@ -84,6 +85,7 @@ class GeographicalArea(TrackedModel, ValidityMixin, DescribedMixin):
business_rules.GA11,
business_rules.GA21,
business_rules.GA22,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down
5 changes: 4 additions & 1 deletion measures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.db import models

from common.business_rules import UniqueIdentifyingFields
from common.business_rules import UpdateValidity
from common.fields import ApplicabilityCode
from common.fields import ShortDescription
Expand Down Expand Up @@ -218,7 +219,7 @@ class DutyExpression(TrackedModel, ValidityMixin):
business_rules.ME111,
)

business_rules = (UpdateValidity,)
business_rules = (UniqueIdentifyingFields, UpdateValidity)


class MeasureType(TrackedModel, ValidityMixin):
Expand Down Expand Up @@ -534,6 +535,7 @@ class Measure(TrackedModel, ValidityMixin):
business_rules.ME110,
business_rules.ME111,
business_rules.ME104,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down Expand Up @@ -828,6 +830,7 @@ class MeasureCondition(TrackedModel):
business_rules.ME62,
business_rules.ME63,
business_rules.ME64,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down
8 changes: 8 additions & 0 deletions measures/tests/test_business_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db import DataError

from common.business_rules import BusinessRuleViolation
from common.business_rules import UniqueIdentifyingFields
from common.tests import factories
from common.tests.factories import date_ranges
from common.tests.factories import end_date
Expand Down Expand Up @@ -1928,3 +1929,10 @@ def test_measurement_unit_qualifier_is_optional():
"""In TARIC measurement unit qualifiers do not have to be used on every
measure."""
factories.MeasurementFactory.create(measurement_unit_qualifier=None)


def test_unique_identifying_fields(assert_handles_duplicates):
assert_handles_duplicates(
factories.MeasureFactory,
UniqueIdentifyingFields,
)
8 changes: 6 additions & 2 deletions quotas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models

from common.business_rules import UniqueIdentifyingFields
from common.business_rules import UpdateValidity
from common.fields import ShortDescription
from common.fields import SignedIntSID
Expand Down Expand Up @@ -67,6 +68,7 @@ class QuotaOrderNumber(TrackedModel, ValidityMixin):
business_rules.ON2,
business_rules.ON9,
business_rules.ON11,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down Expand Up @@ -119,6 +121,7 @@ class QuotaOrderNumberOrigin(TrackedModel, ValidityMixin):
business_rules.ON7,
business_rules.ON10,
business_rules.ON12,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down Expand Up @@ -222,6 +225,7 @@ class QuotaDefinition(TrackedModel, ValidityMixin):
business_rules.QuotaAssociationMustReferToANonDeletedSubQuota,
business_rules.QuotaSuspensionMustReferToANonDeletedQuotaDefinition,
business_rules.QuotaBlockingPeriodMustReferToANonDeletedQuotaDefinition,
UniqueIdentifyingFields,
UpdateValidity,
)

Expand Down Expand Up @@ -298,7 +302,7 @@ class QuotaSuspension(TrackedModel, ValidityMixin):
quota_definition = models.ForeignKey(QuotaDefinition, on_delete=models.PROTECT)
description = ShortDescription()

business_rules = (business_rules.QSP2, UpdateValidity)
business_rules = (business_rules.QSP2, UniqueIdentifyingFields, UpdateValidity)


class QuotaBlocking(TrackedModel, ValidityMixin):
Expand All @@ -316,7 +320,7 @@ class QuotaBlocking(TrackedModel, ValidityMixin):
)
description = ShortDescription()

business_rules = (business_rules.QBP2, UpdateValidity)
business_rules = (business_rules.QBP2, UniqueIdentifyingFields, UpdateValidity)


class QuotaEvent(TrackedModel):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ govuk-tech-docs-sphinx-theme==1.0.0
gunicorn==20.0.4
Jinja2==2.11.3
lxml==4.6.5
markupsafe==2.0.1
moto==2.1.0
openpyxl==3.0.7
parsec==3.8
Expand Down

0 comments on commit df62e18

Please sign in to comment.