##// END OF EJS Templates
sync alternative gravatar options to other .ini files...
sync alternative gravatar options to other .ini files - changelog update

File last commit:

r2709:d2d35cf2 beta
r2736:3aad896d beta
Show More
test_admin_users.py
290 lines | 11.5 KiB | text/x-python | PythonLexer
Switched forms to new validators
r2467 from sqlalchemy.orm.exc import NoResultFound
Refactor codes for scm model...
r691 from rhodecode.tests import *
fixed repo_create permission by adding missing commit statements...
r1758 from rhodecode.model.db import User, Permission
Refactor codes for scm model...
r691 from rhodecode.lib.auth import check_password
fixed repo_create permission by adding missing commit statements...
r1758 from rhodecode.model.user import UserModel
Switched forms to new validators
r2467 from rhodecode.model import validators
from rhodecode.lib import helpers as h
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 from rhodecode.model.meta import Session
Switched forms to new validators
r2467
Refactor codes for scm model...
r691
class TestAdminUsersController(TestController):
def test_index(self):
fixed repo_create permission by adding missing commit statements...
r1758 self.log_user()
Refactor codes for scm model...
r691 response = self.app.get(url('users'))
# Test response...
def test_index_as_xml(self):
response = self.app.get(url('formatted_users', format='xml'))
def test_create(self):
self.log_user()
username = 'newtestuser'
password = 'test12'
implements #237 added password confirmation for my account and admin edit user.
r1597 password_confirmation = password
Refactor codes for scm model...
r691 name = 'name'
lastname = 'lastname'
email = 'mail@mail.com'
auto white-space removal
r1818 response = self.app.post(url('users'),
Switched forms to new validators
r2467 {'username': username,
'password': password,
'password_confirmation': password_confirmation,
Renamed name to firstname in forms...
r2544 'firstname': name,
Switched forms to new validators
r2467 'active': True,
'lastname': lastname,
'email': email})
Refactor codes for scm model...
r691
Switched forms to new validators
r2467 self.checkSessionFlash(response, '''created user %s''' % (username))
Refactor codes for scm model...
r691
fixed repo_create permission by adding missing commit statements...
r1758 new_user = self.Session.query(User).\
filter(User.username == username).one()
Refactor codes for scm model...
r691
Switched forms to new validators
r2467 self.assertEqual(new_user.username, username)
self.assertEqual(check_password(password, new_user.password), True)
self.assertEqual(new_user.name, name)
self.assertEqual(new_user.lastname, lastname)
self.assertEqual(new_user.email, email)
Refactor codes for scm model...
r691
response.follow()
response = response.follow()
fixed test after users table rewrite
r2661 response.mustcontain("""newtestuser""")
Refactor codes for scm model...
r691
def test_create_err(self):
self.log_user()
username = 'new_user'
password = ''
name = 'name'
lastname = 'lastname'
email = 'errmail.com'
Switched forms to new validators
r2467 response = self.app.post(url('users'), {'username': username,
'password': password,
'name': name,
'active': False,
'lastname': lastname,
'email': email})
Refactor codes for scm model...
r691
Switched forms to new validators
r2467 msg = validators.ValidUsername(False, {})._messages['system_invalid_username']
msg = h.html_escape(msg % {'username': 'new_user'})
response.mustcontain("""<span class="error-message">%s</span>""" % msg)
response.mustcontain("""<span class="error-message">Please enter a value</span>""")
response.mustcontain("""<span class="error-message">An email address must contain a single @</span>""")
Refactor codes for scm model...
r691
def get_user():
commit less models...
r1749 self.Session.query(User).filter(User.username == username).one()
Refactor codes for scm model...
r691
self.assertRaises(NoResultFound, get_user), 'found user in database'
def test_new(self):
fixed repo_create permission by adding missing commit statements...
r1758 self.log_user()
Refactor codes for scm model...
r691 response = self.app.get(url('new_user'))
def test_new_as_xml(self):
response = self.app.get(url('formatted_new_user', format='xml'))
Renamed name to firstname in forms...
r2544 @parameterized.expand([('firstname', 'new_username'),
('lastname', 'new_username'),
('admin', True),
('admin', False),
('ldap_dn', 'test'),
('ldap_dn', None),
('active', False),
('active', True),
('email', 'some@email.com'),
])
def test_update(self, name, expected):
self.log_user()
uname = 'testme'
usr = UserModel().create_or_update(username=uname, password='qweqwe',
email='testme@rhodecod.org')
self.Session().commit()
params = usr.get_api_data()
params.update({name: expected})
params.update({'password_confirmation': ''})
params.update({'new_password': ''})
if name == 'email':
params['emails'] = [expected]
if name == 'ldap_dn':
#cannot update this via form
params['ldap_dn'] = None
try:
response = self.app.put(url('user', id=usr.user_id), params)
self.checkSessionFlash(response, '''User updated successfully''')
updated_user = User.get_by_username(uname)
updated_params = updated_user.get_api_data()
updated_params.update({'password_confirmation': ''})
updated_params.update({'new_password': ''})
self.assertEqual(params, updated_params)
finally:
UserModel().delete('testme')
Refactor codes for scm model...
r691
def test_update_browser_fakeout(self):
response = self.app.post(url('user', id=1), params=dict(_method='put'))
def test_delete(self):
self.log_user()
username = 'newtestuserdeleteme'
password = 'test12'
name = 'name'
lastname = 'lastname'
email = 'todeletemail@mail.com'
Switched forms to new validators
r2467 response = self.app.post(url('users'), {'username': username,
'password': password,
'password_confirmation': password,
Renamed name to firstname in forms...
r2544 'firstname': name,
Switched forms to new validators
r2467 'active': True,
'lastname': lastname,
'email': email})
Refactor codes for scm model...
r691
response = response.follow()
fixed repo_create permission by adding missing commit statements...
r1758 new_user = self.Session.query(User)\
.filter(User.username == username).one()
Refactor codes for scm model...
r691 response = self.app.delete(url('user', id=new_user.user_id))
auto white-space removal
r1818 self.assertTrue("""successfully deleted user""" in
fixed repo_create permission by adding missing commit statements...
r1758 response.session['flash'][0])
Refactor codes for scm model...
r691
def test_delete_browser_fakeout(self):
auto white-space removal
r1818 response = self.app.post(url('user', id=1),
fixed repo_create permission by adding missing commit statements...
r1758 params=dict(_method='delete'))
Refactor codes for scm model...
r691
def test_show(self):
response = self.app.get(url('user', id=1))
def test_show_as_xml(self):
response = self.app.get(url('formatted_user', id=1, format='xml'))
def test_edit(self):
fixed repo_create permission by adding missing commit statements...
r1758 self.log_user()
user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
response = self.app.get(url('edit_user', id=user.user_id))
def test_add_perm_create_repo(self):
self.log_user()
perm_none = Permission.get_by_key('hg.create.none')
perm_create = Permission.get_by_key('hg.create.repository')
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 user = UserModel().create_or_update(username='dummy', password='qwe',
email='dummy', firstname='a',
lastname='b')
Session().commit()
uid = user.user_id
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 try:
#User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(user, perm_none), False)
self.assertEqual(UserModel().has_perm(user, perm_create), False)
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 response = self.app.post(url('user_perm', id=uid),
params=dict(_method='put',
create_repo_perm=True))
perm_none = Permission.get_by_key('hg.create.none')
perm_create = Permission.get_by_key('hg.create.repository')
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 #User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(uid, perm_none), False)
self.assertEqual(UserModel().has_perm(uid, perm_create), True)
finally:
UserModel().delete(uid)
Session().commit()
fixed repo_create permission by adding missing commit statements...
r1758
def test_revoke_perm_create_repo(self):
self.log_user()
perm_none = Permission.get_by_key('hg.create.none')
perm_create = Permission.get_by_key('hg.create.repository')
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 user = UserModel().create_or_update(username='dummy', password='qwe',
email='dummy', firstname='a',
lastname='b')
Session().commit()
uid = user.user_id
try:
#User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(user, perm_none), False)
self.assertEqual(UserModel().has_perm(user, perm_create), False)
response = self.app.post(url('user_perm', id=uid),
params=dict(_method='put'))
perm_none = Permission.get_by_key('hg.create.none')
perm_create = Permission.get_by_key('hg.create.repository')
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 #User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(uid, perm_none), True)
self.assertEqual(UserModel().has_perm(uid, perm_create), False)
finally:
UserModel().delete(uid)
Session().commit()
def test_add_perm_fork_repo(self):
self.log_user()
perm_none = Permission.get_by_key('hg.fork.none')
perm_fork = Permission.get_by_key('hg.fork.repository')
user = UserModel().create_or_update(username='dummy', password='qwe',
email='dummy', firstname='a',
lastname='b')
Session().commit()
uid = user.user_id
try:
#User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(user, perm_none), False)
self.assertEqual(UserModel().has_perm(user, perm_fork), False)
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 response = self.app.post(url('user_perm', id=uid),
params=dict(_method='put',
create_repo_perm=True))
perm_none = Permission.get_by_key('hg.create.none')
perm_create = Permission.get_by_key('hg.create.repository')
#User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(uid, perm_none), False)
self.assertEqual(UserModel().has_perm(uid, perm_create), True)
finally:
UserModel().delete(uid)
Session().commit()
def test_revoke_perm_fork_repo(self):
self.log_user()
perm_none = Permission.get_by_key('hg.fork.none')
perm_fork = Permission.get_by_key('hg.fork.repository')
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 user = UserModel().create_or_update(username='dummy', password='qwe',
email='dummy', firstname='a',
lastname='b')
Session().commit()
uid = user.user_id
try:
#User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(user, perm_none), False)
self.assertEqual(UserModel().has_perm(user, perm_fork), False)
fixed repo_create permission by adding missing commit statements...
r1758
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 response = self.app.post(url('user_perm', id=uid),
params=dict(_method='put'))
perm_none = Permission.get_by_key('hg.create.none')
perm_create = Permission.get_by_key('hg.create.repository')
#User should have None permission on creation repository
self.assertEqual(UserModel().has_perm(uid, perm_none), True)
self.assertEqual(UserModel().has_perm(uid, perm_create), False)
finally:
UserModel().delete(uid)
Session().commit()
Refactor codes for scm model...
r691
def test_edit_as_xml(self):
response = self.app.get(url('formatted_edit_user', id=1, format='xml'))