-
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.
Merge pull request #39 from maykinmedia/38-make-loa-a-required-field-…
…and-set-a-sane-default Make EHerkenningConfiguration.loa required
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
digid_eherkenning/migrations/0004_alter_eherkenningconfiguration_loa.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,46 @@ | ||
# Generated by Django 4.2.4 on 2023-08-15 13:47 | ||
|
||
import digid_eherkenning.choices | ||
from django.db import migrations, models | ||
from ..choices import AssuranceLevels | ||
|
||
|
||
def set_default_loa(apps, schema_editor): | ||
EherkenningConfiguration = apps.get_model( | ||
"digid_eherkenning", "EherkenningConfiguration" | ||
) | ||
EherkenningConfiguration.objects.filter(loa="").update(loa=AssuranceLevels.low_plus) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("digid_eherkenning", "0003_digidconfiguration_artifact_resolve_content_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(set_default_loa), | ||
migrations.AlterField( | ||
model_name="eherkenningconfiguration", | ||
name="loa", | ||
field=models.CharField( | ||
choices=[ | ||
("urn:etoegang:core:assurance-class:loa1", "Non existent (1)"), | ||
("urn:etoegang:core:assurance-class:loa2", "Low (2)"), | ||
("urn:etoegang:core:assurance-class:loa2plus", "Low (2+)"), | ||
("urn:etoegang:core:assurance-class:loa3", "Substantial (3)"), | ||
("urn:etoegang:core:assurance-class:loa4", "High (4)"), | ||
], | ||
default="urn:etoegang:core:assurance-class:loa3", | ||
help_text="Level of Assurance (LoA) to use for all the services.", | ||
max_length=100, | ||
verbose_name="LoA", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="eherkenningconfiguration", | ||
constraint=models.CheckConstraint( | ||
check=models.Q(("loa__in", digid_eherkenning.choices.AssuranceLevels)), | ||
name="valid_loa", | ||
), | ||
), | ||
] |
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
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,32 @@ | ||
from django.db import IntegrityError | ||
|
||
import pytest | ||
|
||
from digid_eherkenning.choices import AssuranceLevels | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_fixing_misconfigured_eherkenning(migrator): | ||
old_state = migrator.apply_initial_migration( | ||
("digid_eherkenning", "0003_digidconfiguration_artifact_resolve_content_type") | ||
) | ||
OldEherkenningConfiguration = old_state.apps.get_model( | ||
"digid_eherkenning", "EherkenningConfiguration" | ||
) | ||
|
||
# misconfigured entry; attribute had default, but also blank=True | ||
OldEherkenningConfiguration(loa="").save() | ||
|
||
new_state = migrator.apply_tested_migration( | ||
("digid_eherkenning", "0004_alter_eherkenningconfiguration_loa") | ||
) | ||
EherkenningConfiguration = new_state.apps.get_model( | ||
"digid_eherkenning", "EherkenningConfiguration" | ||
) | ||
config = EherkenningConfiguration.objects.get() | ||
assert config.loa == AssuranceLevels.low_plus | ||
|
||
# impossible to misconfigure | ||
config.loa = "" | ||
with pytest.raises(IntegrityError): | ||
config.save() |