##// END OF EJS Templates
fixed typo in __get_cs_or_redirect method
fixed typo in __get_cs_or_redirect method

File last commit:

r3797:d7488551 beta
r4035:4627bc2d default
Show More
test_admin_repos.py
371 lines | 14.6 KiB | text/x-python | PythonLexer
added test for non ascii repositories and fixed users_groups test
r1398 # -*- coding: utf-8 -*-
added repo creation filesystem test
r1037 import os
Repo size - show just the size without duplicating text...
r3550 import urllib
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 from rhodecode.lib import vcs
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629 from rhodecode.model.db import Repository, RepoGroup, UserRepoToPerm, User,\
Permission
Refactor codes for scm model...
r691 from rhodecode.tests import *
Added functional test create repo with a group...
r2529 from rhodecode.model.repos_group import ReposGroupModel
from rhodecode.model.repo import RepoModel
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629 from rhodecode.model.meta import Session
more usage of fixture tools...
r3647 from rhodecode.tests.fixture import Fixture
fixture = Fixture()
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629
def _get_permission_for_user(user, repo):
perm = UserRepoToPerm.query()\
.filter(UserRepoToPerm.repository ==
Repository.get_by_repo_name(repo))\
.filter(UserRepoToPerm.user == User.get_by_username(user))\
.all()
return perm
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459
Refactor codes for scm model...
r691 class TestAdminReposController(TestController):
def test_index(self):
self.log_user()
response = self.app.get(url('repos'))
# Test response...
def test_index_as_xml(self):
response = self.app.get(url('formatted_repos', format='xml'))
def test_create_hg(self):
self.log_user()
repo_name = NEW_HG_REPO
description = 'description for newly created repo'
whitespace and formatting
r3057 response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_name=repo_name,
repo_description=description))
Initial version of landing revisions ref #483...
r2459 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 'Created repository <a href="/%s">%s</a>'
Repo size - show just the size without duplicating text...
r3550 % (repo_name, repo_name))
Refactor codes for scm model...
r691
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 #test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name).one()
Refactor codes for scm model...
r691
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 self.assertEqual(new_repo.repo_name, repo_name)
self.assertEqual(new_repo.description, description)
Refactor codes for scm model...
r691
#test if repository is visible in the list ?
response = response.follow()
Initial version of landing revisions ref #483...
r2459 response.mustcontain(repo_name)
added repo creation filesystem test
r1037
#test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
Don't catch all exceptions
r3631 except Exception:
Initial version of landing revisions ref #483...
r2459 self.fail('no repo %s in filesystem' % repo_name)
added repo creation filesystem test
r1037
added test for non ascii repositories and fixed users_groups test
r1398 def test_create_hg_non_ascii(self):
self.log_user()
non_ascii = "ąęł"
repo_name = "%s%s" % (NEW_HG_REPO, non_ascii)
repo_name_unicode = repo_name.decode('utf8')
description = 'description for newly created repo' + non_ascii
description_unicode = description.decode('utf8')
private = False
Implemented #379 defaults settings page for creation of repositories...
r3056 response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_name=repo_name,
repo_description=description))
added test for non ascii repositories and fixed users_groups test
r1398 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 u'Created repository <a href="/%s">%s</a>'
Repo size - show just the size without duplicating text...
r3550 % (urllib.quote(repo_name), repo_name_unicode))
added test for non ascii repositories and fixed users_groups test
r1398 #test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name_unicode).one()
added test for non ascii repositories and fixed users_groups test
r1398
self.assertEqual(new_repo.repo_name, repo_name_unicode)
self.assertEqual(new_repo.description, description_unicode)
#test if repository is visible in the list ?
response = response.follow()
Initial version of landing revisions ref #483...
r2459 response.mustcontain(repo_name)
added test for non ascii repositories and fixed users_groups test
r1398
#test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
Don't catch all exceptions
r3631 except Exception:
Initial version of landing revisions ref #483...
r2459 self.fail('no repo %s in filesystem' % repo_name)
added test for non ascii repositories and fixed users_groups test
r1398
revert name change broken in 28305020a4ed127e8aca2f1a10e30d902efb6238
r3675 def test_create_hg_in_group(self):
Added functional test create repo with a group...
r2529 self.log_user()
## create GROUP
group_name = 'sometest'
gr = ReposGroupModel().create(group_name=group_name,
Group management delegation:...
r3222 group_description='test',
owner=TEST_USER_ADMIN_LOGIN)
synced vcs with upstream...
r3797 Session().commit()
Added functional test create repo with a group...
r2529
repo_name = 'ingroup'
repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
description = 'description for newly created repo'
Implemented #379 defaults settings page for creation of repositories...
r3056 response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_name=repo_name,
repo_description=description,
repo_group=gr.group_id,))
Added functional test create repo with a group...
r2529 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 'Created repository <a href="/%s">%s</a>'
fixed broken flash test
r3673 % (repo_name_full, repo_name))
Added functional test create repo with a group...
r2529 #test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Added functional test create repo with a group...
r2529 .filter(Repository.repo_name == repo_name_full).one()
self.assertEqual(new_repo.repo_name, repo_name_full)
self.assertEqual(new_repo.description, description)
#test if repository is visible in the list ?
response = response.follow()
response.mustcontain(repo_name_full)
#test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full))
Don't catch all exceptions
r3631 except Exception:
Added functional test create repo with a group...
r2529 ReposGroupModel().delete(group_name)
synced vcs with upstream...
r3797 Session().commit()
Added functional test create repo with a group...
r2529 self.fail('no repo %s in filesystem' % repo_name)
RepoModel().delete(repo_name_full)
ReposGroupModel().delete(group_name)
synced vcs with upstream...
r3797 Session().commit()
added repo creation filesystem test
r1037
Refactor codes for scm model...
r691 def test_create_git(self):
self.log_user()
repo_name = NEW_GIT_REPO
description = 'description for newly created repo'
Implemented #379 defaults settings page for creation of repositories...
r3056
response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_type='git',
repo_name=repo_name,
repo_description=description))
Initial version of landing revisions ref #483...
r2459 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 'Created repository <a href="/%s">%s</a>'
Repo size - show just the size without duplicating text...
r3550 % (repo_name, repo_name))
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459 #test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name).one()
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459 self.assertEqual(new_repo.repo_name, repo_name)
self.assertEqual(new_repo.description, description)
Refactor codes for scm model...
r691
#test if repository is visible in the list ?
response = response.follow()
Initial version of landing revisions ref #483...
r2459 response.mustcontain(repo_name)
Refactor codes for scm model...
r691
added repo creation filesystem test
r1037 #test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
Don't catch all exceptions
r3631 except Exception:
Initial version of landing revisions ref #483...
r2459 self.fail('no repo %s in filesystem' % repo_name)
def test_create_git_non_ascii(self):
self.log_user()
non_ascii = "ąęł"
repo_name = "%s%s" % (NEW_GIT_REPO, non_ascii)
repo_name_unicode = repo_name.decode('utf8')
description = 'description for newly created repo' + non_ascii
description_unicode = description.decode('utf8')
private = False
Implemented #379 defaults settings page for creation of repositories...
r3056 response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_type='git',
repo_name=repo_name,
repo_description=description))
Initial version of landing revisions ref #483...
r2459 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 u'Created repository <a href="/%s">%s</a>'
Repo size - show just the size without duplicating text...
r3550 % (urllib.quote(repo_name), repo_name_unicode))
Initial version of landing revisions ref #483...
r2459
#test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name_unicode).one()
self.assertEqual(new_repo.repo_name, repo_name_unicode)
self.assertEqual(new_repo.description, description_unicode)
#test if repository is visible in the list ?
response = response.follow()
response.mustcontain(repo_name)
#test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
Don't catch all exceptions
r3631 except Exception:
Initial version of landing revisions ref #483...
r2459 self.fail('no repo %s in filesystem' % repo_name)
Refactor codes for scm model...
r691
def test_update(self):
response = self.app.put(url('repo', repo_name=HG_REPO))
def test_update_browser_fakeout(self):
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 response = self.app.post(url('repo', repo_name=HG_REPO),
params=dict(_method='put'))
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459 def test_delete_hg(self):
Refactor codes for scm model...
r691 self.log_user()
repo_name = 'vcs_test_new_to_delete'
description = 'description for newly created repo'
Implemented #379 defaults settings page for creation of repositories...
r3056 response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_type='hg',
repo_name=repo_name,
repo_description=description))
Initial version of landing revisions ref #483...
r2459 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 'Created repository <a href="/%s">%s</a>'
Repo size - show just the size without duplicating text...
r3550 % (repo_name, repo_name))
Refactor codes for scm model...
r691 #test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name).one()
Refactor codes for scm model...
r691
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 self.assertEqual(new_repo.repo_name, repo_name)
self.assertEqual(new_repo.description, description)
Refactor codes for scm model...
r691
#test if repository is visible in the list ?
response = response.follow()
Initial version of landing revisions ref #483...
r2459 response.mustcontain(repo_name)
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459 #test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
Don't catch all exceptions
r3631 except Exception:
Initial version of landing revisions ref #483...
r2459 self.fail('no repo %s in filesystem' % repo_name)
Refactor codes for scm model...
r691
response = self.app.delete(url('repo', repo_name=repo_name))
unified flash msg tests
r3640 self.checkSessionFlash(response, 'Deleted repository %s' % (repo_name))
Refactor codes for scm model...
r691
response.follow()
#check if repo was deleted from db
synced vcs with upstream...
r3797 deleted_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name).scalar()
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366
self.assertEqual(deleted_repo, None)
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459 self.assertEqual(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name)),
False)
def test_delete_git(self):
self.log_user()
repo_name = 'vcs_test_new_to_delete'
description = 'description for newly created repo'
private = False
whitespace and formatting
r3057 response = self.app.post(url('repos'),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
Implemented #379 defaults settings page for creation of repositories...
r3056 repo_type='git',
repo_name=repo_name,
repo_description=description))
Initial version of landing revisions ref #483...
r2459 self.checkSessionFlash(response,
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 'Created repository <a href="/%s">%s</a>'
Repo size - show just the size without duplicating text...
r3550 % (repo_name, repo_name))
Initial version of landing revisions ref #483...
r2459 #test if the repo was created in the database
synced vcs with upstream...
r3797 new_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name).one()
self.assertEqual(new_repo.repo_name, repo_name)
self.assertEqual(new_repo.description, description)
#test if repository is visible in the list ?
response = response.follow()
response.mustcontain(repo_name)
#test if repository was created on filesystem
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
Don't catch all exceptions
r3631 except Exception:
Initial version of landing revisions ref #483...
r2459 self.fail('no repo %s in filesystem' % repo_name)
response = self.app.delete(url('repo', repo_name=repo_name))
unified flash msg tests
r3640 self.checkSessionFlash(response, 'Deleted repository %s' % (repo_name))
Initial version of landing revisions ref #483...
r2459
response.follow()
#check if repo was deleted from db
synced vcs with upstream...
r3797 deleted_repo = Session().query(Repository)\
Initial version of landing revisions ref #483...
r2459 .filter(Repository.repo_name == repo_name).scalar()
self.assertEqual(deleted_repo, None)
self.assertEqual(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name)),
False)
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366
def test_delete_repo_with_group(self):
#TODO:
pass
Refactor codes for scm model...
r691
def test_delete_browser_fakeout(self):
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 response = self.app.post(url('repo', repo_name=HG_REPO),
params=dict(_method='delete'))
Refactor codes for scm model...
r691
Initial version of landing revisions ref #483...
r2459 def test_show_hg(self):
Refactor codes for scm model...
r691 self.log_user()
response = self.app.get(url('repo', repo_name=HG_REPO))
Initial version of landing revisions ref #483...
r2459 def test_show_git(self):
self.log_user()
response = self.app.get(url('repo', repo_name=GIT_REPO))
Refactor codes for scm model...
r691
def test_edit(self):
response = self.app.get(url('edit_repo', repo_name=HG_REPO))
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629
def test_set_private_flag_sets_default_to_none(self):
self.log_user()
#initially repository perm should be read
perm = _get_permission_for_user(user='default', repo=HG_REPO)
self.assertTrue(len(perm), 1)
self.assertEqual(perm[0].permission.permission_name, 'repository.read')
self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False)
response = self.app.put(url('repo', repo_name=HG_REPO),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=1,
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629 repo_name=HG_REPO,
user=TEST_USER_ADMIN_LOGIN))
self.checkSessionFlash(response,
msg='Repository %s updated successfully' % (HG_REPO))
self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, True)
#now the repo default permission should be None
perm = _get_permission_for_user(user='default', repo=HG_REPO)
self.assertTrue(len(perm), 1)
self.assertEqual(perm[0].permission.permission_name, 'repository.none')
response = self.app.put(url('repo', repo_name=HG_REPO),
more usage of fixture tools...
r3647 fixture._get_repo_create_params(repo_private=False,
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629 repo_name=HG_REPO,
user=TEST_USER_ADMIN_LOGIN))
self.checkSessionFlash(response,
msg='Repository %s updated successfully' % (HG_REPO))
self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False)
#we turn off private now the repo default permission should stay None
perm = _get_permission_for_user(user='default', repo=HG_REPO)
self.assertTrue(len(perm), 1)
self.assertEqual(perm[0].permission.permission_name, 'repository.none')
#update this permission back
perm[0].permission = Permission.get_by_key('repository.read')
Session().add(perm[0])
Session().commit()