From 187a5a81b2439f58b7547fe32f277f9a9908f4ea Mon Sep 17 00:00:00 2001 From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com> Date: Sat, 30 Sep 2023 08:07:00 +0200 Subject: [PATCH] Fix : corrige les tests --- zds/member/tests/views/tests_register.py | 19 ++++++++++++------- zds/tutorialv2/models/database.py | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/zds/member/tests/views/tests_register.py b/zds/member/tests/views/tests_register.py index 7e589ab6e6..e56d05a202 100644 --- a/zds/member/tests/views/tests_register.py +++ b/zds/member/tests/views/tests_register.py @@ -80,23 +80,28 @@ def test_register(self): # check if the new user is active. self.assertTrue(User.objects.get(username="firm1").is_active) - def test_unregister(self): - """ - To test that unregistering user is working. - """ - - # test not logged user can't unregister. + def test_unauthenticated_user_cant_unregister(self): + """An unauthenticated user shall not be able to unregister.""" self.client.logout() result = self.client.post(reverse("member-unregister"), {"password": "hostel77"}, follow=False) self.assertEqual(result.status_code, 302) - # test logged user can unregister. + def test_unregister_base_case(self): + """ + An authenticated user shall be able to unregister. + Base case with no content, API keys, etc. attached to the user. + """ user = ProfileFactory() self.client.force_login(user.user) result = self.client.post(reverse("member-unregister"), {"password": "hostel77"}, follow=False) self.assertEqual(result.status_code, 302) self.assertEqual(User.objects.filter(username=user.user.username).count(), 0) + def test_unregister_with_attached_artefacts(self): + """ + Test unregistering a user with many contents, PM, API keys... + """ + # Attach a user at tutorials, articles, topics and private topics. After that, # unregister this user and check that he is well removed in all contents. user = ProfileFactory() diff --git a/zds/tutorialv2/models/database.py b/zds/tutorialv2/models/database.py index 2c1ce81fae..a39153f24e 100644 --- a/zds/tutorialv2/models/database.py +++ b/zds/tutorialv2/models/database.py @@ -294,7 +294,8 @@ def get_validation(self): validation = ( Validation.objects.select_related("validator").filter(content=self).order_by("-date_proposition").first() ) - validation.content = self + if validation is not None: + validation.content = self return validation def is_public(self, sha: str) -> bool: