bgneal@937: """Tests for the weblink app signal handlers.""" bgneal@937: bgneal@937: from django.contrib.auth.models import User bgneal@937: from django.test import TestCase bgneal@937: bgneal@937: import custom_search.receivers bgneal@937: bgneal@937: from weblinks.models import Category bgneal@937: from weblinks.models import Link bgneal@937: bgneal@937: bgneal@937: class ReceiverTestCase(TestCase): bgneal@937: bgneal@937: fixtures = ['weblinks_categories.json'] bgneal@937: bgneal@937: def setUp(self): bgneal@937: self.user = User.objects.create_user('user', 'user@example.com', 'pw') bgneal@937: bgneal@937: # Don't let our custom search signal handler class catch any of the bgneal@937: # signals we are throwing here. bgneal@937: custom_search.receivers.signal_processor.teardown() bgneal@937: bgneal@937: def tearDown(self): bgneal@937: custom_search.receivers.signal_processor.setup() bgneal@937: bgneal@937: def test_signal_handlers(self): bgneal@937: bgneal@937: category = Category.objects.get(pk=1) bgneal@937: link = Link(category=category, bgneal@937: title='Title', bgneal@937: url='http://example.com/', bgneal@937: description='Cool stuff', bgneal@937: is_public=True, bgneal@937: user=self.user) bgneal@937: link.save() bgneal@937: bgneal@937: category = Category.objects.get(pk=1) bgneal@937: self.assertEqual(1, category.count) bgneal@937: bgneal@937: category2 = Category.objects.get(pk=4) bgneal@937: link.category = category2 bgneal@937: link.save() bgneal@937: bgneal@937: category = Category.objects.get(pk=1) bgneal@937: self.assertEqual(0, category.count) bgneal@937: category2 = Category.objects.get(pk=4) bgneal@937: self.assertEqual(1, category2.count) bgneal@937: bgneal@937: link.delete() bgneal@937: category2 = Category.objects.get(pk=4) bgneal@937: self.assertEqual(0, category2.count)