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