Skip to content

Commit

Permalink
test deleting users now
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Dec 9, 2023
1 parent c058b83 commit 57beeab
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions codeforlife/user/tests/models/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
Created on 08/12/2023 at 15:48:38(+00:00).
"""

from datetime import timedelta
from unittest.mock import patch

from django.test import TestCase
from django.utils import timezone

from ...models import Class, User
from ....tests import ModelTestCase
from ...models import User


class TestAbstract(TestCase):
class TestAbstract(ModelTestCase[User]):
"""
Tests the abstract model inherited by other models.
Expand All @@ -31,9 +32,9 @@ def setUp(self):
self.john_doe = User.objects.get(pk=1)
self.jane_doe = User.objects.get(pk=2)

def test_delete(self):
def test_delete__wait(self):
"""
Deleting a model instance sets its deletion schedule.
Set a model's deletion schedule.
"""

now = timezone.now()
Expand All @@ -44,9 +45,17 @@ def test_delete(self):
assert self.john_doe.delete_after == now + User.delete_wait
assert self.john_doe.last_saved_at == now

def test_objects__delete(self):
def test_delete__now(self):
"""
Deleting a set of models in a query sets their deletion schedule.
Delete a model now.
"""

self.john_doe.delete(wait=timedelta())
self.assert_does_not_exist(self.john_doe)

def test_objects__delete__wait(self):
"""
Set many models deletion schedules.
"""

now = timezone.now()
Expand All @@ -68,6 +77,21 @@ def test_objects__delete(self):
assert self.jane_doe.delete_after == now + User.delete_wait
assert self.jane_doe.last_saved_at == now

def test_objects__delete__now(self):
"""
Delete many models now.
"""

User.objects2.filter(
pk__in=[
self.john_doe.pk,
self.jane_doe.pk,
]
).delete(wait=timedelta())

self.assert_does_not_exist(self.john_doe)
self.assert_does_not_exist(self.jane_doe)

def test_objects__create(self):
"""
Creating a model records when it was first saved.
Expand Down

0 comments on commit 57beeab

Please sign in to comment.