Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
1206:02181fa5ac9d | 1207:80f206a12027 |
---|---|
1 """ | |
2 Unit tests for the messages application tasks. | |
3 | |
4 """ | |
5 import datetime | |
6 | |
7 from django.test import TestCase | |
8 from django.contrib.auth.models import User | |
9 | |
10 from messages.models import Message, Options, Flag | |
11 from messages.tasks import purge_messages | |
12 | |
13 | |
14 class PurgeMessagesTaskTestCase(TestCase): | |
15 """Testing the purge messages celery task.""" | |
16 fixtures = ['messages_test_users.json'] | |
17 | |
18 def setUp(self): | |
19 now = datetime.datetime.now() | |
20 pj = User.objects.get(username='pj') | |
21 eddie = User.objects.get(username='eddie') | |
22 pm = Message(sender=pj, | |
23 receiver=eddie, | |
24 send_date=now, | |
25 read_date=now, | |
26 subject='Test', | |
27 message='Message', | |
28 sender_delete_date=now, | |
29 receiver_delete_date=now) | |
30 pm.save() | |
31 | |
32 def test_purge_command(self): | |
33 self.assertEqual(Message.objects.all().count(), 1) | |
34 task = purge_messages.s().apply() | |
35 self.assertEqual(Message.objects.all().count(), 0) |