From e25aa6ce059a304b5d39b482ed7fb2e56d91278b Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Tue, 2 Jun 2026 14:42:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(backend)=20add=20test=20coverage=20fo?= =?UTF-8?q?r=20blank=20sub=20behavior?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the test to document the actual contract without modifying the underlying model behavior. These tests act as non-regression coverage and explicitly assert that users may have a null sub or email. They are intended to document the current behavior of the initial user model rather than evolve or constrain it. Ghost rows have not been reported as an operational issue. For the sake of simplicity, avoid changing the model unless required by a concrete issue or unless the benefits clearly outweigh the added complexity. --- src/backend/core/tests/test_models_users.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/core/tests/test_models_users.py b/src/backend/core/tests/test_models_users.py index cb23cecd..a230a9fd 100644 --- a/src/backend/core/tests/test_models_users.py +++ b/src/backend/core/tests/test_models_users.py @@ -94,3 +94,23 @@ def test_models_users_sub_null_email_null_does_not_prevent_creation(): u1 = factories.UserFactory(sub=None, email=None) u2 = factories.UserFactory(sub=None, email=None) assert u1.pk != u2.pk + + +def test_models_users_sub_can_be_null(): + """sub is nullable: pending users exist before OIDC activation.""" + user = factories.UserFactory(sub=None) + user.refresh_from_db() + assert user.sub is None + + +def test_models_users_sub_null_does_not_prevent_creation(): + """Multiple users can be created with sub=None (pending state).""" + u1 = factories.UserFactory(sub=None) + u2 = factories.UserFactory(sub=None) + assert u1.pk != u2.pk + + +def test_models_users_sub_blank_is_accepted(): + """sub='' passes validation because blank=True; null is preferred but not enforced.""" + user = factories.UserFactory.build(sub="") + user.full_clean()