Changeset - f9016563f987
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 15 years ago 2011-01-06 23:00:06
marcin@python-works.com
Added sql session into test hg script
small docfix for utils
2 files changed with 52 insertions and 10 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/utils.py
Show inline comments
 
@@ -191,14 +191,13 @@ ui_sections = ['alias', 'auth',
 
                'smtp', 'patch',
 
                'paths', 'profiling',
 
                'server', 'trusted',
 
                '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
 
    :param checkpaths: check the path
 
    :param read_from: read from 'file' or 'db'
 
    """
rhodecode/tests/test_hg_operations.py
Show inline comments
 
@@ -10,18 +10,34 @@
 
    :license: LICENSE_NAME, see LICENSE_FILE for more details.
 
"""
 

	
 
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'
 
HOST = '127.0.0.1:5000'
 
DEBUG = True
 
log = logging.getLogger(__name__)
 
@@ -43,12 +59,38 @@ class Command(object):
 
        p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, cwd=self.cwd)
 
        stdout, stderr = p.communicate()
 
        if DEBUG:
 
            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
 
#==============================================================================
 
def test_clone():
 
    cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
 
@@ -133,24 +175,24 @@ def test_push():
 

	
 
        cmd = """hg ci -m 'changed file %s' %s """ % (i, modified_file)
 
        Command(cwd).execute(cmd)
 

	
 
    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)
 

	
 
        cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file)
 
        Command(cwd).execute(cmd)
 

	
 
@@ -158,13 +200,13 @@ def test_push_new_file():
 
                  {'user':USER,
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   '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():
 

	
 
    clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
 
                  {'user':USER + 'xxx',
 
                   'pass':PASS,
 
@@ -213,16 +255,17 @@ def test_push_wrong_path():
 

	
 
    stdout, stderr = Command(cwd).execute('hg push %s' % clone_url)
 
    assert """abort: HTTP Error 403: Forbidden"""  in stderr
 

	
 

	
 
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()
 

	
 

	
0 comments (0 inline, 0 general)