# HG changeset patch # User Brian Neal # Date 1410113539 18000 # Node ID 56b30c79f10e36076364c2dac9f141f3d4cde9a6 # Parent 4a4fa174a0ece4cdeec5929780cdaedd86527c63 Private messages refactor: start adding tests. diff -r 4a4fa174a0ec -r 56b30c79f10e messages/tests/test_views.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messages/tests/test_views.py Sun Sep 07 13:12:19 2014 -0500 @@ -0,0 +1,74 @@ +""" +Unit tests for the messages application views. + +""" +from django.test import TestCase +from django.core.urlresolvers import reverse + +from messages.models import Message, Options, Flag + + +VIEW_NAMES = [ + 'messages-inbox', + 'messages-compose', + 'messages-outbox', + 'messages-trash', + 'messages-options', + 'messages-delete', + 'messages-undelete', + 'messages-view', + 'messages-report', +] + + +class NotLoggedInTestCase(TestCase): + """Ensure we are redirected to the login page before we can do anything with + this application. + + """ + LOGIN_URL = reverse('accounts-login') + + def _test_get(self, url_name, **kwargs): + url = reverse(url_name, **kwargs) + response = self.client.get(url, follow=True) + self.assertRedirects(response, self.LOGIN_URL + '?next=' + url) + + def _test_post(self, url_name, **kwargs): + url = reverse(url_name, **kwargs) + response = self.client.post(url, follow=True) + self.assertRedirects(response, self.LOGIN_URL + '?next=' + url) + + def test_inbox(self): + self._test_get('messages-inbox') + + def test_compose(self): + url_name = 'messages-compose' + self._test_get(url_name) + self._test_post(url_name) + + def test_outbox(self): + self._test_get('messages-outbox') + + def test_trash(self): + self._test_get('messages-trash') + + def test_options(self): + url_name = 'messages-options' + self._test_get(url_name) + self._test_post(url_name) + + def test_delete(self): + self._test_get('messages-delete') + + def test_undelete(self): + self._test_get('messages-undelete') + + def test_view(self): + url_name = 'messages-view' + self._test_get(url_name, args=[123]) + self._test_post(url_name, args=[123]) + + def test_report(self): + url_name = 'messages-report' + self._test_get(url_name, args=[123]) + self._test_post(url_name, args=[123])