bgneal@811: """ bgneal@811: Unit tests for the messages application views. bgneal@811: bgneal@811: """ bgneal@811: from django.test import TestCase bgneal@811: from django.core.urlresolvers import reverse bgneal@811: bgneal@811: from messages.models import Message, Options, Flag bgneal@811: bgneal@811: bgneal@811: VIEW_NAMES = [ bgneal@811: 'messages-inbox', bgneal@811: 'messages-compose', bgneal@811: 'messages-outbox', bgneal@811: 'messages-trash', bgneal@811: 'messages-options', bgneal@811: 'messages-delete', bgneal@811: 'messages-undelete', bgneal@811: 'messages-view', bgneal@811: 'messages-report', bgneal@811: ] bgneal@811: bgneal@811: bgneal@811: class NotLoggedInTestCase(TestCase): bgneal@811: """Ensure we are redirected to the login page before we can do anything with bgneal@811: this application. bgneal@811: bgneal@811: """ bgneal@811: LOGIN_URL = reverse('accounts-login') bgneal@811: bgneal@811: def _test_get(self, url_name, **kwargs): bgneal@811: url = reverse(url_name, **kwargs) bgneal@811: response = self.client.get(url, follow=True) bgneal@811: self.assertRedirects(response, self.LOGIN_URL + '?next=' + url) bgneal@811: bgneal@811: def _test_post(self, url_name, **kwargs): bgneal@811: url = reverse(url_name, **kwargs) bgneal@811: response = self.client.post(url, follow=True) bgneal@811: self.assertRedirects(response, self.LOGIN_URL + '?next=' + url) bgneal@811: bgneal@811: def test_inbox(self): bgneal@811: self._test_get('messages-inbox') bgneal@811: bgneal@811: def test_compose(self): bgneal@811: url_name = 'messages-compose' bgneal@811: self._test_get(url_name) bgneal@811: self._test_post(url_name) bgneal@811: bgneal@811: def test_outbox(self): bgneal@811: self._test_get('messages-outbox') bgneal@811: bgneal@811: def test_trash(self): bgneal@811: self._test_get('messages-trash') bgneal@811: bgneal@811: def test_options(self): bgneal@811: url_name = 'messages-options' bgneal@811: self._test_get(url_name) bgneal@811: self._test_post(url_name) bgneal@811: bgneal@811: def test_delete(self): bgneal@811: self._test_get('messages-delete') bgneal@811: bgneal@811: def test_undelete(self): bgneal@811: self._test_get('messages-undelete') bgneal@811: bgneal@811: def test_view(self): bgneal@811: url_name = 'messages-view' bgneal@811: self._test_get(url_name, args=[123]) bgneal@811: self._test_post(url_name, args=[123]) bgneal@811: bgneal@811: def test_report(self): bgneal@811: url_name = 'messages-report' bgneal@811: self._test_get(url_name, args=[123]) bgneal@811: self._test_post(url_name, args=[123])