annotate messages/tests/test_tasks.py @ 1207:80f206a12027 modernize tip

Add unit tests for messages tasks.
author Brian Neal <bgneal@gmail.com>
date Sun, 26 Jan 2025 11:41:28 -0600
parents
children
rev   line source
bgneal@1207 1 """
bgneal@1207 2 Unit tests for the messages application tasks.
bgneal@1207 3
bgneal@1207 4 """
bgneal@1207 5 import datetime
bgneal@1207 6
bgneal@1207 7 from django.test import TestCase
bgneal@1207 8 from django.contrib.auth.models import User
bgneal@1207 9
bgneal@1207 10 from messages.models import Message, Options, Flag
bgneal@1207 11 from messages.tasks import purge_messages
bgneal@1207 12
bgneal@1207 13
bgneal@1207 14 class PurgeMessagesTaskTestCase(TestCase):
bgneal@1207 15 """Testing the purge messages celery task."""
bgneal@1207 16 fixtures = ['messages_test_users.json']
bgneal@1207 17
bgneal@1207 18 def setUp(self):
bgneal@1207 19 now = datetime.datetime.now()
bgneal@1207 20 pj = User.objects.get(username='pj')
bgneal@1207 21 eddie = User.objects.get(username='eddie')
bgneal@1207 22 pm = Message(sender=pj,
bgneal@1207 23 receiver=eddie,
bgneal@1207 24 send_date=now,
bgneal@1207 25 read_date=now,
bgneal@1207 26 subject='Test',
bgneal@1207 27 message='Message',
bgneal@1207 28 sender_delete_date=now,
bgneal@1207 29 receiver_delete_date=now)
bgneal@1207 30 pm.save()
bgneal@1207 31
bgneal@1207 32 def test_purge_command(self):
bgneal@1207 33 self.assertEqual(Message.objects.all().count(), 1)
bgneal@1207 34 task = purge_messages.s().apply()
bgneal@1207 35 self.assertEqual(Message.objects.all().count(), 0)