Mercurial > public > sg101
comparison weblinks/tests/test_receivers.py @ 937:89e2d00d653c
Add tests for weblinks signal handlers.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 26 Apr 2015 13:59:03 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
936:8b48ec450497 | 937:89e2d00d653c |
---|---|
1 """Tests for the weblink app signal handlers.""" | |
2 | |
3 from django.contrib.auth.models import User | |
4 from django.test import TestCase | |
5 | |
6 import custom_search.receivers | |
7 | |
8 from weblinks.models import Category | |
9 from weblinks.models import Link | |
10 | |
11 | |
12 class ReceiverTestCase(TestCase): | |
13 | |
14 fixtures = ['weblinks_categories.json'] | |
15 | |
16 def setUp(self): | |
17 self.user = User.objects.create_user('user', 'user@example.com', 'pw') | |
18 | |
19 # Don't let our custom search signal handler class catch any of the | |
20 # signals we are throwing here. | |
21 custom_search.receivers.signal_processor.teardown() | |
22 | |
23 def tearDown(self): | |
24 custom_search.receivers.signal_processor.setup() | |
25 | |
26 def test_signal_handlers(self): | |
27 | |
28 category = Category.objects.get(pk=1) | |
29 link = Link(category=category, | |
30 title='Title', | |
31 url='http://example.com/', | |
32 description='Cool stuff', | |
33 is_public=True, | |
34 user=self.user) | |
35 link.save() | |
36 | |
37 category = Category.objects.get(pk=1) | |
38 self.assertEqual(1, category.count) | |
39 | |
40 category2 = Category.objects.get(pk=4) | |
41 link.category = category2 | |
42 link.save() | |
43 | |
44 category = Category.objects.get(pk=1) | |
45 self.assertEqual(0, category.count) | |
46 category2 = Category.objects.get(pk=4) | |
47 self.assertEqual(1, category2.count) | |
48 | |
49 link.delete() | |
50 category2 = Category.objects.get(pk=4) | |
51 self.assertEqual(0, category2.count) |