from django.test import TestCase

from django_celery_beat.models import IntervalSchedule, PeriodicTask

from newsreader.accounts.tests.factories import UserFactory


class UserTestCase(TestCase):
    def test_task_is_deleted(self):
        user = UserFactory(email="durp@burp.nl")

        interval = IntervalSchedule.objects.create(
            every=1, period=IntervalSchedule.HOURS
        )
        PeriodicTask.objects.create(
            name=f"{user.email}-feed", task="FeedTask", interval=interval
        )

        user.delete()

        self.assertEquals(PeriodicTask.objects.count(), 0)
