From 1bca8674676930d150a2b8b76442ff2a882586ff Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 5 Dec 2023 16:58:24 +0100 Subject: [PATCH] :recycle: [#1889] Remove null=True from User CharFields task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1889 --- .../migrations/0070_auto_20231205_1657.py | 47 +++++++++++++++++++ src/open_inwoner/accounts/models.py | 10 ++-- .../contrib/kvk/tests/test_signals.py | 8 ++-- .../openzaak/tests/test_case_detail.py | 2 +- 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 src/open_inwoner/accounts/migrations/0070_auto_20231205_1657.py diff --git a/src/open_inwoner/accounts/migrations/0070_auto_20231205_1657.py b/src/open_inwoner/accounts/migrations/0070_auto_20231205_1657.py new file mode 100644 index 0000000000..ff1fdfd198 --- /dev/null +++ b/src/open_inwoner/accounts/migrations/0070_auto_20231205_1657.py @@ -0,0 +1,47 @@ +# Generated by Django 3.2.20 on 2023-12-05 15:57 + +from django.db import migrations, models +import localflavor.nl.models +import open_inwoner.utils.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0069_alter_user_postcode"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="bsn", + field=localflavor.nl.models.NLBSNField( + blank=True, default="", max_length=12, verbose_name="Bsn" + ), + ), + migrations.AlterField( + model_name="user", + name="company_name", + field=models.CharField( + blank=True, default="", max_length=250, verbose_name="Company name" + ), + ), + migrations.AlterField( + model_name="user", + name="kvk", + field=models.CharField( + blank=True, + default="", + max_length=8, + validators=[open_inwoner.utils.validators.validate_kvk], + verbose_name="KvK number", + ), + ), + migrations.AlterField( + model_name="user", + name="rsin", + field=models.CharField( + blank=True, default="", max_length=9, verbose_name="Rsin" + ), + ), + ] diff --git a/src/open_inwoner/accounts/models.py b/src/open_inwoner/accounts/models.py index a7b146297e..7949183b0a 100644 --- a/src/open_inwoner/accounts/models.py +++ b/src/open_inwoner/accounts/models.py @@ -121,17 +121,19 @@ class User(AbstractBaseUser, PermissionsMixin): ) # TODO shouldn't rsin & bsn be unique? (possibly fixed in model constraints) # TODO fix rsin & bsn to not be both null AND blank (!) - rsin = models.CharField(verbose_name=_("Rsin"), max_length=9, null=True, blank=True) - bsn = NLBSNField(verbose_name=_("Bsn"), null=True, blank=True) + rsin = models.CharField( + verbose_name=_("Rsin"), max_length=9, blank=True, default="" + ) + bsn = NLBSNField(verbose_name=_("Bsn"), blank=True, default="") kvk = models.CharField( verbose_name=_("KvK number"), max_length=8, - null=True, blank=True, + default="", validators=[validate_kvk], ) company_name = models.CharField( - verbose_name=_("Company name"), max_length=250, null=True, blank=True + verbose_name=_("Company name"), max_length=250, blank=True, default="" ) login_type = models.CharField( verbose_name=_("Login type"), diff --git a/src/open_inwoner/contrib/kvk/tests/test_signals.py b/src/open_inwoner/contrib/kvk/tests/test_signals.py index a83dc6cf4d..f29c0065a2 100644 --- a/src/open_inwoner/contrib/kvk/tests/test_signals.py +++ b/src/open_inwoner/contrib/kvk/tests/test_signals.py @@ -59,7 +59,7 @@ def test_user_is_not_updated_when_not_logged_in_via_eherkenning(self, m): user.refresh_from_db() - self.assertEqual(user.rsin, None) + self.assertEqual(user.rsin, "") self.assertFalse(user.is_prepopulated) def test_empty_response_from_kvk(self, m): @@ -74,7 +74,7 @@ def test_empty_response_from_kvk(self, m): user.refresh_from_db() - self.assertEqual(user.rsin, None) + self.assertEqual(user.rsin, "") self.assertFalse(user.is_prepopulated) def test_user_is_not_updated_when_http_404(self, m): @@ -88,7 +88,7 @@ def test_user_is_not_updated_when_http_404(self, m): user = UserModel.eherkenning_objects.eherkenning_create("69599084") user.refresh_from_db() - self.assertEqual(user.rsin, None) + self.assertEqual(user.rsin, "") self.assertFalse(user.is_prepopulated) def test_user_is_not_updated_when_http_500(self, m): @@ -102,7 +102,7 @@ def test_user_is_not_updated_when_http_500(self, m): user = UserModel.eherkenning_objects.eherkenning_create("69599084") user.refresh_from_db() - self.assertEqual(user.rsin, None) + self.assertEqual(user.rsin, "") self.assertFalse(user.is_prepopulated) diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index 6a7323e1a5..d2e3877f4c 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -834,7 +834,7 @@ def test_no_access_if_fetch_eherkenning_zaken_with_rsin_and_user_has_no_rsin( self.config.fetch_eherkenning_zaken_with_rsin = True self.config.save() - self.eherkenning_user.rsin = None + self.eherkenning_user.rsin = "" self.eherkenning_user.save() response = self.app.get(self.case_detail_url, user=self.eherkenning_user)