annotate weblinks/tests/test_receivers.py @ 1121:67c839267220

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