bgneal@938: """Tests for the downloads app signal handlers.""" bgneal@938: bgneal@938: from django.contrib.auth.models import User bgneal@938: from django.test import TestCase bgneal@938: bgneal@938: from mock import Mock bgneal@938: bgneal@938: import custom_search.receivers bgneal@938: bgneal@938: from downloads.models import Category bgneal@938: from downloads.models import Download bgneal@938: from downloads.models import PendingDownload bgneal@938: bgneal@938: bgneal@938: class ReceiverTestCase(TestCase): bgneal@938: bgneal@938: fixtures = ['downloads_categories.json'] bgneal@938: bgneal@938: def setUp(self): bgneal@938: self.user = User.objects.create_user('user', 'user@example.com', 'pw') bgneal@938: bgneal@938: # Don't let our custom search signal handler class catch any of the bgneal@938: # signals we are throwing here. bgneal@938: custom_search.receivers.signal_processor.teardown() bgneal@938: bgneal@938: def tearDown(self): bgneal@938: custom_search.receivers.signal_processor.setup() bgneal@938: bgneal@938: def test_download_signal_handlers(self): bgneal@938: bgneal@938: category = Category.objects.get(pk=1) bgneal@938: dl = Download(category=category, bgneal@938: title='Title', bgneal@938: description='Cool stuff', bgneal@938: is_public=True, bgneal@938: user=self.user, bgneal@938: ip_address='127.0.0.1') bgneal@938: dl.save() bgneal@938: bgneal@938: category = Category.objects.get(pk=1) bgneal@938: self.assertEqual(1, category.count) bgneal@938: bgneal@938: category2 = Category.objects.get(pk=4) bgneal@938: dl.category = category2 bgneal@938: dl.save() bgneal@938: bgneal@938: category = Category.objects.get(pk=1) bgneal@938: self.assertEqual(0, category.count) bgneal@938: category2 = Category.objects.get(pk=4) bgneal@938: self.assertEqual(1, category2.count) bgneal@938: bgneal@938: dl.delete() bgneal@938: category2 = Category.objects.get(pk=4) bgneal@938: self.assertEqual(0, category2.count) bgneal@938: bgneal@938: def test_pending_download_signal_handlers(self): bgneal@938: bgneal@938: category = Category.objects.get(pk=1) bgneal@938: dl = PendingDownload( bgneal@938: category=category, bgneal@938: title='Title', bgneal@938: description='Cool stuff', bgneal@938: user=self.user, bgneal@938: ip_address='127.0.0.1') bgneal@938: dl.save() bgneal@938: bgneal@938: dl.file = Mock() bgneal@938: dl.delete() bgneal@938: bgneal@938: dl.file.delete.assert_called_with(save=False) bgneal@938: