-
Notifications
You must be signed in to change notification settings - Fork 3
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 #54 from maykinmedia/issue-53-optional-klantnummer
[#53] Making klantnummer optional and auto-generating klantnummer if not provided
- Loading branch information
Showing
4 changed files
with
158 additions
and
2 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 |
---|---|---|
|
@@ -348,6 +348,110 @@ def test_create_klant_website_url_optional(self): | |
self.assertEqual(klant.bronorganisatie, "950428139") | ||
self.assertEqual(klant.website_url, "") | ||
|
||
def test_create_klant_website_url_optional_klantnummer(self): | ||
list_url = reverse(Klant) | ||
data = { | ||
"bronorganisatie": "950428139", | ||
"voornaam": "Xavier", | ||
"achternaam": "Jackson", | ||
"emailadres": "[email protected]", | ||
"adres": { | ||
"straatnaam": "Keizersgracht", | ||
"huisnummer": "117", | ||
"huisletter": "A", | ||
"postcode": "1015CJ", | ||
"woonplaatsnaam": "test", | ||
"landcode": "1234", | ||
}, | ||
"subjectType": KlantType.natuurlijk_persoon, | ||
"subject": SUBJECT, | ||
} | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(SUBJECT, json={}) | ||
response = self.client.post(list_url, data) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
klant = Klant.objects.get() | ||
|
||
self.assertEqual(klant.bronorganisatie, "950428139") | ||
self.assertEqual(klant.website_url, "") | ||
self.assertEqual(klant.klantnummer, "1") | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(SUBJECT, json={}) | ||
response = self.client.post(list_url, data) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
klant = Klant.objects.get(klantnummer__gt=1) | ||
self.assertEqual(klant.klantnummer, "2") | ||
|
||
def test_create_klant_website_url_duplicate_klantnummer(self): | ||
list_url = reverse(Klant) | ||
data = { | ||
"bronorganisatie": "950428139", | ||
"subjectType": KlantType.natuurlijk_persoon, | ||
"klantnummer": "123", | ||
"subject": SUBJECT, | ||
} | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(SUBJECT, json={}) | ||
response = self.client.post(list_url, data) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
klant = Klant.objects.get() | ||
|
||
self.assertEqual(klant.bronorganisatie, "950428139") | ||
self.assertEqual(klant.website_url, "") | ||
self.assertEqual(klant.klantnummer, "123") | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(SUBJECT, json={}) | ||
response = self.client.post(list_url, data) | ||
|
||
self.assertEqual(response.status_code, 409) | ||
klant = Klant.objects.get() | ||
|
||
def test_create_klant_website_url_invalid_klantnummer(self): | ||
list_url = reverse(Klant) | ||
data = { | ||
"bronorganisatie": "950428139", | ||
"subjectType": KlantType.natuurlijk_persoon, | ||
"klantnummer": "123456789", | ||
"subject": SUBJECT, | ||
} | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(SUBJECT, json={}) | ||
response = self.client.post(list_url, data) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
|
||
klanten = Klant.objects.all() | ||
|
||
self.assertFalse(klanten) | ||
|
||
data = { | ||
"bronorganisatie": "950428139", | ||
"subjectType": KlantType.natuurlijk_persoon, | ||
"klantnummer": "KLANT1", | ||
"subject": SUBJECT, | ||
} | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(SUBJECT, json={}) | ||
response = self.client.post(list_url, data) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
|
||
klanten = Klant.objects.all() | ||
|
||
self.assertFalse(klanten) | ||
|
||
def test_create_klant_natuurlijkpersoon(self): | ||
list_url = reverse(Klant) | ||
data = { | ||
|
32 changes: 32 additions & 0 deletions
32
src/openklant/components/klanten/migrations/0005_auto_20230905_1215.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,32 @@ | ||
# Generated by Django 3.2.18 on 2023-09-05 12:15 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("klanten", "0004_klant_geverifieerd"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="klant", | ||
name="klantnummer", | ||
field=models.CharField( | ||
help_text="De unieke identificatie van de klant binnen de bronorganisatie.", | ||
max_length=8, | ||
validators=[ | ||
django.core.validators.RegexValidator( | ||
code="only-digits", | ||
message="Waarde moet numeriek zijn.", | ||
regex="^[0-9]+$", | ||
) | ||
], | ||
), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name="klant", | ||
unique_together=set(), | ||
), | ||
] |
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