1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-24 21:07:17 +00:00

check if user num exceed limit before add user

This commit is contained in:
lian
2016-11-05 12:09:58 +08:00
parent d00cba5769
commit 34a350d623
11 changed files with 343 additions and 23 deletions

View File

@@ -1,7 +1,12 @@
from mock import patch
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.html import escape
from tests.common.common import BASE_URL, USERNAME, PASSWORD
from tests.common.utils import randstring
from seahub.base.accounts import RegistrationForm
from tests.common.common import USERNAME
LOGIN_URL = reverse('auth_login')
class LoginTest(TestCase):
@@ -23,3 +28,107 @@ class LoginTest(TestCase):
assert resp.context['form'].errors['__all__'] == [
u'Please enter a correct email/username and password. Note that both fields are case-sensitive.'
]
class TestRegistrationForm(TestCase):
@patch('seahub.base.accounts.user_number_over_limit')
def test_registration_form_is_valid(self, mock_user_number_over_limit):
mock_user_number_over_limit.return_value = False
user_info = {
'email':'%s@%s.com' % (randstring(10), randstring(10)) ,
'userid': randstring(40),
'password1':'password',
'password2':'password',
}
f = RegistrationForm(data = user_info)
self.assertTrue(f.is_valid())
@patch('seahub.base.accounts.user_number_over_limit')
def test_registration_form_email_invalid(self, mock_user_number_over_limit):
mock_user_number_over_limit.return_value = False
user_info = {
# invalid email without `@`
'email':'%s%s.com' % (randstring(10), randstring(10)) ,
'userid': randstring(40),
'password1':'password',
'password2':'password',
}
f = RegistrationForm(data = user_info)
assert 'Enter a valid email address.' in str(f['email'].errors)
@patch('seahub.base.accounts.user_number_over_limit')
def test_registration_form_email_invalid_for_exceed_limit(self, mock_user_number_over_limit):
mock_user_number_over_limit.return_value = True
user_info = {
'email':'%s@%s.com' % (randstring(10), randstring(10)) ,
'userid': randstring(40),
'password1':'password',
'password2':'password',
}
f = RegistrationForm(data = user_info)
assert 'The number of users exceeds the limit.' in str(f['email'].errors)
@patch('seahub.base.accounts.user_number_over_limit')
def test_registration_form_email_invalid_for_user_exist(self, mock_user_number_over_limit):
mock_user_number_over_limit.return_value = False
user_info = {
# invalid email
'email': USERNAME,
'userid': randstring(40),
'password1':'password',
'password2':'password',
}
f = RegistrationForm(data = user_info)
assert 'User %s already exists.' % USERNAME in str(f['email'].errors)
@patch('seahub.base.accounts.user_number_over_limit')
def test_registration_form_userid_invalid(self, mock_user_number_over_limit):
mock_user_number_over_limit.return_value = False
user_info = {
'email':'%s@%s.com' % (randstring(10), randstring(10)) ,
# invalid userid length < 40
'userid': randstring(10),
'password1':'password',
'password2':'password',
}
f = RegistrationForm(data = user_info)
assert 'Invalid user id.' in str(f['userid'].errors)
@patch('seahub.base.accounts.user_number_over_limit')
def test_registration_form_password_invalid(self, mock_user_number_over_limit):
mock_user_number_over_limit.return_value = False
user_info = {
'email':'%s@%s.com' % (randstring(10), randstring(10)) ,
'userid': randstring(40),
# invalid password
'password1':'password1',
'password2':'password2',
}
f = RegistrationForm(data = user_info)
# to escape `'`
assert escape("The two password fields didn't match.") in str(f['password2'].errors)