# HG changeset patch # User Marcin Kuzminski # Date 1294351206 -3600 # Node ID f9016563f987a3b82fe7b313d225b34265270ddb # Parent c44b3c9b9f7f48753a6f9b181da9832c763f37f5 Added sql session into test hg script small docfix for utils diff -r c44b3c9b9f7f -r f9016563f987 rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py Thu Jan 06 21:07:33 2011 +0100 +++ b/rhodecode/lib/utils.py Thu Jan 06 23:00:06 2011 +0100 @@ -194,8 +194,7 @@ 'ui', 'web', ] def make_ui(read_from='file', path=None, checkpaths=True): - """ - A function that will read python rc files or database + """A function that will read python rc files or database and make an mercurial ui object from read options :param path: path to mercurial config file diff -r c44b3c9b9f7f -r f9016563f987 rhodecode/tests/test_hg_operations.py --- a/rhodecode/tests/test_hg_operations.py Thu Jan 06 21:07:33 2011 +0100 +++ b/rhodecode/tests/test_hg_operations.py Thu Jan 06 23:00:06 2011 +0100 @@ -13,12 +13,28 @@ import os import shutil import logging +from os.path import join as jn +from tempfile import _RandomNameSequence from subprocess import Popen, PIPE -from os.path import join as jn +from paste.deploy import appconfig +from pylons import config +from sqlalchemy import engine_from_config + +from rhodecode.lib.utils import add_cache +from rhodecode.model import init_model +from rhodecode.model import meta +from rhodecode.model.db import User +from rhodecode.lib.auth import get_crypt_password from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO +from rhodecode.config.environment import load_environment + +conf = appconfig('config:development.ini', relative_to='./../../') +load_environment(conf.global_conf, conf.local_conf) + +add_cache(conf) USER = 'test_admin' PASS = 'test12' @@ -46,6 +62,32 @@ print stdout, stderr return stdout, stderr +def get_session(): + engine = engine_from_config(conf, 'sqlalchemy.db1.') + init_model(engine) + sa = meta.Session() + return sa + + +def create_test_user(force=True): + sa = get_session() + + user = sa.query(User).filter(User.username == USER).scalar() + if force: + sa.delete(user) + sa.commit() + + if user is None or force: + new_usr = User() + new_usr.username = USER + new_usr.password = get_crypt_password(PASS) + new_usr.active = True + + sa.add(new_usr) + sa.commit() + + + #============================================================================== # TESTS @@ -136,18 +178,18 @@ Command(cwd).execute('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) -def test_push_new_file(): +def test_push_new_file(commits=15): test_clone() cwd = path = jn(TESTS_TMP_PATH, HG_REPO) - added_file = jn(path, 'setup.py') + added_file = jn(path, '%ssetup.py' % _RandomNameSequence().next()) Command(cwd).execute('touch %s' % added_file) Command(cwd).execute('hg add %s' % added_file) - for i in xrange(15): + for i in xrange(commits): cmd = """echo 'added_line%s' >> %s""" % (i, added_file) Command(cwd).execute(cmd) @@ -161,7 +203,7 @@ 'cloned_repo':HG_REPO, 'dest':jn(TESTS_TMP_PATH, HG_REPO)} - Command(cwd).execute('hg push %s' % push_url) + Command(cwd).execute('hg push --verbose --debug %s' % push_url) def test_push_wrong_credentials(): @@ -216,12 +258,13 @@ if __name__ == '__main__': - test_clone() + create_test_user() + #test_clone() #test_clone_wrong_credentials() ##test_clone_anonymous_ok() - test_pull() - #test_push_new_file() + #test_pull() + test_push_new_file(3) #test_push_wrong_path() #test_push_wrong_credentials()