Mercurial > public > sg101
comparison downloads/tests/test_receivers.py @ 938:9f9e50df5b83
Add tests for downloads signal handlers.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 28 Apr 2015 21:22:42 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
937:89e2d00d653c | 938:9f9e50df5b83 |
---|---|
1 """Tests for the downloads app signal handlers.""" | |
2 | |
3 from django.contrib.auth.models import User | |
4 from django.test import TestCase | |
5 | |
6 from mock import Mock | |
7 | |
8 import custom_search.receivers | |
9 | |
10 from downloads.models import Category | |
11 from downloads.models import Download | |
12 from downloads.models import PendingDownload | |
13 | |
14 | |
15 class ReceiverTestCase(TestCase): | |
16 | |
17 fixtures = ['downloads_categories.json'] | |
18 | |
19 def setUp(self): | |
20 self.user = User.objects.create_user('user', 'user@example.com', 'pw') | |
21 | |
22 # Don't let our custom search signal handler class catch any of the | |
23 # signals we are throwing here. | |
24 custom_search.receivers.signal_processor.teardown() | |
25 | |
26 def tearDown(self): | |
27 custom_search.receivers.signal_processor.setup() | |
28 | |
29 def test_download_signal_handlers(self): | |
30 | |
31 category = Category.objects.get(pk=1) | |
32 dl = Download(category=category, | |
33 title='Title', | |
34 description='Cool stuff', | |
35 is_public=True, | |
36 user=self.user, | |
37 ip_address='127.0.0.1') | |
38 dl.save() | |
39 | |
40 category = Category.objects.get(pk=1) | |
41 self.assertEqual(1, category.count) | |
42 | |
43 category2 = Category.objects.get(pk=4) | |
44 dl.category = category2 | |
45 dl.save() | |
46 | |
47 category = Category.objects.get(pk=1) | |
48 self.assertEqual(0, category.count) | |
49 category2 = Category.objects.get(pk=4) | |
50 self.assertEqual(1, category2.count) | |
51 | |
52 dl.delete() | |
53 category2 = Category.objects.get(pk=4) | |
54 self.assertEqual(0, category2.count) | |
55 | |
56 def test_pending_download_signal_handlers(self): | |
57 | |
58 category = Category.objects.get(pk=1) | |
59 dl = PendingDownload( | |
60 category=category, | |
61 title='Title', | |
62 description='Cool stuff', | |
63 user=self.user, | |
64 ip_address='127.0.0.1') | |
65 dl.save() | |
66 | |
67 dl.file = Mock() | |
68 dl.delete() | |
69 | |
70 dl.file.delete.assert_called_with(save=False) | |
71 |