changeset 937:89e2d00d653c

Add tests for weblinks signal handlers.
author Brian Neal <bgneal@gmail.com>
date Sun, 26 Apr 2015 13:59:03 -0500 (2015-04-26)
parents 8b48ec450497
children 9f9e50df5b83
files weblinks/tests/__init__.py weblinks/tests/test_receivers.py
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/weblinks/tests/test_receivers.py	Sun Apr 26 13:59:03 2015 -0500
@@ -0,0 +1,51 @@
+"""Tests for the weblink app signal handlers."""
+
+from django.contrib.auth.models import User
+from django.test import TestCase
+
+import custom_search.receivers
+
+from weblinks.models import Category
+from weblinks.models import Link
+
+
+class ReceiverTestCase(TestCase):
+
+    fixtures = ['weblinks_categories.json']
+
+    def setUp(self):
+        self.user = User.objects.create_user('user', 'user@example.com', 'pw')
+
+        # Don't let our custom search signal handler class catch any of the
+        # signals we are throwing here.
+        custom_search.receivers.signal_processor.teardown()
+
+    def tearDown(self):
+        custom_search.receivers.signal_processor.setup()
+
+    def test_signal_handlers(self):
+
+        category = Category.objects.get(pk=1)
+        link = Link(category=category,
+                    title='Title',
+                    url='http://example.com/',
+                    description='Cool stuff',
+                    is_public=True,
+                    user=self.user)
+        link.save()
+
+        category = Category.objects.get(pk=1)
+        self.assertEqual(1, category.count)
+
+        category2 = Category.objects.get(pk=4)
+        link.category = category2
+        link.save()
+
+        category = Category.objects.get(pk=1)
+        self.assertEqual(0, category.count)
+        category2 = Category.objects.get(pk=4)
+        self.assertEqual(1, category2.count)
+
+        link.delete()
+        category2 = Category.objects.get(pk=4)
+        self.assertEqual(0, category2.count)