%if c.site_name:
${c.site_name}
diff --git a/kallithea/tests/__init__.py b/kallithea/tests/__init__.py
--- a/kallithea/tests/__init__.py
+++ b/kallithea/tests/__init__.py
@@ -157,6 +157,12 @@ def get_new_dir(title):
return get_normalized_path(path)
+import logging
+
+class NullHandler(logging.Handler):
+ def emit(self, record):
+ pass
+
def init_stack(config=None):
if not config:
config = pylons.test.pylonsapp.config
@@ -167,6 +173,8 @@ def init_stack(config=None):
# Initialize a translator for tests that utilize i18n
translator = _get_translator(pylons.config.get('lang'))
pylons.translator._push_object(translator)
+ h = NullHandler()
+ logging.getLogger("kallithea").addHandler(h)
class BaseTestCase(unittest.TestCase):
diff --git a/kallithea/tests/fixture.py b/kallithea/tests/fixture.py
--- a/kallithea/tests/fixture.py
+++ b/kallithea/tests/fixture.py
@@ -228,7 +228,7 @@ class Fixture(object):
def create_gist(self, **kwargs):
form_data = {
- 'description': 'new-gist',
+ 'description': u'new-gist',
'owner': TEST_USER_ADMIN_LOGIN,
'gist_type': GistModel.cls.GIST_PUBLIC,
'lifetime': -1,
diff --git a/kallithea/tests/functional/test_admin_auth_settings.py b/kallithea/tests/functional/test_admin_auth_settings.py
--- a/kallithea/tests/functional/test_admin_auth_settings.py
+++ b/kallithea/tests/functional/test_admin_auth_settings.py
@@ -23,7 +23,7 @@ class TestAuthSettingsController(TestCon
def test_ldap_save_settings(self):
self.log_user()
- if ldap_lib_installed:
+ if not ldap_lib_installed:
raise SkipTest('skipping due to missing ldap lib')
params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
@@ -53,7 +53,7 @@ class TestAuthSettingsController(TestCon
def test_ldap_error_form_wrong_port_number(self):
self.log_user()
- if ldap_lib_installed:
+ if not ldap_lib_installed:
raise SkipTest('skipping due to missing ldap lib')
params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
@@ -80,7 +80,7 @@ class TestAuthSettingsController(TestCon
def test_ldap_error_form(self):
self.log_user()
- if ldap_lib_installed:
+ if not ldap_lib_installed:
raise SkipTest('skipping due to missing ldap lib')
params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
diff --git a/kallithea/tests/functional/test_admin_gists.py b/kallithea/tests/functional/test_admin_gists.py
--- a/kallithea/tests/functional/test_admin_gists.py
+++ b/kallithea/tests/functional/test_admin_gists.py
@@ -5,7 +5,7 @@ from kallithea.model.db import User, Gis
def _create_gist(f_name, content='some gist', lifetime=-1,
- description='gist-desc', gist_type='public',
+ description=u'gist-desc', gist_type='public',
owner=TEST_USER_ADMIN_LOGIN):
gist_mapping = {
f_name: {'content': content}
@@ -33,7 +33,7 @@ class TestGistsController(TestController
g1 = _create_gist('gist1').gist_access_id
g2 = _create_gist('gist2', lifetime=1400).gist_access_id
- g3 = _create_gist('gist3', description='gist3-desc').gist_access_id
+ g3 = _create_gist('gist3', description=u'gist3-desc').gist_access_id
g4 = _create_gist('gist4', gist_type='private').gist_access_id
response = self.app.get(url('gists'))
# Test response...
diff --git a/kallithea/tests/functional/test_admin_repos.py b/kallithea/tests/functional/test_admin_repos.py
--- a/kallithea/tests/functional/test_admin_repos.py
+++ b/kallithea/tests/functional/test_admin_repos.py
@@ -79,7 +79,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
- except Exception:
+ except vcs.exceptions.VCSError:
self.fail('no repo %s in filesystem' % repo_name)
RepoModel().delete(repo_name)
@@ -118,7 +118,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
- except Exception:
+ except vcs.exceptions.VCSError:
self.fail('no repo %s in filesystem' % repo_name)
def test_create_in_group(self):
@@ -166,7 +166,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full))
- except Exception:
+ except vcs.exceptions.VCSError:
RepoGroupModel().delete(group_name)
Session().commit()
self.fail('no repo %s in filesystem' % repo_name)
@@ -254,7 +254,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full))
- except Exception:
+ except vcs.exceptions.VCSError:
RepoGroupModel().delete(group_name)
Session().commit()
self.fail('no repo %s in filesystem' % repo_name)
@@ -310,7 +310,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full))
- except Exception:
+ except vcs.exceptions.VCSError:
RepoGroupModel().delete(group_name)
Session().commit()
self.fail('no repo %s in filesystem' % repo_name)
@@ -384,7 +384,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
- except Exception:
+ except vcs.exceptions.VCSError:
self.fail('no repo %s in filesystem' % repo_name)
response = self.app.delete(url('repo', repo_name=repo_name))
@@ -435,7 +435,7 @@ class _BaseTest(TestController):
# test if the repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
- except Exception:
+ except vcs.exceptions.VCSError:
self.fail('no repo %s in filesystem' % repo_name)
response = self.app.delete(url('repo', repo_name=repo_name))
diff --git a/kallithea/tests/functional/test_admin_user_groups.py b/kallithea/tests/functional/test_admin_user_groups.py
--- a/kallithea/tests/functional/test_admin_user_groups.py
+++ b/kallithea/tests/functional/test_admin_user_groups.py
@@ -23,7 +23,9 @@ class TestAdminUsersGroupsController(Tes
response.follow()
self.checkSessionFlash(response,
- 'Created user group %s' % TEST_USER_GROUP)
+ 'Created user group %s' % TEST_USER_GROUP)
def test_new(self):
response = self.app.get(url('new_users_group'))
@@ -45,7 +47,7 @@ class TestAdminUsersGroupsController(Tes
response.follow()
self.checkSessionFlash(response,
- 'Created user group %s' % users_group_name)
+ 'Created user group ')
gr = Session().query(UserGroup)\
.filter(UserGroup.users_group_name == users_group_name).one()
@@ -68,7 +70,7 @@ class TestAdminUsersGroupsController(Tes
ug = UserGroup.get_by_group_name(users_group_name)
self.checkSessionFlash(response,
- 'Created user group %s' % users_group_name)
+ 'Created user group ')
## ENABLE REPO CREATE ON A GROUP
response = self.app.put(url('edit_user_group_default_perms',
id=ug.users_group_id),
@@ -138,7 +140,7 @@ class TestAdminUsersGroupsController(Tes
ug = UserGroup.get_by_group_name(users_group_name)
self.checkSessionFlash(response,
- 'Created user group %s' % users_group_name)
+ 'Created user group ')
## ENABLE REPO CREATE ON A GROUP
response = self.app.put(url('edit_user_group_default_perms',
id=ug.users_group_id),
diff --git a/kallithea/tests/functional/test_admin_users.py b/kallithea/tests/functional/test_admin_users.py
--- a/kallithea/tests/functional/test_admin_users.py
+++ b/kallithea/tests/functional/test_admin_users.py
@@ -60,7 +60,8 @@ class TestAdminUsersController(TestContr
'extern_type': 'internal',
'email': email})
- self.checkSessionFlash(response, '''Created user %s''' % (username))
+ self.checkSessionFlash(response, '''Created user
%s''' % (username))
new_user = Session().query(User).\
filter(User.username == username).one()
@@ -166,6 +167,79 @@ class TestAdminUsersController(TestContr
self.checkSessionFlash(response, 'Successfully deleted user')
+ def test_delete_repo_err(self):
+ self.log_user()
+ username = 'repoerr'
+ reponame = 'repoerr_fail'
+
+ fixture.create_user(name=username)
+ fixture.create_repo(name=reponame, cur_user=username)
+
+ new_user = Session().query(User)\
+ .filter(User.username == username).one()
+ response = self.app.delete(url('user', id=new_user.user_id))
+ self.checkSessionFlash(response, 'User "%s" still '
+ 'owns 1 repositories and cannot be removed. '
+ 'Switch owners or remove those repositories: '
+ '%s' % (username, reponame))
+
+ response = self.app.delete(url('repo', repo_name=reponame))
+ self.checkSessionFlash(response, 'Deleted repository %s' % reponame)
+
+ response = self.app.delete(url('user', id=new_user.user_id))
+ self.checkSessionFlash(response, 'Successfully deleted user')
+
+ def test_delete_repo_group_err(self):
+ self.log_user()
+ username = 'repogrouperr'
+ groupname = 'repogroup_fail'
+
+ fixture.create_user(name=username)
+ fixture.create_repo_group(name=groupname, cur_user=username)
+
+ new_user = Session().query(User)\
+ .filter(User.username == username).one()
+ response = self.app.delete(url('user', id=new_user.user_id))
+ self.checkSessionFlash(response, 'User "%s" still '
+ 'owns 1 repository groups and cannot be removed. '
+ 'Switch owners or remove those repository groups: '
+ '%s' % (username, groupname))
+
+ # Relevant _if_ the user deletion succeeded to make sure we can render groups without owner
+ # rg = RepoGroup.get_by_group_name(group_name=groupname)
+ # response = self.app.get(url('repos_groups', id=rg.group_id))
+
+ response = self.app.delete(url('delete_repo_group', group_name=groupname))
+ self.checkSessionFlash(response, 'Removed repository group %s' % groupname)
+
+ response = self.app.delete(url('user', id=new_user.user_id))
+ self.checkSessionFlash(response, 'Successfully deleted user')
+
+ def test_delete_user_group_err(self):
+ self.log_user()
+ username = 'usergrouperr'
+ groupname = 'usergroup_fail'
+
+ fixture.create_user(name=username)
+ ug = fixture.create_user_group(name=groupname, cur_user=username)
+
+ new_user = Session().query(User)\
+ .filter(User.username == username).one()
+ response = self.app.delete(url('user', id=new_user.user_id))
+ self.checkSessionFlash(response, 'User "%s" still '
+ 'owns 1 user groups and cannot be removed. '
+ 'Switch owners or remove those user groups: '
+ '%s' % (username, groupname))
+
+ # TODO: why do this fail?
+ #response = self.app.delete(url('delete_users_group', id=groupname))
+ #self.checkSessionFlash(response, 'Removed user group %s' % groupname)
+
+ fixture.destroy_user_group(ug.users_group_id)
+
+ response = self.app.delete(url('user', id=new_user.user_id))
+ self.checkSessionFlash(response, 'Successfully deleted user')
+
def test_show(self):
response = self.app.get(url('user', id=1))
diff --git a/kallithea/tests/functional/test_login.py b/kallithea/tests/functional/test_login.py
--- a/kallithea/tests/functional/test_login.py
+++ b/kallithea/tests/functional/test_login.py
@@ -347,7 +347,7 @@ class TestLoginController(TestController
self.assertEqual(['ChangesetController:changeset_raw'],
whitelist['api_access_controllers_whitelist'])
- new_api_key = ApiKeyModel().create(TEST_USER_ADMIN_LOGIN, 'test')
+ new_api_key = ApiKeyModel().create(TEST_USER_ADMIN_LOGIN, u'test')
Session().commit()
with fixture.anon_access(False):
self.app.get(url(controller='changeset',
@@ -361,7 +361,7 @@ class TestLoginController(TestController
self.assertEqual(['ChangesetController:changeset_raw'],
whitelist['api_access_controllers_whitelist'])
- new_api_key = ApiKeyModel().create(TEST_USER_ADMIN_LOGIN, 'test')
+ new_api_key = ApiKeyModel().create(TEST_USER_ADMIN_LOGIN, u'test')
Session().commit()
#patch the api key and make it expired
new_api_key.expires = 0
diff --git a/kallithea/tests/other/test_libs.py b/kallithea/tests/other/test_libs.py
--- a/kallithea/tests/other/test_libs.py
+++ b/kallithea/tests/other/test_libs.py
@@ -126,7 +126,12 @@ class TestLibs(BaseTestCase):
(dict(hours= -24 * 5), u'5 days ago'),
(dict(months= -1), u'1 month ago'),
(dict(months= -1, days= -2), u'1 month and 2 days ago'),
+ (dict(months= -1, days= -20), u'1 month and 19 days ago'),
(dict(years= -1, months= -1), u'1 year and 1 month ago'),
+ (dict(years= -1, months= -10), u'1 year and 10 months ago'),
+ (dict(years= -2, months= -4), u'2 years and 4 months ago'),
+ (dict(years= -2, months= -11), u'2 years and 11 months ago'),
+ (dict(years= -3, months= -2), u'3 years and 2 months ago'),
])
def test_age(self, age_args, expected):
from kallithea.lib.utils2 import age
@@ -136,7 +141,30 @@ class TestLibs(BaseTestCase):
self.assertEqual(age(n + delt(**age_args), now=n), expected)
@parameterized.expand([
+ (dict(), u'just now'),
+ (dict(seconds= -1), u'1 second ago'),
+ (dict(seconds= -60 * 2), u'2 minutes ago'),
+ (dict(hours= -1), u'1 hour ago'),
+ (dict(hours= -24), u'1 day ago'),
+ (dict(hours= -24 * 5), u'5 days ago'),
+ (dict(months= -1), u'1 month ago'),
+ (dict(months= -1, days= -2), u'1 month ago'),
+ (dict(months= -1, days= -20), u'1 month ago'),
+ (dict(years= -1, months= -1), u'13 months ago'),
+ (dict(years= -1, months= -10), u'22 months ago'),
+ (dict(years= -2, months= -4), u'2 years ago'),
+ (dict(years= -2, months= -11), u'3 years ago'),
+ (dict(years= -3, months= -2), u'3 years ago'),
+ (dict(years= -4, months= -8), u'5 years ago'),
+ ])
+ def test_age_short(self, age_args, expected):
+ from kallithea.lib.utils2 import age
+ from dateutil import relativedelta
+ n = datetime.datetime(year=2012, month=5, day=17)
+ delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
+ self.assertEqual(age(n + delt(**age_args), show_short_version=True, now=n), expected)
+ @parameterized.expand([
(dict(), u'just now'),
(dict(seconds=1), u'in 1 second'),
(dict(seconds=60 * 2), u'in 2 minutes'),
@@ -339,7 +367,6 @@ class TestLibs(BaseTestCase):
("_21/121", '21'),
("/_21/_12", '21'),
("_21/rc/foo", '21'),
-
])
def test_get_repo_by_id(self, test, expected):
from kallithea.lib.utils import _extract_id_from_repo_name
diff --git a/kallithea/tests/scripts/test_concurency.py b/kallithea/tests/scripts/test_concurency.py
--- a/kallithea/tests/scripts/test_concurency.py
+++ b/kallithea/tests/scripts/test_concurency.py
@@ -200,12 +200,12 @@ if __name__ == '__main__':
try:
METHOD = sys.argv[3]
- except Exception:
+ except IndexError:
pass
try:
backend = sys.argv[4]
- except Exception:
+ except IndexError:
backend = 'hg'
if METHOD == 'pull':
diff --git a/whitespacecleanup.sh b/whitespacecleanup.sh
new file mode 100755
--- /dev/null
+++ b/whitespacecleanup.sh
@@ -0,0 +1,18 @@
+#!/bin/bash -x
+
+# Enforce some consistency in whitespace - just to avoid spurious whitespaces changes
+
+files=`hg loc '*.py' '*.html' '*.css' '*.rst' '*.txt' '*.js' | egrep -v '/lockfiles.py|LICENSE-MERGELY.html|/codemirror/|/fontello/|(graph|mergely|native.history|select2/select2|yui.flot)\.js$'`
+sed -i "s,`printf '\t'`, ,g" $files
+sed -i "s, *$,,g" $files
+
+sed -i 's,\([^ /]\){,\1 {,g' `hg loc '*.css'`
+sed -i 's|^\([^ /].*,\)\([^ ]\)|\1 \2|g' `hg loc '*.css'`
+
+sed -i 's/^\( [^: ]*\) *: *\([^/]\)/\1: \2/g' kallithea/public/css/{style,contextbar}.css
+sed -i '1s|, |,|g' kallithea/public/css/{style,contextbar}.css
+sed -i 's/^\([^ ,/]\+ [^,]*[^ ,]\) *, *\(.\)/\1,\n\2/g' kallithea/public/css/{style,contextbar}.css
+sed -i 's/^\([^ ,/].*\) */\1 /g' kallithea/public/css/{style,contextbar}.css
+sed -i 's,^--$,-- ,g' kallithea/templates/email_templates/main.txt
+
+hg diff