annotate downloads/tests/test_receivers.py @ 989:2908859c2fe4

Smilies now use relative links. This is for upcoming switch to SSL. Currently we do not need absolute URLs for smilies. If this changes we can add it later.
author Brian Neal <bgneal@gmail.com>
date Thu, 29 Oct 2015 20:54:34 -0500
parents 9f9e50df5b83
children
rev   line source
bgneal@938 1 """Tests for the downloads app signal handlers."""
bgneal@938 2
bgneal@938 3 from django.contrib.auth.models import User
bgneal@938 4 from django.test import TestCase
bgneal@938 5
bgneal@938 6 from mock import Mock
bgneal@938 7
bgneal@938 8 import custom_search.receivers
bgneal@938 9
bgneal@938 10 from downloads.models import Category
bgneal@938 11 from downloads.models import Download
bgneal@938 12 from downloads.models import PendingDownload
bgneal@938 13
bgneal@938 14
bgneal@938 15 class ReceiverTestCase(TestCase):
bgneal@938 16
bgneal@938 17 fixtures = ['downloads_categories.json']
bgneal@938 18
bgneal@938 19 def setUp(self):
bgneal@938 20 self.user = User.objects.create_user('user', 'user@example.com', 'pw')
bgneal@938 21
bgneal@938 22 # Don't let our custom search signal handler class catch any of the
bgneal@938 23 # signals we are throwing here.
bgneal@938 24 custom_search.receivers.signal_processor.teardown()
bgneal@938 25
bgneal@938 26 def tearDown(self):
bgneal@938 27 custom_search.receivers.signal_processor.setup()
bgneal@938 28
bgneal@938 29 def test_download_signal_handlers(self):
bgneal@938 30
bgneal@938 31 category = Category.objects.get(pk=1)
bgneal@938 32 dl = Download(category=category,
bgneal@938 33 title='Title',
bgneal@938 34 description='Cool stuff',
bgneal@938 35 is_public=True,
bgneal@938 36 user=self.user,
bgneal@938 37 ip_address='127.0.0.1')
bgneal@938 38 dl.save()
bgneal@938 39
bgneal@938 40 category = Category.objects.get(pk=1)
bgneal@938 41 self.assertEqual(1, category.count)
bgneal@938 42
bgneal@938 43 category2 = Category.objects.get(pk=4)
bgneal@938 44 dl.category = category2
bgneal@938 45 dl.save()
bgneal@938 46
bgneal@938 47 category = Category.objects.get(pk=1)
bgneal@938 48 self.assertEqual(0, category.count)
bgneal@938 49 category2 = Category.objects.get(pk=4)
bgneal@938 50 self.assertEqual(1, category2.count)
bgneal@938 51
bgneal@938 52 dl.delete()
bgneal@938 53 category2 = Category.objects.get(pk=4)
bgneal@938 54 self.assertEqual(0, category2.count)
bgneal@938 55
bgneal@938 56 def test_pending_download_signal_handlers(self):
bgneal@938 57
bgneal@938 58 category = Category.objects.get(pk=1)
bgneal@938 59 dl = PendingDownload(
bgneal@938 60 category=category,
bgneal@938 61 title='Title',
bgneal@938 62 description='Cool stuff',
bgneal@938 63 user=self.user,
bgneal@938 64 ip_address='127.0.0.1')
bgneal@938 65 dl.save()
bgneal@938 66
bgneal@938 67 dl.file = Mock()
bgneal@938 68 dl.delete()
bgneal@938 69
bgneal@938 70 dl.file.delete.assert_called_with(save=False)
bgneal@938 71