# HG changeset patch # User Brian Neal # Date 1737913288 21600 # Node ID 80f206a120272ff39e914e9dbf97463d2471fa30 # Parent 02181fa5ac9d4df51032e92162a4e8990671408d Add unit tests for messages tasks. diff -r 02181fa5ac9d -r 80f206a12027 messages/tests/test_tasks.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messages/tests/test_tasks.py Sun Jan 26 11:41:28 2025 -0600 @@ -0,0 +1,35 @@ +""" +Unit tests for the messages application tasks. + +""" +import datetime + +from django.test import TestCase +from django.contrib.auth.models import User + +from messages.models import Message, Options, Flag +from messages.tasks import purge_messages + + +class PurgeMessagesTaskTestCase(TestCase): + """Testing the purge messages celery task.""" + fixtures = ['messages_test_users.json'] + + def setUp(self): + now = datetime.datetime.now() + pj = User.objects.get(username='pj') + eddie = User.objects.get(username='eddie') + pm = Message(sender=pj, + receiver=eddie, + send_date=now, + read_date=now, + subject='Test', + message='Message', + sender_delete_date=now, + receiver_delete_date=now) + pm.save() + + def test_purge_command(self): + self.assertEqual(Message.objects.all().count(), 1) + task = purge_messages.s().apply() + self.assertEqual(Message.objects.all().count(), 0)