Commit 1627b4a611aa9716944da4e0db9fac87a2838622
Committed by
Sergio Oliveira
1 parent
b57841f9
Exists in
master
and in
39 other branches
Add tests
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Showing
4 changed files
with
253 additions
and
1 deletions
Show diff stats
colab/search/tests.py
| @@ -13,7 +13,7 @@ class SearchViewTest(TestCase): | @@ -13,7 +13,7 @@ class SearchViewTest(TestCase): | ||
| 13 | self.client = Client() | 13 | self.client = Client() |
| 14 | 14 | ||
| 15 | def tearDown(self): | 15 | def tearDown(self): |
| 16 | - call_command('clear_index', interactive=False,verbosity=0) | 16 | + call_command('clear_index', interactive=False, verbosity=0) |
| 17 | 17 | ||
| 18 | def test_search_thread(self): | 18 | def test_search_thread(self): |
| 19 | request = self.client.get('/search/?q=thread') | 19 | request = self.client.get('/search/?q=thread') |
| @@ -0,0 +1,186 @@ | @@ -0,0 +1,186 @@ | ||
| 1 | +[ | ||
| 2 | + { | ||
| 3 | + "fields": { | ||
| 4 | + "last_name": "Jar", | ||
| 5 | + "webpage": null, | ||
| 6 | + "twitter": null, | ||
| 7 | + "is_staff": false, | ||
| 8 | + "user_permissions": [ | ||
| 9 | + | ||
| 10 | + ], | ||
| 11 | + "date_joined": "2015-02-24T21:10:35.004Z", | ||
| 12 | + "google_talk": null, | ||
| 13 | + "first_name": "Gust", | ||
| 14 | + "is_superuser": false, | ||
| 15 | + "last_login": "2015-02-26T17:56:13.378Z", | ||
| 16 | + "verification_hash": null, | ||
| 17 | + "role": null, | ||
| 18 | + "email": "gustmax@hotmail.com", | ||
| 19 | + "username": "gustmax", | ||
| 20 | + "bio": null, | ||
| 21 | + "needs_update": false, | ||
| 22 | + "is_active": true, | ||
| 23 | + "facebook": null, | ||
| 24 | + "groups": [ | ||
| 25 | + | ||
| 26 | + ], | ||
| 27 | + "password": "pbkdf2_sha256$12000$ez83ccNOUQZk$vYT/QcYMukXZ7D7L1qQPyYlzCUEEEF20J7/Xjef0Rqg=", | ||
| 28 | + "institution": null, | ||
| 29 | + "github": null, | ||
| 30 | + "modified": "2015-02-24T21:11:22.323Z" | ||
| 31 | + }, | ||
| 32 | + "model": "accounts.user", | ||
| 33 | + "pk": 1 | ||
| 34 | + }, | ||
| 35 | + { | ||
| 36 | + "fields": { | ||
| 37 | + "real_name": "", | ||
| 38 | + "user": 1, | ||
| 39 | + "md5": "ed8f47ae6048f8d4456c0554578f53ff", | ||
| 40 | + "address": "gustmax@hotmail.com" | ||
| 41 | + }, | ||
| 42 | + "model": "super_archives.emailaddress", | ||
| 43 | + "pk": 1 | ||
| 44 | + }, | ||
| 45 | + { | ||
| 46 | + "fields": { | ||
| 47 | + "description": "", | ||
| 48 | + "email": "", | ||
| 49 | + "logo": "", | ||
| 50 | + "last_imported_index": 0, | ||
| 51 | + "is_private": true, | ||
| 52 | + "name": "mailman" | ||
| 53 | + }, | ||
| 54 | + "model": "super_archives.mailinglist", | ||
| 55 | + "pk": 1 | ||
| 56 | + }, | ||
| 57 | + { | ||
| 58 | + "fields": { | ||
| 59 | + "description": "", | ||
| 60 | + "email": "", | ||
| 61 | + "logo": "", | ||
| 62 | + "last_imported_index": 0, | ||
| 63 | + "is_private": false, | ||
| 64 | + "name": "lista" | ||
| 65 | + }, | ||
| 66 | + "model": "super_archives.mailinglist", | ||
| 67 | + "pk": 2 | ||
| 68 | + }, | ||
| 69 | + { | ||
| 70 | + "fields": { | ||
| 71 | + "description": "", | ||
| 72 | + "email": "", | ||
| 73 | + "logo": "", | ||
| 74 | + "last_imported_index": 0, | ||
| 75 | + "is_private": true, | ||
| 76 | + "name": "privatelist" | ||
| 77 | + }, | ||
| 78 | + "model": "super_archives.mailinglist", | ||
| 79 | + "pk": 3 | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + "fields": { | ||
| 83 | + "spam": false, | ||
| 84 | + "subject_token": "no-subject", | ||
| 85 | + "mailinglist": 1, | ||
| 86 | + "score": 34, | ||
| 87 | + "latest_message": 1 | ||
| 88 | + }, | ||
| 89 | + "model": "super_archives.thread", | ||
| 90 | + "pk": 1 | ||
| 91 | + }, | ||
| 92 | + { | ||
| 93 | + "fields": { | ||
| 94 | + "spam": false, | ||
| 95 | + "subject_token": "no-subject", | ||
| 96 | + "mailinglist": 2, | ||
| 97 | + "score": 34, | ||
| 98 | + "latest_message": 2 | ||
| 99 | + }, | ||
| 100 | + "model": "super_archives.thread", | ||
| 101 | + "pk": 2 | ||
| 102 | + }, | ||
| 103 | + { | ||
| 104 | + "fields": { | ||
| 105 | + "spam": false, | ||
| 106 | + "subject_token": "no-subject", | ||
| 107 | + "mailinglist": 3, | ||
| 108 | + "score": 33, | ||
| 109 | + "latest_message": 3 | ||
| 110 | + }, | ||
| 111 | + "model": "super_archives.thread", | ||
| 112 | + "pk": 3 | ||
| 113 | + }, | ||
| 114 | + { | ||
| 115 | + "fields": { | ||
| 116 | + "body": "lista Mailman email", | ||
| 117 | + "received_time": "2015-02-24T14:23:42Z", | ||
| 118 | + "from_address": 1, | ||
| 119 | + "thread": 1, | ||
| 120 | + "spam": false, | ||
| 121 | + "subject_clean": "(no subject)", | ||
| 122 | + "message_id": "<20150224142347.9ED2419A5B0@localhost.localdomain>", | ||
| 123 | + "subject": "[Mailman] (no subject)" | ||
| 124 | + }, | ||
| 125 | + "model": "super_archives.message", | ||
| 126 | + "pk": 1 | ||
| 127 | + }, | ||
| 128 | + { | ||
| 129 | + "fields": { | ||
| 130 | + "body": "nada", | ||
| 131 | + "received_time": "2015-02-24T14:15:39Z", | ||
| 132 | + "from_address": 1, | ||
| 133 | + "thread": 2, | ||
| 134 | + "spam": false, | ||
| 135 | + "subject_clean": "(no subject)", | ||
| 136 | + "message_id": "<20150224141545.1AECA19A5A0@localhost.localdomain>", | ||
| 137 | + "subject": "[Lista] (no subject)" | ||
| 138 | + }, | ||
| 139 | + "model": "super_archives.message", | ||
| 140 | + "pk": 2 | ||
| 141 | + }, | ||
| 142 | + { | ||
| 143 | + "fields": { | ||
| 144 | + "body": "Mensagem da lista privada nada", | ||
| 145 | + "received_time": "2015-02-24T14:15:39Z", | ||
| 146 | + "from_address": 1, | ||
| 147 | + "thread": 3, | ||
| 148 | + "spam": false, | ||
| 149 | + "subject_clean": "(no subject)", | ||
| 150 | + "message_id": "<20150224141545.1AECA19A5A0@localhost.localdomain>", | ||
| 151 | + "subject": "[PrivateList] (no subject)" | ||
| 152 | + }, | ||
| 153 | + "model": "super_archives.message", | ||
| 154 | + "pk": 3 | ||
| 155 | + }, | ||
| 156 | + { | ||
| 157 | + "fields": { | ||
| 158 | + "text": "lista Mailman email\n", | ||
| 159 | + "message": 1, | ||
| 160 | + "is_reply": false, | ||
| 161 | + "order": 0 | ||
| 162 | + }, | ||
| 163 | + "model": "super_archives.messageblock", | ||
| 164 | + "pk": 1 | ||
| 165 | + }, | ||
| 166 | + { | ||
| 167 | + "fields": { | ||
| 168 | + "text": "nada\n", | ||
| 169 | + "message": 2, | ||
| 170 | + "is_reply": false, | ||
| 171 | + "order": 0 | ||
| 172 | + }, | ||
| 173 | + "model": "super_archives.messageblock", | ||
| 174 | + "pk": 2 | ||
| 175 | + }, | ||
| 176 | + { | ||
| 177 | + "fields": { | ||
| 178 | + "text": "Mensagem da lista privada nada\n", | ||
| 179 | + "message": 3, | ||
| 180 | + "is_reply": false, | ||
| 181 | + "order": 0 | ||
| 182 | + }, | ||
| 183 | + "model": "super_archives.messageblock", | ||
| 184 | + "pk": 3 | ||
| 185 | + } | ||
| 186 | +] |
| @@ -0,0 +1,66 @@ | @@ -0,0 +1,66 @@ | ||
| 1 | +# -*- coding:utf-8 -*- | ||
| 2 | +import mock | ||
| 3 | + | ||
| 4 | +from colab.accounts.utils import mailman | ||
| 5 | +from django.test import TestCase, Client | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +class ArchivesViewTest(TestCase): | ||
| 9 | + | ||
| 10 | + fixtures = ['mailinglistdata.json'] | ||
| 11 | + | ||
| 12 | + def setUp(self): | ||
| 13 | + self.client = Client() | ||
| 14 | + | ||
| 15 | + def authenticate_user(self): | ||
| 16 | + self.client.login(username='gustmax', password='1234') | ||
| 17 | + | ||
| 18 | + def test_see_only_private_list_if_member(self): | ||
| 19 | + mailman.get_user_mailinglists = mock.Mock( | ||
| 20 | + return_value="['privatelist']") | ||
| 21 | + | ||
| 22 | + self.authenticate_user() | ||
| 23 | + request = self.client.get('/archives/thread/') | ||
| 24 | + | ||
| 25 | + list_data = request.context['lists'] | ||
| 26 | + | ||
| 27 | + self.assertEqual('lista', list_data[0][0]) | ||
| 28 | + self.assertEqual('privatelist', list_data[1][0]) | ||
| 29 | + self.assertEqual(2, len(list_data)) | ||
| 30 | + | ||
| 31 | + def test_see_only_public_if_not_logged_in(self): | ||
| 32 | + request = self.client.get('/archives/thread/') | ||
| 33 | + | ||
| 34 | + list_data = request.context['lists'] | ||
| 35 | + | ||
| 36 | + self.assertEqual('lista', list_data[0][0]) | ||
| 37 | + self.assertEqual(1, len(list_data)) | ||
| 38 | + | ||
| 39 | + def test_see_private_thread_in_dashboard_if_member(self): | ||
| 40 | + mailman.get_user_mailinglists = mock.Mock( | ||
| 41 | + return_value="['privatelist']") | ||
| 42 | + | ||
| 43 | + self.authenticate_user() | ||
| 44 | + request = self.client.get('/dashboard') | ||
| 45 | + | ||
| 46 | + latest_threads = request.context['latest_threads'] | ||
| 47 | + hottest_threads = request.context['hottest_threads'] | ||
| 48 | + | ||
| 49 | + self.assertEqual(2, len(latest_threads)) | ||
| 50 | + self.assertEqual(2, len(hottest_threads)) | ||
| 51 | + | ||
| 52 | + def test_dont_see_private_thread_if_logged_out(self): | ||
| 53 | + request = self.client.get('/dashboard') | ||
| 54 | + | ||
| 55 | + latest_threads = request.context['latest_threads'] | ||
| 56 | + hottest_threads = request.context['hottest_threads'] | ||
| 57 | + | ||
| 58 | + self.assertEqual(1, len(latest_threads)) | ||
| 59 | + self.assertEqual(1, len(hottest_threads)) | ||
| 60 | + | ||
| 61 | + def test_dont_see_private_threads_in_profile_if_logged_out(self): | ||
| 62 | + request = self.client.get('/account/gustmax') | ||
| 63 | + | ||
| 64 | + emails = request.context['emails'] | ||
| 65 | + | ||
| 66 | + self.assertEqual(1, len(emails)) |