Skip to content

Commit

Permalink
Fix : corrige les tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Sep 30, 2023
1 parent c50e183 commit 7c2b864
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 12 additions & 7 deletions zds/member/tests/views/tests_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7c2b864

Please sign in to comment.