Skip to content

Commit

Permalink
Merge pull request #881 from maykinmedia/issue/1889-remove-null-from-…
Browse files Browse the repository at this point in the history
…user-charfields

♻️ [#1889] Remove null=True from User CharFields
  • Loading branch information
alextreme authored Dec 7, 2023
2 parents 802433f + 1bca867 commit 59dc8af
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
47 changes: 47 additions & 0 deletions src/open_inwoner/accounts/migrations/0070_auto_20231205_1657.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
10 changes: 6 additions & 4 deletions src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 4 additions & 4 deletions src/open_inwoner/contrib/kvk/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59dc8af

Please sign in to comment.