test_login.py
233 lines
| 12.4 KiB
| text/x-python
|
PythonLexer
r728 | # -*- coding: utf-8 -*- | |||
r547 | from rhodecode.tests import * | |||
from rhodecode.model.db import User | ||||
from rhodecode.lib.auth import check_password | ||||
class TestLoginController(TestController): | ||||
def test_index(self): | ||||
response = self.app.get(url(controller='login', action='index')) | ||||
assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | ||||
# Test response... | ||||
def test_login_admin_ok(self): | ||||
response = self.app.post(url(controller='login', action='index'), | ||||
{'username':'test_admin', | ||||
'password':'test12'}) | ||||
assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | ||||
r548 | assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user' | |||
r547 | response = response.follow() | |||
r688 | assert '%s repository' % HG_REPO in response.body | |||
r659 | ||||
r547 | def test_login_regular_ok(self): | |||
response = self.app.post(url(controller='login', action='index'), | ||||
{'username':'test_regular', | ||||
'password':'test12'}) | ||||
print response | ||||
assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | ||||
r548 | assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user' | |||
r547 | response = response.follow() | |||
r688 | assert '%s repository' % HG_REPO in response.body | |||
r547 | assert '<a title="Admin" href="/_admin">' not in response.body | |||
r659 | ||||
r547 | def test_login_ok_came_from(self): | |||
test_came_from = '/_admin/users' | ||||
response = self.app.post(url(controller='login', action='index', came_from=test_came_from), | ||||
{'username':'test_admin', | ||||
'password':'test12'}) | ||||
assert response.status == '302 Found', 'Wrong response code from came from redirection' | ||||
response = response.follow() | ||||
r659 | ||||
r547 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | |||
assert 'Users administration' in response.body, 'No proper title in response' | ||||
r659 | ||||
r547 | def test_login_short_password(self): | |||
response = self.app.post(url(controller='login', action='index'), | ||||
{'username':'error', | ||||
'password':'test'}) | ||||
assert response.status == '200 OK', 'Wrong response from login page' | ||||
r567 | print response.body | |||
assert 'Enter 6 characters or more' in response.body, 'No error password message in response' | ||||
r547 | ||||
def test_login_wrong_username_password(self): | ||||
response = self.app.post(url(controller='login', action='index'), | ||||
{'username':'error', | ||||
'password':'test12'}) | ||||
assert response.status == '200 OK', 'Wrong response from login page' | ||||
r659 | ||||
r547 | assert 'invalid user name' in response.body, 'No error username message in response' | |||
assert 'invalid password' in response.body, 'No error password message in response' | ||||
r659 | ||||
r723 | #========================================================================== | |||
# REGISTRATIONS | ||||
#========================================================================== | ||||
r547 | def test_register(self): | |||
response = self.app.get(url(controller='login', action='register')) | ||||
r728 | assert 'Sign Up to RhodeCode' in response.body, 'wrong page for user registration' | |||
r659 | ||||
r547 | def test_register_err_same_username(self): | |||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'test_admin', | ||||
r723 | 'password':'test12', | |||
'password_confirmation':'test12', | ||||
r547 | 'email':'goodmail@domain.com', | |||
'name':'test', | ||||
'lastname':'test'}) | ||||
r659 | ||||
r547 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |||
r659 | assert 'This username already exists' in response.body | |||
r745 | def test_register_err_same_email(self): | |||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'test_admin_0', | ||||
'password':'test12', | ||||
'password_confirmation':'test12', | ||||
'email':'test_admin@mail.com', | ||||
'name':'test', | ||||
'lastname':'test'}) | ||||
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | ||||
r746 | assert 'This e-mail address is already taken' in response.body | |||
r745 | ||||
def test_register_err_same_email_case_sensitive(self): | ||||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'test_admin_1', | ||||
'password':'test12', | ||||
'password_confirmation':'test12', | ||||
'email':'TesT_Admin@mail.COM', | ||||
'name':'test', | ||||
'lastname':'test'}) | ||||
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | ||||
r746 | assert 'This e-mail address is already taken' in response.body | |||
r745 | ||||
r547 | def test_register_err_wrong_data(self): | |||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'xs', | ||||
r723 | 'password':'test', | |||
'password_confirmation':'test', | ||||
r547 | 'email':'goodmailm', | |||
'name':'test', | ||||
'lastname':'test'}) | ||||
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | ||||
assert 'An email address must contain a single @' in response.body | ||||
r728 | assert 'Enter a value 6 characters long or more' in response.body | |||
r659 | ||||
r745 | def test_register_err_username(self): | |||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'error user', | ||||
'password':'test12', | ||||
'password_confirmation':'test12', | ||||
'email':'goodmailm', | ||||
'name':'test', | ||||
'lastname':'test'}) | ||||
print response.body | ||||
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | ||||
assert 'An email address must contain a single @' in response.body | ||||
r1021 | assert ('Username may only contain ' | |||
'alphanumeric characters underscores, ' | ||||
'periods or dashes and must begin with ' | ||||
'alphanumeric character') in response.body | ||||
r745 | ||||
def test_register_err_case_sensitive(self): | ||||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'Test_Admin', | ||||
'password':'test12', | ||||
'password_confirmation':'test12', | ||||
'email':'goodmailm', | ||||
'name':'test', | ||||
'lastname':'test'}) | ||||
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | ||||
assert 'An email address must contain a single @' in response.body | ||||
assert 'This username already exists' in response.body | ||||
r723 | def test_register_special_chars(self): | |||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'xxxaxn', | ||||
'password':'ąćźżąśśśś', | ||||
'password_confirmation':'ąćźżąśśśś', | ||||
r728 | 'email':'goodmailm@test.plx', | |||
r723 | 'name':'test', | |||
r728 | 'lastname':'test'}) | |||
r723 | ||||
r728 | print response.body | |||
r723 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |||
assert 'Invalid characters in password' in response.body | ||||
def test_register_password_mismatch(self): | ||||
response = self.app.post(url(controller='login', action='register'), | ||||
{'username':'xs', | ||||
'password':'123qwe', | ||||
'password_confirmation':'qwe123', | ||||
r728 | 'email':'goodmailm@test.plxa', | |||
r723 | 'name':'test', | |||
r728 | 'lastname':'test'}) | |||
r723 | ||||
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | ||||
r728 | print response.body | |||
r723 | assert 'Password do not match' in response.body | |||
r659 | ||||
r547 | def test_register_ok(self): | |||
username = 'test_regular4' | ||||
password = 'qweqwe' | ||||
email = 'marcin@test.com' | ||||
name = 'testname' | ||||
lastname = 'testlastname' | ||||
r659 | ||||
r547 | response = self.app.post(url(controller='login', action='register'), | |||
{'username':username, | ||||
'password':password, | ||||
r723 | 'password_confirmation':password, | |||
r547 | 'email':email, | |||
'name':name, | ||||
'lastname':lastname}) | ||||
r659 | assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status | |||
r549 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' | |||
r659 | ||||
r547 | ret = self.sa.query(User).filter(User.username == 'test_regular4').one() | |||
assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) | ||||
assert check_password(password, ret.password) == True , 'password mismatch' | ||||
assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) | ||||
assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) | ||||
assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) | ||||
r659 | ||||
def test_forgot_password_wrong_mail(self): | ||||
r547 | response = self.app.post(url(controller='login', action='password_reset'), | |||
{'email':'marcin@wrongmail.org', }) | ||||
r659 | ||||
r746 | assert "This e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' | |||
r659 | ||||
r547 | def test_forgot_password(self): | |||
response = self.app.get(url(controller='login', action='password_reset')) | ||||
assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | ||||
username = 'test_password_reset_1' | ||||
password = 'qweqwe' | ||||
email = 'marcin@python-works.com' | ||||
name = 'passwd' | ||||
lastname = 'reset' | ||||
r659 | ||||
r547 | response = self.app.post(url(controller='login', action='register'), | |||
{'username':username, | ||||
'password':password, | ||||
r728 | 'password_confirmation':password, | |||
r547 | 'email':email, | |||
'name':name, | ||||
r659 | 'lastname':lastname}) | |||
r547 | #register new user for email test | |||
response = self.app.post(url(controller='login', action='password_reset'), | ||||
{'email':email, }) | ||||
print response.session['flash'] | ||||
r549 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' | |||
r547 | assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' | |||
r659 | ||||