-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3086] Create data migration to add defaults for ContactFormSubject …
…klant configs
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/open_inwoner/openklant/migrations/0026_contactform_subject_config_default.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,37 @@ | ||
# Generated by Django 4.2.18 on 2025-03-04 13:08 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def set_default_for_klant_config(apps, _): | ||
ContactFormSubject = apps.get_model("openklant", "ContactFormSubject") | ||
ESuiteKlantConfig = apps.get_model("openklant", "ESuiteKlantConfig") | ||
OpenKlant2Config = apps.get_model("openklant", "OpenKlant2Config") | ||
|
||
for contact_form_subject in ContactFormSubject.objects.all(): | ||
contact_form_subject.esuite_config = ESuiteKlantConfig.objects.first() | ||
contact_form_subject.openklant_config = OpenKlant2Config.objects.first() | ||
contact_form_subject.save() | ||
|
||
|
||
def delete_default_for_klant_config(apps, _): | ||
ContactFormSubject = apps.get_model("openklant", "ContactFormSubject") | ||
|
||
for contact_form_subject in ContactFormSubject.objects.all(): | ||
contact_form_subject.esuite_config = None | ||
contact_form_subject.openklant_config = None | ||
contact_form_subject.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("openklant", "0025_esuiteklantconfig_send_klantcontact_confirmation_email"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=set_default_for_klant_config, | ||
reverse_code=delete_default_for_klant_config, | ||
) | ||
] |
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,34 @@ | ||
from open_inwoner.utils.tests.test_migrations import TestSuccessfulMigrations | ||
|
||
|
||
class ContactFormSubjectConfigMigrationTest(TestSuccessfulMigrations): | ||
migrate_from = "0025_esuiteklantconfig_send_klantcontact_confirmation_email" | ||
migrate_to = "0026_contactform_subject_config_default" | ||
app = "openklant" | ||
|
||
def setUpBeforeMigration(self, app): | ||
ContactFormSubject = app.get_model("openklant", "ContactFormSubject") | ||
ESuiteKlantConfig = app.get_model("openklant", "ESuiteKlantConfig") | ||
OpenKlant2Config = app.get_model("openklant", "OpenKlant2Config") | ||
|
||
self.esuite_config_1 = ESuiteKlantConfig.objects.create() | ||
self.esuite_config_2 = ESuiteKlantConfig.objects.create() | ||
self.openklant_config_1 = OpenKlant2Config.objects.create() | ||
self.openklant_config_2 = OpenKlant2Config.objects.create() | ||
|
||
for contact_form_subject in ContactFormSubject.objects.all(): | ||
contact_form_subject.esuite_config = None | ||
contact_form_subject.openklant_config = None | ||
|
||
def test_set_default_config(self): | ||
ContactFormSubject = self.apps.get_model("openklant", "ContactFormSubject") | ||
ESuiteKlantConfig = self.apps.get_model("openklant", "ESuiteKlantConfig") | ||
OpenKlant2Config = self.apps.get_model("openklant", "OpenKlant2Config") | ||
|
||
for contact_form_subject in ContactFormSubject.objects.all(): | ||
self.assertEqual( | ||
contact_form_subject.esuite_config, self.esuite_config_1 | ||
) | ||
self.assertEqual( | ||
contact_form_subject.openklant_config, self.openklant_config_1 | ||
) |