-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛[#226] make digitalAdres betrokkene optional in admin #273
Merged
+73
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/openklant/components/klantinteracties/migrations/0021_alter_digitaaladres_betrokkene.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,26 @@ | ||
# Generated by Django 4.2.15 on 2024-10-22 13:43 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("klantinteracties", "0020_alter_digitaaladres_soort_digitaal_adres"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="digitaaladres", | ||
name="betrokkene", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="'Digitaal Adres' had 'Betrokkene bij klantcontact'", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="klantinteracties.betrokkene", | ||
verbose_name="betrokkene", | ||
), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -5,15 +5,19 @@ | |
from django.urls import reverse | ||
|
||
from django_webtest import WebTest | ||
from maykin_2fa.test import disable_admin_mfa | ||
from webtest import Form, TestResponse | ||
|
||
from openklant.accounts.tests.factories import SuperUserFactory | ||
from openklant.components.klantinteracties.models import DigitaalAdres | ||
from openklant.components.klantinteracties.models.tests.factories.digitaal_adres import ( | ||
DigitaalAdresFactory, | ||
) | ||
from openklant.components.klantinteracties.models.tests.factories.partijen import ( | ||
PartijFactory, | ||
PersoonFactory, | ||
) | ||
from openklant.utils.tests.webtest import add_dynamic_field | ||
|
||
|
||
class PartijAdminTests(WebTest): | ||
|
@@ -90,3 +94,35 @@ def test_search(self): | |
self.assertContains(search_response, digitaal_adres_persoon.get_full_name()) | ||
self.assertNotContains(search_response, nummer_persoon.get_full_name()) | ||
self.assertNotContains(search_response, uuid_persoon.get_full_name()) | ||
|
||
@disable_admin_mfa() | ||
def test_digitaal_adres_inline(self): | ||
""" | ||
Regression test for #226 | ||
|
||
betrokkene should be optional | ||
""" | ||
|
||
SuperUserFactory(username="admin", password="admin") | ||
self._login_user(username="admin", password="admin") | ||
|
||
partij = PartijFactory(soort_partij="persoon", voorkeurs_digitaal_adres=None) | ||
PersoonFactory(partij=partij) | ||
url = reverse("admin:klantinteracties_partij_change", args=[partij.pk]) | ||
|
||
response = self.app.get(url) | ||
|
||
form = response.form | ||
form["digitaaladres_set-TOTAL_FORMS"] = 1 | ||
add_dynamic_field(form, "digitaaladres_set-0-omschrijving", "description") | ||
add_dynamic_field(form, "digitaaladres_set-0-soort_digitaal_adres", "email") | ||
add_dynamic_field(form, "digitaaladres_set-0-adres", "[email protected]") | ||
|
||
response = form.submit() | ||
self.assertEqual(response.status_code, 302) | ||
|
||
adres = DigitaalAdres.objects.get() | ||
|
||
self.assertEqual(adres.omschrijving, "description") | ||
self.assertEqual(adres.adres, "[email protected]") | ||
self.assertIsNone(adres.betrokkene) |
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,10 @@ | ||
from webtest import forms | ||
|
||
|
||
def add_dynamic_field(form: forms.Form, name: str, value: str) -> None: | ||
""" | ||
Helper to add fields to a webtest form that is typically done in JS otherwise. | ||
""" | ||
field = forms.Text(form, "input", name, pos=999, value=value) | ||
form.fields[name] = [field] | ||
form.field_order.append((name, field)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative to having to add these fields, you could maybe create a DigitaalAdres with a factory to ensure the form is there, and then try to save it again without a betrokkene, but either way is fine to me