Commit 5864dc5681ae85b71566400ce34be73acce6df69
Exists in
master
and in
39 other branches
Merge branch 'colab_test' into 'master'
Colab test Added test to colab/accounts/
Showing
19 changed files
with
627 additions
and
61 deletions
Show diff stats
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +[run] | ||
| 2 | +omit = | ||
| 3 | + */migrations/* | ||
| 4 | + */tests/* | ||
| 5 | + test_*.py | ||
| 6 | + */__init__.py | ||
| 7 | + */urls.py | ||
| 8 | + */settings.py | ||
| 9 | + */tests.py | ||
| 10 | +source = | ||
| 11 | + colab/ | ||
| 12 | + | ||
| 13 | +[report] | ||
| 14 | +precision = 2 | ||
| 15 | +show_missing = True | ||
| 16 | + | ||
| 17 | +[html] | ||
| 18 | +directory = coverage_report/ | ||
| 19 | +title = Colab test coverage | ||
| 20 | + | ||
| 21 | + |
.gitignore
README.rst
| @@ -72,3 +72,20 @@ To run Colab with development server you will have to: | @@ -72,3 +72,20 @@ To run Colab with development server you will have to: | ||
| 72 | 72 | ||
| 73 | **NOTE**: In case you want to keep the configuration file else where just set the | 73 | **NOTE**: In case you want to keep the configuration file else where just set the |
| 74 | desired location in environment variable **COLAB_SETTINGS**. | 74 | desired location in environment variable **COLAB_SETTINGS**. |
| 75 | + | ||
| 76 | +About test | ||
| 77 | +========== | ||
| 78 | + | ||
| 79 | +How to write a tests. | ||
| 80 | +-------------------- | ||
| 81 | +Inside of each folder on /vagrant/colab/<folder> you can create a folder called | ||
| 82 | +"tests", and inside of it implements the code for test each file. | ||
| 83 | + | ||
| 84 | +How to run a test | ||
| 85 | +----------------- | ||
| 86 | + | ||
| 87 | +Follow the steps below: | ||
| 88 | + | ||
| 89 | +* Go to vagrant/colab/ | ||
| 90 | +* Install the test dependencies with `pip install -r requirements_test.txt` | ||
| 91 | +* run: ./runtests.sh |
colab/accounts/models.py
| @@ -2,26 +2,29 @@ | @@ -2,26 +2,29 @@ | ||
| 2 | 2 | ||
| 3 | import urlparse | 3 | import urlparse |
| 4 | 4 | ||
| 5 | -from django.db import models, DatabaseError | ||
| 6 | -from django.contrib.auth.hashers import check_password | 5 | +from django.db import models |
| 7 | from django.contrib.auth.models import AbstractUser | 6 | from django.contrib.auth.models import AbstractUser |
| 8 | from django.core import validators | 7 | from django.core import validators |
| 9 | from django.core.urlresolvers import reverse | 8 | from django.core.urlresolvers import reverse |
| 10 | from django.utils.translation import ugettext_lazy as _ | 9 | from django.utils.translation import ugettext_lazy as _ |
| 11 | 10 | ||
| 12 | -from conversejs import xmpp | ||
| 13 | - | ||
| 14 | from .utils import mailman | 11 | from .utils import mailman |
| 15 | 12 | ||
| 16 | 13 | ||
| 17 | class User(AbstractUser): | 14 | class User(AbstractUser): |
| 15 | + """ | ||
| 16 | + For more information about AbstractUser | ||
| 17 | + @see: https://docs.djangoproject.com/en/1.7/ref/contrib/auth/ | ||
| 18 | + """ | ||
| 18 | institution = models.CharField(max_length=128, null=True, blank=True) | 19 | institution = models.CharField(max_length=128, null=True, blank=True) |
| 19 | role = models.CharField(max_length=128, null=True, blank=True) | 20 | role = models.CharField(max_length=128, null=True, blank=True) |
| 20 | - twitter = models.CharField(max_length=128, null=True, blank=True) | ||
| 21 | - facebook = models.CharField(max_length=128, null=True, blank=True) | 21 | + # Twitter limits user name to 15 characters. |
| 22 | + twitter = models.CharField(max_length=15, null=True, blank=True) | ||
| 23 | + # Facebook limits user lenght to 15. | ||
| 24 | + facebook = models.CharField(max_length=15, null=True, blank=True) | ||
| 22 | google_talk = models.EmailField(null=True, blank=True) | 25 | google_talk = models.EmailField(null=True, blank=True) |
| 23 | - github = models.CharField(max_length=128, null=True, blank=True, | ||
| 24 | - verbose_name=u'github') | 26 | + github = models.CharField(max_length=39, null=True, blank=True, |
| 27 | + verbose_name=u'github') | ||
| 25 | webpage = models.CharField(max_length=256, null=True, blank=True) | 28 | webpage = models.CharField(max_length=256, null=True, blank=True) |
| 26 | verification_hash = models.CharField(max_length=32, null=True, blank=True) | 29 | verification_hash = models.CharField(max_length=32, null=True, blank=True) |
| 27 | modified = models.DateTimeField(auto_now=True) | 30 | modified = models.DateTimeField(auto_now=True) |
colab/accounts/tests.py
| @@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
| 1 | -""" | ||
| 2 | -This file demonstrates writing tests using the unittest module. These will pass | ||
| 3 | -when you run "manage.py test". | ||
| 4 | - | ||
| 5 | -Replace this with more appropriate tests for your application. | ||
| 6 | -""" | ||
| 7 | - | ||
| 8 | -from django.test import TestCase | ||
| 9 | - | ||
| 10 | - | ||
| 11 | -class SimpleTest(TestCase): | ||
| 12 | - def test_basic_addition(self): | ||
| 13 | - """ | ||
| 14 | - Tests that 1 + 1 always equals 2. | ||
| 15 | - """ | ||
| 16 | - self.assertEqual(1 + 1, 2) |
| @@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
| 1 | +""" | ||
| 2 | +Test account redirections. | ||
| 3 | +Objective: Test requests. | ||
| 4 | +""" | ||
| 5 | + | ||
| 6 | +from django.test import TestCase, Client | ||
| 7 | +from django.test.client import RequestFactory | ||
| 8 | +from colab.accounts.models import User | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +class RequestTest(TestCase): | ||
| 12 | + | ||
| 13 | + def setUp(self): | ||
| 14 | + self.factory = RequestFactory() | ||
| 15 | + self.client = Client() | ||
| 16 | + | ||
| 17 | + def test_successful_signup(self): | ||
| 18 | + # TODO | ||
| 19 | + pass | ||
| 20 | + | ||
| 21 | + def test_invalid_user_profile_url(self): | ||
| 22 | + response = self.client.get('/account/johndoe/') | ||
| 23 | + self.assertEqual(404, response.status_code) | ||
| 24 | + | ||
| 25 | + def test_valid_user_profile_url(self): | ||
| 26 | + self.userTest = User() | ||
| 27 | + self.userTest.username = "usertest" | ||
| 28 | + self.userTest.email = "usertest@colab.com.br" | ||
| 29 | + self.userTest.set_password("1234colab") | ||
| 30 | + self.userTest.save() | ||
| 31 | + response = self.client.get('/account/usertest/') | ||
| 32 | + self.assertEqual(200, response.status_code) | ||
| 33 | + | ||
| 34 | + def test_valid_login_url(self): | ||
| 35 | + response = self.client.get('/account/login') | ||
| 36 | + self.assertEqual(200, response.status_code) |
| @@ -0,0 +1,397 @@ | @@ -0,0 +1,397 @@ | ||
| 1 | +""" | ||
| 2 | +Test User class. | ||
| 3 | +Objective: Test parameters, and behavior. | ||
| 4 | +""" | ||
| 5 | +from colab.accounts.models import User | ||
| 6 | +from django.test import TestCase, Client | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +class UserTest(TestCase): | ||
| 10 | + | ||
| 11 | + def setup(self): | ||
| 12 | + self.user = self.create_user() | ||
| 13 | + self.client = Client() | ||
| 14 | + | ||
| 15 | + def teardown(self): | ||
| 16 | + pass | ||
| 17 | + | ||
| 18 | + def create_user(self): | ||
| 19 | + user = User() | ||
| 20 | + user.username = "USERtestCoLaB" | ||
| 21 | + user.set_password("123colab4") | ||
| 22 | + user.email = "usertest@colab.com.br" | ||
| 23 | + user.id = 1 | ||
| 24 | + user.twitter = "usertestcolab" | ||
| 25 | + user.facebook = "usertestcolab" | ||
| 26 | + user.first_name = "USERtestCoLaB" | ||
| 27 | + user.last_name = "COLAB" | ||
| 28 | + user.save() | ||
| 29 | + | ||
| 30 | + return user | ||
| 31 | + | ||
| 32 | + def authenticate_user(self): | ||
| 33 | + self.user.needs_update = False | ||
| 34 | + self.user.save() | ||
| 35 | + self.client.login(username=self.user.username, | ||
| 36 | + password='123colab4') | ||
| 37 | + | ||
| 38 | + def validate_mandatory_fields(self, expected_first_name, | ||
| 39 | + expected_last_name, | ||
| 40 | + first_name, last_name): | ||
| 41 | + data = {'first_name': first_name, | ||
| 42 | + 'last_name': last_name} | ||
| 43 | + self.client.post('/account/usertestcolab/edit', data) | ||
| 44 | + user = User.objects.get(id=1) | ||
| 45 | + self.assertEqual(expected_first_name, user.first_name) | ||
| 46 | + self.assertEqual(expected_last_name, user.last_name) | ||
| 47 | + | ||
| 48 | + def validate_non_mandatory_fields(self, field_name, expected_value, value): | ||
| 49 | + data = {'first_name': 'usertestcolab', | ||
| 50 | + 'last_name': 'colab', | ||
| 51 | + field_name: value} | ||
| 52 | + self.client.post('/account/usertestcolab/edit', data) | ||
| 53 | + user = User.objects.get(id=1) | ||
| 54 | + self.assertEqual(expected_value, getattr(user, field_name)) | ||
| 55 | + | ||
| 56 | + def test_check_password(self): | ||
| 57 | + self.assertTrue(self.user.check_password("123colab4")) | ||
| 58 | + self.assertFalse(self.user.check_password("1234")) | ||
| 59 | + | ||
| 60 | + def test_get_absolute_url(self): | ||
| 61 | + url = self.user.get_absolute_url() | ||
| 62 | + self.assertEqual("/account/usertestcolab", url) | ||
| 63 | + | ||
| 64 | + def test_twitter_link(self): | ||
| 65 | + link_twitter = self.user.twitter_link() | ||
| 66 | + self.assertEqual('https://twitter.com/usertestcolab', link_twitter) | ||
| 67 | + | ||
| 68 | + def test_facebook_link(self): | ||
| 69 | + link_facebook = self.user.facebook_link() | ||
| 70 | + self.assertEqual('https://www.facebook.com/usertestcolab', | ||
| 71 | + link_facebook) | ||
| 72 | + | ||
| 73 | + def test_mailinglists(self): | ||
| 74 | + empty_list = () | ||
| 75 | + self.assertEqual(empty_list, self.user.mailinglists()) | ||
| 76 | + | ||
| 77 | + def test_update_subscription(self): | ||
| 78 | + pass | ||
| 79 | + # TODO: You should have mailman connection. | ||
| 80 | + | ||
| 81 | + def test_save(self): | ||
| 82 | + username_test = "USERtestCoLaB" | ||
| 83 | + | ||
| 84 | + user_db = User.objects.get(id=1) | ||
| 85 | + self.assertEqual(user_db.username, username_test.lower()) | ||
| 86 | + self.user.delete() | ||
| 87 | + | ||
| 88 | + def test_update_user_mandatory_information(self): | ||
| 89 | + self.authenticate_user() | ||
| 90 | + self.validate_mandatory_fields('usertestcolab', 'colabtest', | ||
| 91 | + 'usertestcolab', 'colabtest') | ||
| 92 | + self.user.delete() | ||
| 93 | + | ||
| 94 | + def test_update_user_mandatory_max_leght_limit(self): | ||
| 95 | + self.authenticate_user() | ||
| 96 | + self.validate_mandatory_fields('a' * 30, 'a' * 30, 'a' * 30, 'a' * 30) | ||
| 97 | + self.user.delete() | ||
| 98 | + | ||
| 99 | + def test_update_user_mandatory_max_leght_limit_one_less(self): | ||
| 100 | + self.authenticate_user() | ||
| 101 | + self.validate_mandatory_fields('a' * 29, 'a' * 29, 'a' * 29, 'a' * 29) | ||
| 102 | + self.user.delete() | ||
| 103 | + | ||
| 104 | + def test_update_user_mandatory_max_leght_overflow(self): | ||
| 105 | + self.authenticate_user() | ||
| 106 | + self.validate_mandatory_fields('USERtestCoLaB', 'COLAB', 'a' * 31, | ||
| 107 | + 'a' * 31) | ||
| 108 | + self.user.delete() | ||
| 109 | + | ||
| 110 | + def test_update_user_mandatory_invalid_empty_field(self): | ||
| 111 | + self.authenticate_user() | ||
| 112 | + self.validate_mandatory_fields('USERtestCoLaB', 'COLAB', '', '') | ||
| 113 | + self.user.delete() | ||
| 114 | + | ||
| 115 | + def test_update_user_mandatory_invalid_whitespace(self): | ||
| 116 | + self.authenticate_user() | ||
| 117 | + self.validate_mandatory_fields('USERtestCoLaB', 'COLAB', ' ', ' ') | ||
| 118 | + self.user.delete() | ||
| 119 | + | ||
| 120 | + def test_update_user_mandatory_invalid_using_number(self): | ||
| 121 | + self.authenticate_user() | ||
| 122 | + self.validate_mandatory_fields('USERtestCoLaB', 'COLAB', '123', '456') | ||
| 123 | + self.user.delete() | ||
| 124 | + | ||
| 125 | + def test_update_user_institution(self): | ||
| 126 | + self.authenticate_user() | ||
| 127 | + self.validate_non_mandatory_fields('institution', 'fga', 'fga') | ||
| 128 | + self.user.delete() | ||
| 129 | + | ||
| 130 | + def test_update_user_institution_max_lenght_limit(self): | ||
| 131 | + self.authenticate_user() | ||
| 132 | + self.validate_non_mandatory_fields('institution', 'a' * 128, 'a' * 128) | ||
| 133 | + self.user.delete() | ||
| 134 | + | ||
| 135 | + def test_update_user_institution_max_lenght_limit_one_less(self): | ||
| 136 | + self.authenticate_user() | ||
| 137 | + self.validate_non_mandatory_fields('institution', 'a' * 127, 'a' * 127) | ||
| 138 | + self.user.delete() | ||
| 139 | + | ||
| 140 | + def test_update_user_institution_max_lenght_overflow(self): | ||
| 141 | + self.authenticate_user() | ||
| 142 | + self.validate_non_mandatory_fields('institution', None, 'a' * 129) | ||
| 143 | + self.user.delete() | ||
| 144 | + | ||
| 145 | + def test_update_user_institution_invalid_empty_field(self): | ||
| 146 | + self.authenticate_user() | ||
| 147 | + self.validate_non_mandatory_fields('institution', '', '') | ||
| 148 | + self.user.delete() | ||
| 149 | + | ||
| 150 | + def test_update_user_institution_invalid_whitespace(self): | ||
| 151 | + self.authenticate_user() | ||
| 152 | + self.validate_non_mandatory_fields('institution', None, ' ') | ||
| 153 | + | ||
| 154 | + def test_update_user_institution_invalid_using_number(self): | ||
| 155 | + self.authenticate_user() | ||
| 156 | + self.validate_non_mandatory_fields('institution', None, '123') | ||
| 157 | + self.user.delete() | ||
| 158 | + | ||
| 159 | + def test_update_user_role(self): | ||
| 160 | + self.authenticate_user() | ||
| 161 | + self.validate_non_mandatory_fields('role', 'studenty', 'studenty') | ||
| 162 | + self.user.delete() | ||
| 163 | + | ||
| 164 | + def test_update_user_role_max_lenght_limit(self): | ||
| 165 | + self.authenticate_user() | ||
| 166 | + self.validate_non_mandatory_fields('role', 'a' * 128, 'a' * 128) | ||
| 167 | + self.user.delete() | ||
| 168 | + | ||
| 169 | + def test_update_user_role_max_lenght_limit_one_less(self): | ||
| 170 | + self.authenticate_user() | ||
| 171 | + self.validate_non_mandatory_fields('role', 'a' * 127, 'a' * 127) | ||
| 172 | + self.user.delete() | ||
| 173 | + | ||
| 174 | + def test_update_user_role_max_lenght_overflow(self): | ||
| 175 | + self.authenticate_user() | ||
| 176 | + self.validate_non_mandatory_fields('role', None, 'a' * 129) | ||
| 177 | + self.user.delete() | ||
| 178 | + | ||
| 179 | + def test_update_user_role_invalid_empty_field(self): | ||
| 180 | + self.authenticate_user() | ||
| 181 | + self.validate_non_mandatory_fields('role', '', '') | ||
| 182 | + self.user.delete() | ||
| 183 | + | ||
| 184 | + def test_update_user_role_invalid_whitespace(self): | ||
| 185 | + self.authenticate_user() | ||
| 186 | + self.validate_non_mandatory_fields('role', None, ' ') | ||
| 187 | + self.user.delete() | ||
| 188 | + | ||
| 189 | + def test_update_user_role_invalid_using_number(self): | ||
| 190 | + self.authenticate_user() | ||
| 191 | + self.validate_non_mandatory_fields('role', None, '123') | ||
| 192 | + self.user.delete() | ||
| 193 | + | ||
| 194 | + def test_update_user_twitter(self): | ||
| 195 | + self.authenticate_user() | ||
| 196 | + self.validate_non_mandatory_fields('twitter', 'twitter', 'twitter') | ||
| 197 | + self.user.delete() | ||
| 198 | + | ||
| 199 | + ''' | ||
| 200 | + Max_lenght is the maximmum size accept by Twitter. | ||
| 201 | + Tests related with twitter should have internet connection, | ||
| 202 | + because it's need username authentication. | ||
| 203 | + ''' | ||
| 204 | + def test_update_user_twitter_max_lenght_limit(self): | ||
| 205 | + self.authenticate_user() | ||
| 206 | + self.validate_non_mandatory_fields('twitter', 't' * 15, 't' * 15) | ||
| 207 | + self.user.delete() | ||
| 208 | + | ||
| 209 | + def test_update_user_twitter_max_lenght_limit_one_less(self): | ||
| 210 | + self.authenticate_user() | ||
| 211 | + self.validate_non_mandatory_fields('twitter', 't' * 14, 't' * 14) | ||
| 212 | + self.user.delete() | ||
| 213 | + | ||
| 214 | + def test_update_user_twitter_max_lenght_overflow(self): | ||
| 215 | + self.authenticate_user() | ||
| 216 | + self.validate_non_mandatory_fields('twitter', 'usertestcolab', | ||
| 217 | + 't' * 16) | ||
| 218 | + self.user.delete() | ||
| 219 | + | ||
| 220 | + def test_update_user_twitter_invalid_empty_field(self): | ||
| 221 | + self.authenticate_user() | ||
| 222 | + self.validate_non_mandatory_fields('twitter', '', '') | ||
| 223 | + self.user.delete() | ||
| 224 | + | ||
| 225 | + def test_update_user_twitter_invalid_whitespace(self): | ||
| 226 | + self.authenticate_user() | ||
| 227 | + self.validate_non_mandatory_fields('twitter', 'usertestcolab', ' ') | ||
| 228 | + self.user.delete() | ||
| 229 | + | ||
| 230 | + def test_update_user_twitter_invalid_using_number(self): | ||
| 231 | + self.authenticate_user() | ||
| 232 | + self.validate_non_mandatory_fields('twitter', 'usertestcolab', '123') | ||
| 233 | + self.user.delete() | ||
| 234 | + | ||
| 235 | + ''' | ||
| 236 | + Max_lenght is the maximmum size accept by Faceebook. | ||
| 237 | + Tests related with twitter should have internet connection, | ||
| 238 | + because it's need username authentication. | ||
| 239 | + ''' | ||
| 240 | + def test_update_user_facebook(self): | ||
| 241 | + self.authenticate_user() | ||
| 242 | + self.validate_non_mandatory_fields('facebook', 'facebook', 'facebook') | ||
| 243 | + self.user.delete() | ||
| 244 | + | ||
| 245 | + def test_update_user_facebook_max_lenght_limit(self): | ||
| 246 | + self.authenticate_user() | ||
| 247 | + self.validate_non_mandatory_fields('facebook', 'f' * 15, 'f' * 15) | ||
| 248 | + self.user.delete() | ||
| 249 | + | ||
| 250 | + def test_update_user_facebook_max_lenght_limit_one_less(self): | ||
| 251 | + self.authenticate_user() | ||
| 252 | + self.validate_non_mandatory_fields('facebook', 'f' * 14, 'f' * 14) | ||
| 253 | + self.user.delete() | ||
| 254 | + | ||
| 255 | + def test_update_user_facebook_max_lenght_overflow(self): | ||
| 256 | + self.authenticate_user() | ||
| 257 | + self.validate_non_mandatory_fields('facebook', 'usertestcolab', | ||
| 258 | + 'f' * 16) | ||
| 259 | + self.user.delete() | ||
| 260 | + | ||
| 261 | + def test_update_user_facebook_invalid_empty_field(self): | ||
| 262 | + self.authenticate_user() | ||
| 263 | + self.validate_non_mandatory_fields('facebook', '', '') | ||
| 264 | + self.user.delete() | ||
| 265 | + | ||
| 266 | + def test_update_user_facebook_invalid_whitespace(self): | ||
| 267 | + self.authenticate_user() | ||
| 268 | + self.validate_non_mandatory_fields('facebook', 'usertestcolab', ' ') | ||
| 269 | + self.user.delete() | ||
| 270 | + | ||
| 271 | + def test_update_user_facebook_invalid_using_number(self): | ||
| 272 | + self.authenticate_user() | ||
| 273 | + self.validate_non_mandatory_fields('facebook', 'usertestcolab', '123') | ||
| 274 | + self.user.delete() | ||
| 275 | + | ||
| 276 | + def test_update_user_gtalk(self): | ||
| 277 | + self.authenticate_user() | ||
| 278 | + self.validate_non_mandatory_fields('google_talk', 'gtalk@colab.com.br', | ||
| 279 | + 'gtalk@colab.com.br') | ||
| 280 | + self.user.delete() | ||
| 281 | + | ||
| 282 | + def test_update_user_gtalk_email_invalid_caracters(self): | ||
| 283 | + self.authenticate_user() | ||
| 284 | + self.validate_non_mandatory_fields('google_talk', None, '@@@') | ||
| 285 | + self.user.delete() | ||
| 286 | + | ||
| 287 | + def test_update_user_gtalk_email_without_arroba(self): | ||
| 288 | + self.authenticate_user() | ||
| 289 | + self.validate_non_mandatory_fields('google_talk', None, | ||
| 290 | + 'usercolab.hotmail.com') | ||
| 291 | + self.user.delete() | ||
| 292 | + | ||
| 293 | + def test_update_user_gtalk_max_lenght_overflow(self): | ||
| 294 | + self.authenticate_user() | ||
| 295 | + self.validate_non_mandatory_fields('google_talk', None, | ||
| 296 | + 'usercolab@hotmail') | ||
| 297 | + self.user.delete() | ||
| 298 | + | ||
| 299 | + def test_update_user_gtalk_invalid_empty_field(self): | ||
| 300 | + self.authenticate_user() | ||
| 301 | + self.validate_non_mandatory_fields('google_talk', '', '') | ||
| 302 | + self.user.delete() | ||
| 303 | + | ||
| 304 | + def test_update_user_gtalk_invalid_whitespace(self): | ||
| 305 | + self.authenticate_user() | ||
| 306 | + self.validate_non_mandatory_fields('google_talk', '', ' ') | ||
| 307 | + self.user.delete() | ||
| 308 | + | ||
| 309 | + def test_update_user_github(self): | ||
| 310 | + self.authenticate_user() | ||
| 311 | + self.validate_non_mandatory_fields('github', 'github', 'github') | ||
| 312 | + self.user.delete() | ||
| 313 | + | ||
| 314 | + def test_update_user_github_max_lenght_limit(self): | ||
| 315 | + self.authenticate_user() | ||
| 316 | + self.validate_non_mandatory_fields('github', 'a' * 39, 'a' * 39) | ||
| 317 | + self.user.delete() | ||
| 318 | + | ||
| 319 | + def test_update_user_github_max_lenght_limit_one_less(self): | ||
| 320 | + self.authenticate_user() | ||
| 321 | + self.validate_non_mandatory_fields('github', 'a' * 38, 'a' * 38) | ||
| 322 | + self.user.delete() | ||
| 323 | + | ||
| 324 | + def test_update_user_github_max_lenght_overflow(self): | ||
| 325 | + self.authenticate_user() | ||
| 326 | + self.validate_non_mandatory_fields('github', None, 'a' * 40) | ||
| 327 | + self.user.delete() | ||
| 328 | + | ||
| 329 | + def test_update_user_github_invalid_empty_field(self): | ||
| 330 | + self.authenticate_user() | ||
| 331 | + self.validate_non_mandatory_fields('github', '', '') | ||
| 332 | + self.user.delete() | ||
| 333 | + | ||
| 334 | + def test_update_user_github_invalid_whitespace(self): | ||
| 335 | + self.authenticate_user() | ||
| 336 | + self.validate_non_mandatory_fields('github', None, ' ') | ||
| 337 | + self.user.delete() | ||
| 338 | + | ||
| 339 | + def test_update_user_webpage(self): | ||
| 340 | + self.authenticate_user() | ||
| 341 | + self.validate_non_mandatory_fields('webpage', 'webpage', 'webpage') | ||
| 342 | + self.user.delete() | ||
| 343 | + | ||
| 344 | + def test_update_user_webpage_max_lenght_limit(self): | ||
| 345 | + self.authenticate_user() | ||
| 346 | + self.validate_non_mandatory_fields('webpage', 'p' * 256, 'p' * 256) | ||
| 347 | + self.user.delete() | ||
| 348 | + | ||
| 349 | + def test_update_user_webpage_max_lenght_limit_one_less(self): | ||
| 350 | + self.authenticate_user() | ||
| 351 | + self.validate_non_mandatory_fields('webpage', 'p' * 255, 'p' * 255) | ||
| 352 | + self.user.delete() | ||
| 353 | + | ||
| 354 | + def test_update_user_webpage_max_lenght_overflow(self): | ||
| 355 | + self.authenticate_user() | ||
| 356 | + self.validate_non_mandatory_fields('webpage', None, 'p' * 257) | ||
| 357 | + self.user.delete() | ||
| 358 | + | ||
| 359 | + def test_update_user_webpage_invalid_empty_field(self): | ||
| 360 | + self.authenticate_user() | ||
| 361 | + self.validate_non_mandatory_fields('webpage', '', '') | ||
| 362 | + self.user.delete() | ||
| 363 | + | ||
| 364 | + def test_update_user_webpage_invalid_whitespace(self): | ||
| 365 | + self.authenticate_user() | ||
| 366 | + self.validate_non_mandatory_fields('webpage', None, ' ') | ||
| 367 | + self.user.delete() | ||
| 368 | + | ||
| 369 | + def test_update_user_bio(self): | ||
| 370 | + self.authenticate_user() | ||
| 371 | + self.validate_non_mandatory_fields('bio', 'bio', 'bio') | ||
| 372 | + self.user.delete() | ||
| 373 | + | ||
| 374 | + def test_update_user_bio_max_lenght_limit(self): | ||
| 375 | + self.authenticate_user() | ||
| 376 | + self.validate_non_mandatory_fields('bio', 'a' * 200, 'a' * 200) | ||
| 377 | + self.user.delete() | ||
| 378 | + | ||
| 379 | + def test_update_user_bio_max_lenght_limit_one_less(self): | ||
| 380 | + self.authenticate_user() | ||
| 381 | + self.validate_non_mandatory_fields('bio', 'a' * 199, 'a' * 199) | ||
| 382 | + self.user.delete() | ||
| 383 | + | ||
| 384 | + def test_update_user_bio_max_lenght_overflow(self): | ||
| 385 | + self.authenticate_user() | ||
| 386 | + self.validate_non_mandatory_fields('bio', None, 'a' * 201) | ||
| 387 | + self.user.delete() | ||
| 388 | + | ||
| 389 | + def test_update_user_bio_invalid_empty_field(self): | ||
| 390 | + self.authenticate_user() | ||
| 391 | + self.validate_non_mandatory_fields('bio', '', '') | ||
| 392 | + self.user.delete() | ||
| 393 | + | ||
| 394 | + def test_update_user_bio_invalid_whitespace(self): | ||
| 395 | + self.authenticate_user() | ||
| 396 | + self.validate_non_mandatory_fields('bio', None, ' ') | ||
| 397 | + self.user.delete() |
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +""" | ||
| 2 | +Test Sign Up view | ||
| 3 | +This test related with accounts/views.py | ||
| 4 | +""" | ||
| 5 | + | ||
| 6 | +from django.test import TestCase, Client | ||
| 7 | +from colab.accounts.models import User | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +class TestSignUpView(TestCase): | ||
| 11 | + | ||
| 12 | + def setUp(self): | ||
| 13 | + self.user = self.create_user_django() | ||
| 14 | + self.client = Client() | ||
| 15 | + | ||
| 16 | + def tearDown(self): | ||
| 17 | + self.user.delete() | ||
| 18 | + | ||
| 19 | + def create_user_django(self): | ||
| 20 | + user = User.objects.create_user("USERtestCoLaB", | ||
| 21 | + "usertest@colab.com.br", "123colab4") | ||
| 22 | + return user | ||
| 23 | + | ||
| 24 | + def test_user_authenticated_and_unregistered(self): | ||
| 25 | + self.client.login(username="usertestcolab", password="123colab4") | ||
| 26 | + response = self.client.get("/account/register/") | ||
| 27 | + self.assertEquals(200, response.status_code) | ||
| 28 | + self.client.logout() | ||
| 29 | + | ||
| 30 | + def test_user_authenticated_and_registered(self): | ||
| 31 | + self.user.needs_update = False | ||
| 32 | + self.user.save() | ||
| 33 | + self.client.login(username="usertestcolab", password="123colab4") | ||
| 34 | + response = self.client.get("/account/register/") | ||
| 35 | + self.assertEquals(302, response.status_code) | ||
| 36 | + url = "http://testserver/account/usertestcolab" | ||
| 37 | + self.assertEquals(url, response.url) | ||
| 38 | + self.client.logout() | ||
| 39 | + | ||
| 40 | + def test_user_not_authenticated(self): | ||
| 41 | + response = self.client.get("/account/register/") | ||
| 42 | + self.assertEquals(302, response.status_code) | ||
| 43 | + url = "http://testserver/account/login" | ||
| 44 | + self.assertEquals(url, response.url) |
colab/accounts/utils/mailman.py
| @@ -7,6 +7,8 @@ from django.conf import settings | @@ -7,6 +7,8 @@ from django.conf import settings | ||
| 7 | 7 | ||
| 8 | TIMEOUT = 1 | 8 | TIMEOUT = 1 |
| 9 | 9 | ||
| 10 | +LOGGER = logging.getLogger('colab.mailman') | ||
| 11 | + | ||
| 10 | 12 | ||
| 11 | def get_url(listname=None): | 13 | def get_url(listname=None): |
| 12 | if listname: | 14 | if listname: |
| @@ -20,7 +22,7 @@ def subscribe(listname, address): | @@ -20,7 +22,7 @@ def subscribe(listname, address): | ||
| 20 | try: | 22 | try: |
| 21 | requests.put(url, timeout=TIMEOUT, data={'address': address}) | 23 | requests.put(url, timeout=TIMEOUT, data={'address': address}) |
| 22 | except: | 24 | except: |
| 23 | - logging.exception('Unable to subscribe user') | 25 | + LOGGER.exception('Unable to subscribe user') |
| 24 | return False | 26 | return False |
| 25 | return True | 27 | return True |
| 26 | 28 | ||
| @@ -30,7 +32,7 @@ def unsubscribe(listname, address): | @@ -30,7 +32,7 @@ def unsubscribe(listname, address): | ||
| 30 | try: | 32 | try: |
| 31 | requests.delete(url, timeout=TIMEOUT, data={'address': address}) | 33 | requests.delete(url, timeout=TIMEOUT, data={'address': address}) |
| 32 | except: | 34 | except: |
| 33 | - logging.exception('Unable to unsubscribe user') | 35 | + LOGGER.exception('Unable to unsubscribe user') |
| 34 | return False | 36 | return False |
| 35 | return True | 37 | return True |
| 36 | 38 | ||
| @@ -56,7 +58,7 @@ def address_lists(address, description=''): | @@ -56,7 +58,7 @@ def address_lists(address, description=''): | ||
| 56 | try: | 58 | try: |
| 57 | lists = requests.get(url, timeout=TIMEOUT, params=params) | 59 | lists = requests.get(url, timeout=TIMEOUT, params=params) |
| 58 | except: | 60 | except: |
| 59 | - logging.exception('Unable to list mailing lists') | 61 | + LOGGER.exception('Unable to list mailing lists') |
| 60 | return [] | 62 | return [] |
| 61 | 63 | ||
| 62 | return lists.json() | 64 | return lists.json() |
colab/accounts/views.py
| @@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
| 3 | 3 | ||
| 4 | from collections import OrderedDict | 4 | from collections import OrderedDict |
| 5 | 5 | ||
| 6 | +from haystack.exceptions import SearchBackendError | ||
| 7 | + | ||
| 6 | from django.conf import settings | 8 | from django.conf import settings |
| 7 | from django.contrib import messages | 9 | from django.contrib import messages |
| 8 | from django.db import transaction | 10 | from django.db import transaction |
| @@ -106,7 +108,10 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -106,7 +108,10 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
| 106 | for filter_or in fields_or_lookup: | 108 | for filter_or in fields_or_lookup: |
| 107 | sqs = sqs.filter_or(**filter_or).exclude(type='thread') | 109 | sqs = sqs.filter_or(**filter_or).exclude(type='thread') |
| 108 | 110 | ||
| 109 | - context['results'] = sqs.order_by('-modified', '-created')[:10] | 111 | + try: |
| 112 | + context['results'] = sqs.order_by('-modified', '-created')[:10] | ||
| 113 | + except SearchBackendError: | ||
| 114 | + context['results'] = sqs.order_by('-modified')[:10] | ||
| 110 | 115 | ||
| 111 | email_pks = [addr.pk for addr in user.emails.iterator()] | 116 | email_pks = [addr.pk for addr in user.emails.iterator()] |
| 112 | query = Message.objects.filter(from_address__in=email_pks) | 117 | query = Message.objects.filter(from_address__in=email_pks) |
| @@ -123,17 +128,22 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -123,17 +128,22 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
| 123 | 128 | ||
| 124 | 129 | ||
| 125 | def signup(request): | 130 | def signup(request): |
| 126 | - user = request.user | 131 | + # TODO: Refactor |
| 127 | 132 | ||
| 128 | - # If the user is not authenticated, redirect to login | 133 | + user = request.user |
| 134 | + # If the user is not authenticated in Persona, and try to access url | ||
| 135 | + # /account/register/ then he will be redirected to login page. | ||
| 129 | if not user.is_authenticated(): | 136 | if not user.is_authenticated(): |
| 130 | return redirect('login') | 137 | return redirect('login') |
| 131 | 138 | ||
| 132 | - # If the user doesn't need to update its main data, redirect to its profile | 139 | + # If the user is authenticated in Persona, already register in Colab |
| 140 | + # and try to access directly "/account/register/", then he will be redirect | ||
| 141 | + # to user profile. | ||
| 133 | if not user.needs_update: | 142 | if not user.needs_update: |
| 134 | return redirect('user_profile', username=user.username) | 143 | return redirect('user_profile', username=user.username) |
| 135 | 144 | ||
| 136 | - # If the request method is GET just return the form | 145 | + # If the user is authenticated in Persona, but not in the Colab then he |
| 146 | + # will be redirected to the register form. | ||
| 137 | if request.method == 'GET': | 147 | if request.method == 'GET': |
| 138 | user_form = UserCreationForm() | 148 | user_form = UserCreationForm() |
| 139 | lists_form = ListsForm() | 149 | lists_form = ListsForm() |
| @@ -154,7 +164,8 @@ def signup(request): | @@ -154,7 +164,8 @@ def signup(request): | ||
| 154 | 164 | ||
| 155 | # Check if the user's email have been used previously | 165 | # Check if the user's email have been used previously |
| 156 | # in the mainling lists to link the user to old messages | 166 | # in the mainling lists to link the user to old messages |
| 157 | - email_addr, created = EmailAddress.objects.get_or_create(address=user.email) | 167 | + email_addr, created = EmailAddress.objects.get_or_create( |
| 168 | + address=user.email) | ||
| 158 | if created: | 169 | if created: |
| 159 | email_addr.real_name = user.get_full_name() | 170 | email_addr.real_name = user.get_full_name() |
| 160 | 171 | ||
| @@ -214,7 +225,8 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): | @@ -214,7 +225,8 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): | ||
| 214 | 225 | ||
| 215 | context.update(kwargs) | 226 | context.update(kwargs) |
| 216 | 227 | ||
| 217 | - return super(ManageUserSubscriptionsView, self).get_context_data(**context) | 228 | + return super(ManageUserSubscriptionsView, |
| 229 | + self).get_context_data(**context) | ||
| 218 | 230 | ||
| 219 | 231 | ||
| 220 | class ChangeXMPPPasswordView(UpdateView): | 232 | class ChangeXMPPPasswordView(UpdateView): |
colab/super_archives/fixtures/initial_data.json
colab/super_archives/tests.py
| @@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
| 1 | -""" | ||
| 2 | -This file demonstrates writing tests using the unittest module. These will pass | ||
| 3 | -when you run "manage.py test". | ||
| 4 | - | ||
| 5 | -Replace this with more appropriate tests for your application. | ||
| 6 | -""" | ||
| 7 | - | ||
| 8 | -from django.test import TestCase | ||
| 9 | - | ||
| 10 | - | ||
| 11 | -class SimpleTest(TestCase): | ||
| 12 | - def test_basic_addition(self): | ||
| 13 | - """ | ||
| 14 | - Tests that 1 + 1 always equals 2. | ||
| 15 | - """ | ||
| 16 | - self.assertEqual(1 + 1, 2) |
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +from ..settings import * | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' | ||
| 5 | + | ||
| 6 | +LOGGING = { | ||
| 7 | + 'version': 1, | ||
| 8 | + | ||
| 9 | + 'handlers': { | ||
| 10 | + 'null': { | ||
| 11 | + 'level': 'DEBUG', | ||
| 12 | + 'class': 'logging.NullHandler', | ||
| 13 | + }, | ||
| 14 | + }, | ||
| 15 | + | ||
| 16 | + 'loggers': { | ||
| 17 | + 'colab.mailman': { | ||
| 18 | + 'handlers': ['null'], | ||
| 19 | + 'propagate': False, | ||
| 20 | + }, | ||
| 21 | + 'haystack': { | ||
| 22 | + 'handlers': ['null'], | ||
| 23 | + 'propagate': False, | ||
| 24 | + }, | ||
| 25 | + 'pysolr': { | ||
| 26 | + 'handlers': ['null'], | ||
| 27 | + 'propagate': False, | ||
| 28 | + }, | ||
| 29 | + }, | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +import os | ||
| 33 | +HAYSTACK_CONNECTIONS = { | ||
| 34 | + 'default': { | ||
| 35 | + 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', | ||
| 36 | + 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), | ||
| 37 | + }, | ||
| 38 | +} |
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | +#!/usr/bin/env python | ||
| 2 | + | ||
| 3 | +import os | ||
| 4 | +import sys | ||
| 5 | + | ||
| 6 | +os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.tests.settings' | ||
| 7 | +os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' | ||
| 8 | +os.environ['REUSE_DB'] = '0' | ||
| 9 | + | ||
| 10 | +import django | ||
| 11 | +import coverage | ||
| 12 | + | ||
| 13 | +from django.test.utils import get_runner | ||
| 14 | +from django.conf import settings | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +def runtests(): | ||
| 18 | + if django.VERSION >= (1, 7, 0): | ||
| 19 | + django.setup() | ||
| 20 | + test_runner = get_runner(settings) | ||
| 21 | + failures = test_runner(interactive=False, failfast=False).run_tests([]) | ||
| 22 | + sys.exit(failures) | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +if __name__ == '__main__': | ||
| 26 | + os.remove('.coverage') | ||
| 27 | + coverage.process_startup() | ||
| 28 | + runtests() |
vagrant/centos.sh
| @@ -53,6 +53,7 @@ fi | @@ -53,6 +53,7 @@ fi | ||
| 53 | 53 | ||
| 54 | ### Create colab user in PostgreSQL | 54 | ### Create colab user in PostgreSQL |
| 55 | echo "CREATE USER colab WITH PASSWORD 'colab';" | sudo -u postgres -i psql 2> /dev/null || echo | 55 | echo "CREATE USER colab WITH PASSWORD 'colab';" | sudo -u postgres -i psql 2> /dev/null || echo |
| 56 | +echo "ALTER USER colab CREATEDB;" | ||
| 56 | 57 | ||
| 57 | ### Create colab DB in PostgreSQL | 58 | ### Create colab DB in PostgreSQL |
| 58 | sudo -u postgres -i createdb --owner=colab colab 2> /dev/null | echo | 59 | sudo -u postgres -i createdb --owner=colab colab 2> /dev/null | echo |
vagrant/ubuntu.sh
| @@ -14,6 +14,7 @@ chown vagrant:vagrant /etc/colab | @@ -14,6 +14,7 @@ chown vagrant:vagrant /etc/colab | ||
| 14 | 14 | ||
| 15 | ### Create colab user in PostgreSQL | 15 | ### Create colab user in PostgreSQL |
| 16 | echo "CREATE USER colab WITH PASSWORD 'colab';" | sudo -u postgres -i psql 2> /dev/null || echo | 16 | echo "CREATE USER colab WITH PASSWORD 'colab';" | sudo -u postgres -i psql 2> /dev/null || echo |
| 17 | +echo "ALTER USER colab CREATEDB;" | ||
| 17 | 18 | ||
| 18 | #i## Create colab DB in PostgreSQL | 19 | #i## Create colab DB in PostgreSQL |
| 19 | sudo -u postgres -i createdb --owner=colab colab 2> /dev/null | echo | 20 | sudo -u postgres -i createdb --owner=colab colab 2> /dev/null | echo |