# HG changeset patch # User Marcin Kuzminski # Date 2010-11-14 21:54:16 # Node ID 7486da5f06280fbf21f725bc0963f681d933e71d # Parent 4685f3eafd3531b4ff7f973ef82b51e3fbeb83f6 Refactor codes for scm model Some test updates, added test for admin user controller diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -6,7 +6,7 @@ from rhodecode.config.routing import mak from rhodecode.lib.auth import set_available_permissions, set_base_path from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config from rhodecode.model import init_model -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from sqlalchemy import engine_from_config import logging import os @@ -71,7 +71,7 @@ def load_environment(global_conf, app_co config['pylons.app_globals'].baseui = make_ui('db') g = config['pylons.app_globals'] - repo2db_mapper(HgModel().repo_scan(g.paths[0][1], g.baseui, initial)) + repo2db_mapper(ScmModel().repo_scan(g.paths[0][1], g.baseui, initial)) set_available_permissions(config) set_base_path(config) set_rhodecode_config(config) diff --git a/rhodecode/controllers/admin/repos.py b/rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py +++ b/rhodecode/controllers/admin/repos.py @@ -35,7 +35,7 @@ from rhodecode.lib.base import BaseContr from rhodecode.lib.utils import invalidate_cache, action_logger from rhodecode.model.db import User from rhodecode.model.forms import RepoForm -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from rhodecode.model.repo import RepoModel import formencode import logging @@ -60,7 +60,7 @@ class ReposController(BaseController): def index(self, format='html'): """GET /repos: All items in the collection""" # url('repos') - cached_repo_list = HgModel().get_repos() + cached_repo_list = ScmModel().get_repos() c.repos_list = sorted(cached_repo_list, key=itemgetter('name_sort')) return render('admin/repos/repos.html') diff --git a/rhodecode/controllers/admin/settings.py b/rhodecode/controllers/admin/settings.py --- a/rhodecode/controllers/admin/settings.py +++ b/rhodecode/controllers/admin/settings.py @@ -36,7 +36,7 @@ from rhodecode.lib.utils import repo2db_ from rhodecode.model.db import RhodeCodeSettings, RhodeCodeUi, Repository from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \ ApplicationUiSettingsForm -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from rhodecode.model.user import UserModel from rhodecode.lib.celerylib import tasks, run_task from sqlalchemy import func @@ -99,7 +99,7 @@ class SettingsController(BaseController) rm_obsolete = request.POST.get('destroy', False) log.debug('Rescanning directories with destroy=%s', rm_obsolete) - initial = HgModel().repo_scan(g.paths[0][1], g.baseui) + initial = ScmModel().repo_scan(g.paths[0][1], g.baseui) for repo_name in initial.keys(): invalidate_cache('get_repo_cached_%s' % repo_name) @@ -253,7 +253,7 @@ class SettingsController(BaseController) .filter(Repository.user_id == c.user.user_id)\ .order_by(func.lower(Repository.repo_name))\ .all() - c.user_repos = HgModel().get_repos(all_repos) + c.user_repos = ScmModel().get_repos(all_repos) if c.user.username == 'default': h.flash(_("You can't edit this user since it's" @@ -294,7 +294,7 @@ class SettingsController(BaseController) .filter(Repository.user_id == c.user.user_id)\ .order_by(func.lower(Repository.repo_name))\ .all() - c.user_repos = HgModel().get_repos(all_repos) + c.user_repos = ScmModel().get_repos(all_repos) return htmlfill.render( render('admin/users/user_edit_my_account.html'), diff --git a/rhodecode/controllers/branches.py b/rhodecode/controllers/branches.py --- a/rhodecode/controllers/branches.py +++ b/rhodecode/controllers/branches.py @@ -26,7 +26,7 @@ from pylons import tmpl_context as c from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseController, render from rhodecode.lib.utils import OrderedDict -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel import logging log = logging.getLogger(__name__) @@ -38,7 +38,7 @@ class BranchesController(BaseController) super(BranchesController, self).__before__() def index(self): - hg_model = HgModel() + hg_model = ScmModel() c.repo_info = hg_model.get_repo(c.repo_name) c.repo_branches = OrderedDict() for name, hash_ in c.repo_info.branches.items(): diff --git a/rhodecode/controllers/changelog.py b/rhodecode/controllers/changelog.py --- a/rhodecode/controllers/changelog.py +++ b/rhodecode/controllers/changelog.py @@ -32,7 +32,7 @@ from mercurial.graphmod import colored, from pylons import request, session, tmpl_context as c from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseController, render -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from webhelpers.paginate import Page import logging log = logging.getLogger(__name__) @@ -60,7 +60,7 @@ class ChangelogController(BaseController else: c.size = int(session.get('changelog_size', default)) - changesets = HgModel().get_repo(c.repo_name) + changesets = ScmModel().get_repo(c.repo_name) p = int(request.params.get('page', 1)) c.total_cs = len(changesets) diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -28,7 +28,7 @@ from rhodecode.lib.auth import LoginRequ from rhodecode.lib.base import BaseController, render from rhodecode.lib.utils import EmptyChangeset import rhodecode.lib.helpers as h -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from vcs.exceptions import RepositoryError, ChangesetError from vcs.nodes import FileNode from vcs.utils import diffs as differ @@ -46,7 +46,7 @@ class ChangesetController(BaseController super(ChangesetController, self).__before__() def index(self, revision): - hg_model = HgModel() + hg_model = ScmModel() cut_off_limit = 1024 * 250 def wrap_to_table(str): @@ -132,7 +132,7 @@ class ChangesetController(BaseController def raw_changeset(self, revision): - hg_model = HgModel() + hg_model = ScmModel() method = request.GET.get('diff', 'show') try: r = hg_model.get_repo(c.repo_name) diff --git a/rhodecode/controllers/feed.py b/rhodecode/controllers/feed.py --- a/rhodecode/controllers/feed.py +++ b/rhodecode/controllers/feed.py @@ -24,7 +24,7 @@ feed controller for pylons """ from pylons import tmpl_context as c, url, response from rhodecode.lib.base import BaseController, render -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed import logging log = logging.getLogger(__name__) @@ -49,7 +49,7 @@ class FeedController(BaseController): language=self.language, ttl=self.ttl) - changesets = HgModel().get_repo(repo_name) + changesets = ScmModel().get_repo(repo_name) for cs in changesets[:self.feed_nr]: feed.add_item(title=cs.message, @@ -69,7 +69,7 @@ class FeedController(BaseController): language=self.language, ttl=self.ttl) - changesets = HgModel().get_repo(repo_name) + changesets = ScmModel().get_repo(repo_name) for cs in changesets[:self.feed_nr]: feed.add_item(title=cs.message, link=url('changeset_home', repo_name=repo_name, diff --git a/rhodecode/controllers/files.py b/rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py +++ b/rhodecode/controllers/files.py @@ -29,7 +29,7 @@ from pylons.controllers.util import redi from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseController, render from rhodecode.lib.utils import EmptyChangeset -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from vcs.exceptions import RepositoryError, ChangesetError from vcs.nodes import FileNode from vcs.utils import diffs as differ @@ -49,7 +49,7 @@ class FilesController(BaseController): c.file_size_limit = 250 * 1024 #limit of file size to display def index(self, repo_name, revision, f_path): - hg_model = HgModel() + hg_model = ScmModel() c.repo = hg_model.get_repo(c.repo_name) revision = request.POST.get('at_rev', None) or revision @@ -95,7 +95,7 @@ class FilesController(BaseController): return render('files/files.html') def rawfile(self, repo_name, revision, f_path): - hg_model = HgModel() + hg_model = ScmModel() c.repo = hg_model.get_repo(c.repo_name) file_node = c.repo.get_changeset(revision).get_node(f_path) response.content_type = file_node.mimetype @@ -104,7 +104,7 @@ class FilesController(BaseController): return file_node.content def raw(self, repo_name, revision, f_path): - hg_model = HgModel() + hg_model = ScmModel() c.repo = hg_model.get_repo(c.repo_name) file_node = c.repo.get_changeset(revision).get_node(f_path) response.content_type = 'text/plain' @@ -112,7 +112,7 @@ class FilesController(BaseController): return file_node.content def annotate(self, repo_name, revision, f_path): - hg_model = HgModel() + hg_model = ScmModel() c.repo = hg_model.get_repo(c.repo_name) c.cs = c.repo.get_changeset(revision) c.file = c.cs.get_node(f_path) @@ -141,7 +141,7 @@ class FilesController(BaseController): yield data archive = tempfile.TemporaryFile() - repo = HgModel().get_repo(repo_name).repo + repo = ScmModel().get_repo(repo_name).repo fname = '%s-%s%s' % (repo_name, revision, fileformat) archival.archive(repo, archive, revision, archive_specs[fileformat][1], prefix='%s-%s' % (repo_name, revision)) @@ -151,7 +151,7 @@ class FilesController(BaseController): return read_in_chunks(archive) def diff(self, repo_name, f_path): - hg_model = HgModel() + hg_model = ScmModel() diff1 = request.GET.get('diff1') diff2 = request.GET.get('diff2') c.action = request.GET.get('diff') diff --git a/rhodecode/controllers/home.py b/rhodecode/controllers/home.py --- a/rhodecode/controllers/home.py +++ b/rhodecode/controllers/home.py @@ -26,7 +26,7 @@ from operator import itemgetter from pylons import tmpl_context as c, request from rhodecode.lib.auth import LoginRequired from rhodecode.lib.base import BaseController, render -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel import logging log = logging.getLogger(__name__) @@ -47,7 +47,7 @@ class HomeController(BaseController): else: c.sort_by = current_sort c.sort_slug = current_sort_slug - cached_repo_list = HgModel().get_repos() + cached_repo_list = ScmModel().get_repos() sort_key = current_sort_slug + '_sort' if c.sort_by.startswith('-'): diff --git a/rhodecode/controllers/shortlog.py b/rhodecode/controllers/shortlog.py --- a/rhodecode/controllers/shortlog.py +++ b/rhodecode/controllers/shortlog.py @@ -25,7 +25,7 @@ shortlog controller for pylons from pylons import tmpl_context as c, request from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseController, render -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from webhelpers.paginate import Page import logging log = logging.getLogger(__name__) @@ -40,7 +40,7 @@ class ShortlogController(BaseController) def index(self): p = int(request.params.get('page', 1)) - repo = HgModel().get_repo(c.repo_name) + repo = ScmModel().get_repo(c.repo_name) c.repo_changesets = Page(repo, page=p, items_per_page=20) c.shortlog_data = render('shortlog/shortlog_data.html') if request.params.get('partial'): diff --git a/rhodecode/controllers/summary.py b/rhodecode/controllers/summary.py --- a/rhodecode/controllers/summary.py +++ b/rhodecode/controllers/summary.py @@ -27,7 +27,7 @@ from vcs.exceptions import ChangesetErro from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseController, render from rhodecode.lib.utils import OrderedDict, EmptyChangeset -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from rhodecode.model.db import Statistics from webhelpers.paginate import Page from rhodecode.lib.celerylib import run_task @@ -52,7 +52,7 @@ class SummaryController(BaseController): super(SummaryController, self).__before__() def index(self): - hg_model = HgModel() + hg_model = ScmModel() c.repo_info = hg_model.get_repo(c.repo_name) def url_generator(**kw): return url('shortlog_home', repo_name=c.repo_name, **kw) diff --git a/rhodecode/controllers/tags.py b/rhodecode/controllers/tags.py --- a/rhodecode/controllers/tags.py +++ b/rhodecode/controllers/tags.py @@ -26,7 +26,7 @@ from pylons import tmpl_context as c from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseController, render from rhodecode.lib.utils import OrderedDict -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel import logging log = logging.getLogger(__name__) @@ -38,7 +38,7 @@ class TagsController(BaseController): super(TagsController, self).__before__() def index(self): - hg_model = HgModel() + hg_model = ScmModel() c.repo_info = hg_model.get_repo(c.repo_name) c.repo_tags = OrderedDict() for name, hash_ in c.repo_info.tags.items(): diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -9,7 +9,7 @@ from rhodecode import __version__ from rhodecode.lib import auth from rhodecode.lib.utils import get_repo_slug from rhodecode.model import meta -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from vcs import BACKENDS class BaseController(WSGIController): @@ -18,11 +18,11 @@ class BaseController(WSGIController): c.rhodecode_version = __version__ c.rhodecode_name = config['rhodecode_title'] c.repo_name = get_repo_slug(request) - c.cached_repo_list = HgModel().get_repos() + c.cached_repo_list = ScmModel().get_repos() c.backends = BACKENDS.keys() if c.repo_name: - cached_repo = HgModel().get(c.repo_name) + cached_repo = ScmModel().get(c.repo_name) if cached_repo: c.repository_tags = cached_repo.tags diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -10,7 +10,7 @@ from time import mktime import os import traceback from vcs.backends import get_repo -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel try: import json except ImportError: @@ -62,7 +62,7 @@ def get_commits_stats(repo_name, ts_min_ commits_by_day_author_aggregate = {} commits_by_day_aggregate = {} - repos_path = HgModel().repos_path + repos_path = ScmModel().repos_path p = os.path.join(repos_path, repo_name) repo = get_repo(p) @@ -274,7 +274,7 @@ def create_repo_fork(form_data, cur_user repo_model = RepoModel(get_session()) repo_model.create(form_data, cur_user, just_db=True, fork=True) repo_name = form_data['repo_name'] - repos_path = HgModel().repos_path + repos_path = ScmModel().repos_path repo_path = os.path.join(repos_path, repo_name) repo_fork_path = os.path.join(repos_path, form_data['fork_name']) alias = form_data['repo_type'] @@ -291,7 +291,7 @@ def __get_codes_stats(repo_name): 's', 'sh', 'tpl', 'txt', 'vim', 'wss', 'xhtml', 'xml', 'xsl', 'xslt', 'yaws'] - repos_path = HgModel().repos_path + repos_path = ScmModel().repos_path p = os.path.join(repos_path, repo_name) repo = get_repo(p) tip = repo.get_changeset() diff --git a/rhodecode/lib/indexers/__init__.py b/rhodecode/lib/indexers/__init__.py --- a/rhodecode/lib/indexers/__init__.py +++ b/rhodecode/lib/indexers/__init__.py @@ -6,7 +6,7 @@ from os.path import dirname as dn, join sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) from rhodecode.config.environment import load_environment -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from shutil import rmtree from webhelpers.html.builder import escape from vcs.utils.lazy import LazyProperty diff --git a/rhodecode/lib/indexers/daemon.py b/rhodecode/lib/indexers/daemon.py --- a/rhodecode/lib/indexers/daemon.py +++ b/rhodecode/lib/indexers/daemon.py @@ -33,7 +33,7 @@ project_path = dn(dn(dn(dn(os.path.realp sys.path.append(project_path) -from rhodecode.model.hg import HgModel +from rhodecode.model.scm import ScmModel from rhodecode.lib.helpers import safe_unicode from whoosh.index import create_in, open_dir from shutil import rmtree @@ -78,7 +78,7 @@ class WhooshIndexingDaemon(object): if not repo_location: raise Exception('You have to provide repositories location') - self.repo_paths = HgModel().repo_scan(self.repo_location, None, True) + self.repo_paths = ScmModel().repo_scan(self.repo_location, None, True) self.initial = False if not os.path.isdir(self.index_location): os.mkdir(self.index_location) diff --git a/rhodecode/model/hg.py b/rhodecode/model/scm.py rename from rhodecode/model/hg.py rename to rhodecode/model/scm.py --- a/rhodecode/model/hg.py +++ b/rhodecode/model/scm.py @@ -40,7 +40,7 @@ import time log = logging.getLogger(__name__) -class HgModel(object): +class ScmModel(object): """ Mercurial Model """ diff --git a/rhodecode/tests/functional/test_permissions.py b/rhodecode/tests/functional/test_admin_permissions.py rename from rhodecode/tests/functional/test_permissions.py rename to rhodecode/tests/functional/test_admin_permissions.py --- a/rhodecode/tests/functional/test_permissions.py +++ b/rhodecode/tests/functional/test_admin_permissions.py @@ -1,6 +1,6 @@ from rhodecode.tests import * -class TestPermissionsController(TestController): +class TestAdminPermissionsController(TestController): def test_index(self): response = self.app.get(url('permissions')) diff --git a/rhodecode/tests/functional/test_repos.py b/rhodecode/tests/functional/test_admin_repos.py rename from rhodecode/tests/functional/test_repos.py rename to rhodecode/tests/functional/test_admin_repos.py --- a/rhodecode/tests/functional/test_repos.py +++ b/rhodecode/tests/functional/test_admin_repos.py @@ -1,7 +1,7 @@ from rhodecode.model.db import Repository from rhodecode.tests import * -class TestReposController(TestController): +class TestAdminReposController(TestController): def test_index(self): self.log_user() @@ -21,11 +21,8 @@ class TestReposController(TestController 'description':description, 'private':private}) - print response #test if we have a message for that repository - print '-' * 100 - print response.session assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo' #test if the fork was created in the database @@ -49,11 +46,8 @@ class TestReposController(TestController 'description':description, 'private':private}) - print response #test if we have a message for that repository - print '-' * 100 - print response.session assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo' #test if the fork was created in the database @@ -91,11 +85,8 @@ class TestReposController(TestController 'description':description, 'private':private}) - print response #test if we have a message for that repository - print '-' * 100 - print response.session assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo' #test if the repo was created in the database @@ -112,8 +103,6 @@ class TestReposController(TestController response = self.app.delete(url('repo', repo_name=repo_name)) - print '-' * 100 - print response.session assert '''deleted repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about delete repo' response.follow() diff --git a/rhodecode/tests/functional/test_admin_settings.py b/rhodecode/tests/functional/test_admin_settings.py --- a/rhodecode/tests/functional/test_admin_settings.py +++ b/rhodecode/tests/functional/test_admin_settings.py @@ -1,7 +1,7 @@ from rhodecode.tests import * from rhodecode.model.db import User -class TestSettingsController(TestController): +class TestAdminSettingsController(TestController): def test_index(self): response = self.app.get(url('admin_settings')) @@ -48,9 +48,9 @@ class TestSettingsController(TestControl response = self.app.get(url('admin_settings_my_account')) print response assert 'value="test_admin' in response.body - - - + + + def test_my_account_update(self): self.log_user() new_email = 'new@mail.pl' @@ -64,16 +64,16 @@ class TestSettingsController(TestControl email=new_email,)) response.follow() print response - + print 'x' * 100 print response.session assert 'Your account was updated succesfully' in response.session['flash'][0][1], 'no flash message about success of change' user = self.sa.query(User).filter(User.username == 'test_admin').one() assert user.email == new_email , 'incorrect user email after update got %s vs %s' % (user.email, new_email) - + def test_my_account_update_own_email_ok(self): self.log_user() - + new_email = 'new@mail.pl' response = self.app.post(url('admin_settings_my_account_update'), params=dict( _method='put', @@ -83,10 +83,10 @@ class TestSettingsController(TestControl lastname='NewLastname', email=new_email,)) print response - + def test_my_account_update_err_email_exists(self): self.log_user() - + new_email = 'test_regular@mail.com'#already exisitn email response = self.app.post(url('admin_settings_my_account_update'), params=dict( _method='put', @@ -96,13 +96,13 @@ class TestSettingsController(TestControl lastname='NewLastname', email=new_email,)) print response - + assert 'That e-mail address is already taken' in response.body, 'Missing error message about existing email' - - + + def test_my_account_update_err(self): self.log_user('test_regular2', 'test12') - + new_email = 'newmail.pl' response = self.app.post(url('admin_settings_my_account_update'), params=dict( _method='put', diff --git a/rhodecode/tests/functional/test_users.py b/rhodecode/tests/functional/test_admin_users.py rename from rhodecode/tests/functional/test_users.py rename to rhodecode/tests/functional/test_admin_users.py --- a/rhodecode/tests/functional/test_users.py +++ b/rhodecode/tests/functional/test_admin_users.py @@ -1,6 +1,9 @@ from rhodecode.tests import * +from rhodecode.model.db import User +from rhodecode.lib.auth import check_password +from sqlalchemy.orm.exc import NoResultFound -class TestUsersController(TestController): +class TestAdminUsersController(TestController): def test_index(self): response = self.app.get(url('users')) @@ -11,12 +14,59 @@ class TestUsersController(TestController def test_create(self): self.log_user() -# user_name = 'new_user' -# response = self.app.post(url('users'),{'repo_name':user_name, -# 'repo_type':'hg', -# 'description':description, -# 'private':private}) + username = 'newtestuser' + password = 'test12' + name = 'name' + lastname = 'lastname' + email = 'mail@mail.com' + + response = self.app.post(url('users'), {'username':username, + 'password':password, + 'name':name, + 'active':True, + 'lastname':lastname, + 'email':email}) + + + assert '''created user %s''' % (username) in response.session['flash'][0], 'No flash message about new user' + + new_user = self.sa.query(User).filter(User.username == username).one() + + + assert new_user.username == username, 'wrong info about username' + assert check_password(password, new_user.password) == True , 'wrong info about password' + assert new_user.name == name, 'wrong info about name' + assert new_user.lastname == lastname, 'wrong info about lastname' + assert new_user.email == email, 'wrong info about email' + + response.follow() + response = response.follow() + assert """edit">newtestuser""" in response.body + + def test_create_err(self): + self.log_user() + username = 'new_user' + password = '' + name = 'name' + lastname = 'lastname' + email = 'errmail.com' + + response = self.app.post(url('users'), {'username':username, + 'password':password, + 'name':name, + 'active':False, + 'lastname':lastname, + 'email':email}) + + assert """Invalid username""" in response.body + assert """Please enter a value""" in response.body + assert """An email address must contain a single @""" in response.body + + def get_user(): + self.sa.query(User).filter(User.username == username).one() + + self.assertRaises(NoResultFound, get_user), 'found user in database' def test_new(self): response = self.app.get(url('new_user')) @@ -31,7 +81,27 @@ class TestUsersController(TestController response = self.app.post(url('user', id=1), params=dict(_method='put')) def test_delete(self): - response = self.app.delete(url('user', id=1)) + self.log_user() + username = 'newtestuserdeleteme' + password = 'test12' + name = 'name' + lastname = 'lastname' + email = 'todeletemail@mail.com' + + response = self.app.post(url('users'), {'username':username, + 'password':password, + 'name':name, + 'active':True, + 'lastname':lastname, + 'email':email}) + + response = response.follow() + + new_user = self.sa.query(User).filter(User.username == username).one() + response = self.app.delete(url('user', id=new_user.user_id)) + + assert """sucessfully deleted user""" in response.session['flash'][0], 'No info about user deletion' + def test_delete_browser_fakeout(self): response = self.app.post(url('user', id=1), params=dict(_method='delete')) diff --git a/rhodecode/tests/functional/test_hg.py b/rhodecode/tests/functional/test_home.py rename from rhodecode/tests/functional/test_hg.py rename to rhodecode/tests/functional/test_home.py --- a/rhodecode/tests/functional/test_hg.py +++ b/rhodecode/tests/functional/test_home.py @@ -1,6 +1,6 @@ from rhodecode.tests import * -class TestAdminController(TestController): +class TestHomeController(TestController): def test_index(self): self.log_user() diff --git a/rhodecode/tests/functional/test_login.py b/rhodecode/tests/functional/test_login.py --- a/rhodecode/tests/functional/test_login.py +++ b/rhodecode/tests/functional/test_login.py @@ -102,7 +102,6 @@ class TestLoginController(TestController 'email':email, 'name':name, 'lastname':lastname}) - print response.body assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ py_version = sys.version_info requirements = [ "Pylons>=1.0.0", "SQLAlchemy>=0.6.5", - "Mako>=0.3.5", + "Mako>=0.3.6", "vcs>=0.1.10", "pygments>=1.3.0", "mercurial>=1.6.4",