annotate messages/tests/test_views.py @ 811:56b30c79f10e

Private messages refactor: start adding tests.
author Brian Neal <bgneal@gmail.com>
date Sun, 07 Sep 2014 13:12:19 -0500
parents
children 42436d674ba8
rev   line source
bgneal@811 1 """
bgneal@811 2 Unit tests for the messages application views.
bgneal@811 3
bgneal@811 4 """
bgneal@811 5 from django.test import TestCase
bgneal@811 6 from django.core.urlresolvers import reverse
bgneal@811 7
bgneal@811 8 from messages.models import Message, Options, Flag
bgneal@811 9
bgneal@811 10
bgneal@811 11 VIEW_NAMES = [
bgneal@811 12 'messages-inbox',
bgneal@811 13 'messages-compose',
bgneal@811 14 'messages-outbox',
bgneal@811 15 'messages-trash',
bgneal@811 16 'messages-options',
bgneal@811 17 'messages-delete',
bgneal@811 18 'messages-undelete',
bgneal@811 19 'messages-view',
bgneal@811 20 'messages-report',
bgneal@811 21 ]
bgneal@811 22
bgneal@811 23
bgneal@811 24 class NotLoggedInTestCase(TestCase):
bgneal@811 25 """Ensure we are redirected to the login page before we can do anything with
bgneal@811 26 this application.
bgneal@811 27
bgneal@811 28 """
bgneal@811 29 LOGIN_URL = reverse('accounts-login')
bgneal@811 30
bgneal@811 31 def _test_get(self, url_name, **kwargs):
bgneal@811 32 url = reverse(url_name, **kwargs)
bgneal@811 33 response = self.client.get(url, follow=True)
bgneal@811 34 self.assertRedirects(response, self.LOGIN_URL + '?next=' + url)
bgneal@811 35
bgneal@811 36 def _test_post(self, url_name, **kwargs):
bgneal@811 37 url = reverse(url_name, **kwargs)
bgneal@811 38 response = self.client.post(url, follow=True)
bgneal@811 39 self.assertRedirects(response, self.LOGIN_URL + '?next=' + url)
bgneal@811 40
bgneal@811 41 def test_inbox(self):
bgneal@811 42 self._test_get('messages-inbox')
bgneal@811 43
bgneal@811 44 def test_compose(self):
bgneal@811 45 url_name = 'messages-compose'
bgneal@811 46 self._test_get(url_name)
bgneal@811 47 self._test_post(url_name)
bgneal@811 48
bgneal@811 49 def test_outbox(self):
bgneal@811 50 self._test_get('messages-outbox')
bgneal@811 51
bgneal@811 52 def test_trash(self):
bgneal@811 53 self._test_get('messages-trash')
bgneal@811 54
bgneal@811 55 def test_options(self):
bgneal@811 56 url_name = 'messages-options'
bgneal@811 57 self._test_get(url_name)
bgneal@811 58 self._test_post(url_name)
bgneal@811 59
bgneal@811 60 def test_delete(self):
bgneal@811 61 self._test_get('messages-delete')
bgneal@811 62
bgneal@811 63 def test_undelete(self):
bgneal@811 64 self._test_get('messages-undelete')
bgneal@811 65
bgneal@811 66 def test_view(self):
bgneal@811 67 url_name = 'messages-view'
bgneal@811 68 self._test_get(url_name, args=[123])
bgneal@811 69 self._test_post(url_name, args=[123])
bgneal@811 70
bgneal@811 71 def test_report(self):
bgneal@811 72 url_name = 'messages-report'
bgneal@811 73 self._test_get(url_name, args=[123])
bgneal@811 74 self._test_post(url_name, args=[123])