##// END OF EJS Templates
hide add repository button when you don't have at least write permission in group...
hide add repository button when you don't have at least write permission in group ref #730

File last commit:

r2679:dffb9222 beta
r3241:12f2547c beta
Show More
test_login.py
291 lines | 13.3 KiB | text/x-python | PythonLexer
fixed bug in forms found due to testing,...
r728 # -*- coding: utf-8 -*-
renamed project to rhodecode
r547 from rhodecode.tests import *
test fixes
r1732 from rhodecode.model.db import User, Notification
utils/conf...
r2109 from rhodecode.lib.utils2 import generate_api_key
renamed project to rhodecode
r547 from rhodecode.lib.auth import check_password
Switched forms to new validators
r2467 from rhodecode.lib import helpers as h
from rhodecode.model import validators
renamed project to rhodecode
r547
utils/conf...
r2109
renamed project to rhodecode
r547 class TestLoginController(TestController):
test fixes
r1732 def tearDown(self):
for n in Notification.query().all():
Added functional test create repo with a group...
r2529 self.Session().delete(n)
test fixes
r1732
Added functional test create repo with a group...
r2529 self.Session().commit()
test fixes
r1732 self.assertEqual(Notification.query().all(), [])
renamed project to rhodecode
r547 def test_index(self):
response = self.app.get(url(controller='login', action='index'))
Fixes tests
r1418 self.assertEqual(response.status, '200 OK')
renamed project to rhodecode
r547 # Test response...
def test_login_admin_ok(self):
response = self.app.post(url(controller='login', action='index'),
Switched forms to new validators
r2467 {'username': 'test_admin',
'password': 'test12'})
Fixes tests
r1418 self.assertEqual(response.status, '302 Found')
Switched forms to new validators
r2467 self.assertEqual(response.session['rhodecode_user'].get('username'),
Fixes tests
r1418 'test_admin')
renamed project to rhodecode
r547 response = response.follow()
Fixes tests
r1418 self.assertTrue('%s repository' % HG_REPO in response.body)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 def test_login_regular_ok(self):
response = self.app.post(url(controller='login', action='index'),
Switched forms to new validators
r2467 {'username': 'test_regular',
'password': 'test12'})
Fixes tests
r1418
self.assertEqual(response.status, '302 Found')
Switched forms to new validators
r2467 self.assertEqual(response.session['rhodecode_user'].get('username'),
Fixes tests
r1418 'test_regular')
renamed project to rhodecode
r547 response = response.follow()
Fixes tests
r1418 self.assertTrue('%s repository' % HG_REPO in response.body)
self.assertTrue('<a title="Admin" href="/_admin">' not in response.body)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 def test_login_ok_came_from(self):
test_came_from = '/_admin/users'
Fixes tests
r1418 response = self.app.post(url(controller='login', action='index',
came_from=test_came_from),
Switched forms to new validators
r2467 {'username': 'test_admin',
'password': 'test12'})
Fixes tests
r1418 self.assertEqual(response.status, '302 Found')
renamed project to rhodecode
r547 response = response.follow()
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
Fixes tests
r1418 self.assertEqual(response.status, '200 OK')
self.assertTrue('Users administration' in response.body)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
removed ftp from allowed schemas...
r2679 @parameterized.expand([
('data:text/html,<script>window.alert("xss")</script>',),
('mailto:test@rhodecode.org',),
('file:///etc/passwd',),
('ftp://some.ftp.server',),
('http://other.domain',),
])
def test_login_bad_came_froms(self, url_came_from):
response = self.app.post(url(controller='login', action='index',
came_from=url_came_from),
{'username': 'test_admin',
'password': 'test12'})
self.assertEqual(response.status, '302 Found')
self.assertEqual(response._environ['paste.testing_variables']
['tmpl_context'].came_from, '/')
response = response.follow()
self.assertEqual(response.status, '200 OK')
renamed project to rhodecode
r547 def test_login_short_password(self):
response = self.app.post(url(controller='login', action='index'),
Switched forms to new validators
r2467 {'username': 'test_admin',
'password': 'as'})
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 self.assertEqual(response.status, '200 OK')
Fixes tests
r1418
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 self.assertTrue('Enter 3 characters or more' in response.body)
renamed project to rhodecode
r547
def test_login_wrong_username_password(self):
response = self.app.post(url(controller='login', action='index'),
Switched forms to new validators
r2467 {'username': 'error',
'password': 'test12'})
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
Fixes tests
r1418 self.assertTrue('invalid user name' in response.body)
self.assertTrue('invalid password' in response.body)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
some tests update
r723 #==========================================================================
# REGISTRATIONS
#==========================================================================
renamed project to rhodecode
r547 def test_register(self):
response = self.app.get(url(controller='login', action='register'))
Fixes tests
r1418 self.assertTrue('Sign Up to RhodeCode' in response.body)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 def test_register_err_same_username(self):
Switched forms to new validators
r2467 uname = 'test_admin'
renamed project to rhodecode
r547 response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': uname,
'password': 'test12',
'password_confirmation': 'test12',
'email': 'goodmail@domain.com',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
Switched forms to new validators
r2467 msg = validators.ValidUsername()._messages['username_exists']
msg = h.html_escape(msg % {'username': uname})
response.mustcontain(msg)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
added test for username and email case senstitive validators,...
r745 def test_register_err_same_email(self):
response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': 'test_admin_0',
'password': 'test12',
'password_confirmation': 'test12',
'email': 'test_admin@mail.com',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
added test for username and email case senstitive validators,...
r745
Switched forms to new validators
r2467 msg = validators.UniqSystemEmail()()._messages['email_taken']
response.mustcontain(msg)
added test for username and email case senstitive validators,...
r745
def test_register_err_same_email_case_sensitive(self):
response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': 'test_admin_1',
'password': 'test12',
'password_confirmation': 'test12',
'email': 'TesT_Admin@mail.COM',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
msg = validators.UniqSystemEmail()()._messages['email_taken']
response.mustcontain(msg)
added test for username and email case senstitive validators,...
r745
renamed project to rhodecode
r547 def test_register_err_wrong_data(self):
response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': 'xs',
'password': 'test',
'password_confirmation': 'test',
'email': 'goodmailm',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
self.assertEqual(response.status, '200 OK')
fixed issue with empty APIKEYS on registration #438
r2248 response.mustcontain('An email address must contain a single @')
response.mustcontain('Enter a value 6 characters long or more')
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
added test for username and email case senstitive validators,...
r745 def test_register_err_username(self):
response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': 'error user',
'password': 'test12',
'password_confirmation': 'test12',
'email': 'goodmailm',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
added test for username and email case senstitive validators,...
r745
fixed issue with empty APIKEYS on registration #438
r2248 response.mustcontain('An email address must contain a single @')
response.mustcontain('Username may only contain '
fixed tests
r1021 'alphanumeric characters underscores, '
'periods or dashes and must begin with '
fixed issue with empty APIKEYS on registration #438
r2248 'alphanumeric character')
added test for username and email case senstitive validators,...
r745
def test_register_err_case_sensitive(self):
Switched forms to new validators
r2467 usr = 'Test_Admin'
added test for username and email case senstitive validators,...
r745 response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': usr,
'password': 'test12',
'password_confirmation': 'test12',
'email': 'goodmailm',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
added test for username and email case senstitive validators,...
r745
Switched forms to new validators
r2467 response.mustcontain('An email address must contain a single @')
msg = validators.ValidUsername()._messages['username_exists']
msg = h.html_escape(msg % {'username': usr})
response.mustcontain(msg)
added test for username and email case senstitive validators,...
r745
some tests update
r723 def test_register_special_chars(self):
response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': 'xxxaxn',
'password': 'ąćźżąśśśś',
'password_confirmation': 'ąćźżąśśśś',
'email': 'goodmailm@test.plx',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
some tests update
r723
Switched forms to new validators
r2467 msg = validators.ValidPassword()._messages['invalid_password']
response.mustcontain(msg)
some tests update
r723
def test_register_password_mismatch(self):
response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': 'xs',
'password': '123qwe',
'password_confirmation': 'qwe123',
'email': 'goodmailm@test.plxa',
renamed some leftover name -> firstname
r2595 'firstname': 'test',
Switched forms to new validators
r2467 'lastname': 'test'})
msg = validators.ValidPasswordsMatch()._messages['password_mismatch']
response.mustcontain(msg)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 def test_register_ok(self):
username = 'test_regular4'
password = 'qweqwe'
email = 'marcin@test.com'
name = 'testname'
lastname = 'testlastname'
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 response = self.app.post(url(controller='login', action='register'),
Switched forms to new validators
r2467 {'username': username,
'password': password,
'password_confirmation': password,
'email': email,
renamed some leftover name -> firstname
r2595 'firstname': name,
Switched forms to new validators
r2467 'lastname': lastname,
'admin': True}) # This should be overriden
fixed issue with empty APIKEYS on registration #438
r2248 self.assertEqual(response.status, '302 Found')
self.checkSessionFlash(response, 'You have successfully registered into rhodecode')
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
Added functional test create repo with a group...
r2529 ret = self.Session().query(User).filter(User.username == 'test_regular4').one()
fixed issue with empty APIKEYS on registration #438
r2248 self.assertEqual(ret.username, username)
self.assertEqual(check_password(password, ret.password), True)
self.assertEqual(ret.email, email)
self.assertEqual(ret.name, name)
self.assertEqual(ret.lastname, lastname)
self.assertNotEqual(ret.api_key, None)
self.assertEqual(ret.admin, False)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
def test_forgot_password_wrong_mail(self):
Switched forms to new validators
r2467 bad_email = 'marcin@wrongmail.org'
fixed issue with empty APIKEYS on registration #438
r2248 response = self.app.post(
url(controller='login', action='password_reset'),
Switched forms to new validators
r2467 {'email': bad_email, }
fixed issue with empty APIKEYS on registration #438
r2248 )
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
Switched forms to new validators
r2467 msg = validators.ValidSystemEmail()._messages['non_existing_email']
msg = h.html_escape(msg % {'email': bad_email})
response.mustcontain()
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 def test_forgot_password(self):
Fixes tests
r1418 response = self.app.get(url(controller='login',
action='password_reset'))
fixed issue with empty APIKEYS on registration #438
r2248 self.assertEqual(response.status, '200 OK')
renamed project to rhodecode
r547
username = 'test_password_reset_1'
password = 'qweqwe'
email = 'marcin@python-works.com'
name = 'passwd'
lastname = 'reset'
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
Fixes tests
r1418 new = User()
new.username = username
new.password = password
new.email = email
new.name = name
new.lastname = lastname
new.api_key = generate_api_key(username)
Added functional test create repo with a group...
r2529 self.Session().add(new)
self.Session().commit()
Fixes tests
r1418
response = self.app.post(url(controller='login',
action='password_reset'),
Switched forms to new validators
r2467 {'email': email, })
Fixes tests
r1418
self.checkSessionFlash(response, 'Your password reset link was sent')
response = response.follow()
# BAD KEY
key = "bad"
response = self.app.get(url(controller='login',
action='password_reset_confirmation',
key=key))
self.assertEqual(response.status, '302 Found')
self.assertTrue(response.location.endswith(url('reset_password')))
# GOOD KEY
Refactoring of model get functions
r1530 key = User.get_by_username(username).api_key
Fixes tests
r1418 response = self.app.get(url(controller='login',
action='password_reset_confirmation',
key=key))
self.assertEqual(response.status, '302 Found')
self.assertTrue(response.location.endswith(url('login_home')))
self.checkSessionFlash(response,
('Your password reset was successful, '
'new password has been sent to your email'))
response = response.follow()