Changeset - 089ef495e9dd
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 14 years ago 2011-10-24 23:28:04
marcin@python-works.com
fixed test_hg_push operations
1 file changed with 21 insertions and 32 deletions:
0 comments (0 inline, 0 general)
rhodecode/tests/test_hg_operations.py
Show inline comments
 
@@ -45,24 +45,28 @@ from rhodecode.model.db import User, Rep
 
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
 

	
 
rel_path = dn(dn(dn(os.path.abspath(__file__))))
 
conf = appconfig('config:development.ini', relative_to=rel_path)
 

	
 
conf = appconfig('config:%s' % sys.argv[1], relative_to=rel_path)
 
load_environment(conf.global_conf, conf.local_conf)
 

	
 
add_cache(conf)
 

	
 
USER = 'test_admin'
 
PASS = 'test12'
 
HOST = '127.0.0.1:5000'
 
DEBUG = True if sys.argv[1:] else False
 
DEBUG = False
 
print 'DEBUG:', DEBUG
 
log = logging.getLogger(__name__)
 

	
 
engine = engine_from_config(conf, 'sqlalchemy.db1.')
 
init_model(engine)
 
sa = meta.Session
 

	
 
class Command(object):
 

	
 
    def __init__(self, cwd):
 
        self.cwd = cwd
 

	
 
@@ -93,28 +97,21 @@ def test_wrapp(func):
 
                   '###############\n' % (func.__name__, e))
 
            sys.exit()
 
        print '++OK++'
 
        return res
 
    return __wrapp
 

	
 
def get_session():
 
    engine = engine_from_config(conf, 'sqlalchemy.db1.')
 
    init_model(engine)
 
    sa = meta.Session
 
    return sa
 

	
 

	
 
def create_test_user(force=True):
 
    print '\tcreating test user'
 
    sa = get_session()
 

	
 
    user = sa.query(User).filter(User.username == USER).scalar()
 
    user = User.get_by_username(USER)
 

	
 
    if force and user is not None:
 
        print '\tremoving current user'
 
        for repo in sa.query(Repository).filter(Repository.user == user).all():
 
        for repo in Repository.query().filter(Repository.user == user).all():
 
            sa.delete(repo)
 
        sa.delete(user)
 
        sa.commit()
 

	
 
    if user is None or force:
 
        print '\tcreating new one'
 
@@ -131,15 +128,14 @@ def create_test_user(force=True):
 

	
 
    print '\tdone'
 

	
 

	
 
def create_test_repo(force=True):
 
    from rhodecode.model.repo import RepoModel
 
    sa = get_session()
 

	
 
    user = sa.query(User).filter(User.username == USER).scalar()
 
    user = User.get_by_username(USER)
 
    if user is None:
 
        raise Exception('user not found')
 

	
 

	
 
    repo = sa.query(Repository).filter(Repository.repo_name == HG_REPO).scalar()
 

	
 
@@ -153,28 +149,23 @@ def create_test_repo(force=True):
 
        rm = RepoModel(sa)
 
        rm.base_path = '/home/hg'
 
        rm.create(form_data, user)
 

	
 

	
 
def set_anonymous_access(enable=True):
 
    sa = get_session()
 
    user = sa.query(User).filter(User.username == 'default').one()
 
    sa.expire(user)
 
    user = User.get_by_username('default')
 
    user.active = enable
 
    sa.add(user)
 
    sa.commit()
 
    sa.remove()
 
    import time;time.sleep(3)
 
    print '\tanonymous access is now:', enable
 

	
 
    if enable != User.get_by_username('default').active:
 
        raise Exception('Cannot set anonymous access')
 

	
 
def get_anonymous_access():
 
    sa = get_session()
 
    obj1 = sa.query(User).filter(User.username == 'default').one()
 
    sa.expire(obj1)
 
    return obj1.active
 
    user = User.get_by_username('default')
 
    return user.active
 

	
 

	
 
#==============================================================================
 
# TESTS
 
#==============================================================================
 
@test_wrapp
 
@@ -375,38 +366,36 @@ def test_push_wrong_path():
 
    stdout, stderr = Command(cwd).execute('hg push %s' % clone_url)
 
    if not """abort: HTTP Error 403: Forbidden"""  in stderr:
 
        raise Exception('Failure')
 

	
 
@test_wrapp
 
def get_logs():
 
    sa = get_session()
 
    return len(sa.query(UserLog).all())
 
    return UserLog.query().all()
 

	
 
@test_wrapp
 
def test_logs(initial):
 
    sa = get_session()
 
    logs = sa.query(UserLog).all()
 
    operations = 7
 
    if initial + operations != len(logs):
 
        raise Exception("missing number of logs %s vs %s" % (initial, len(logs)))
 
    logs = UserLog.query().all()
 
    operations = 4
 
    if len(initial) + operations != len(logs):
 
        raise Exception("missing number of logs initial:%s vs current:%s" % \
 
                            (len(initial), len(logs)))
 

	
 

	
 
if __name__ == '__main__':
 
    create_test_user(force=False)
 
    create_test_repo()
 

	
 
    initial_logs = get_logs()
 
    print 'initial activity logs: %s' % len(initial_logs)
 

	
 
#    test_push_modify_file()
 
    test_clone_with_credentials()
 
    test_clone_wrong_credentials()
 

	
 

	
 
    test_push_new_file(commits=2, with_clone=True)
 

	
 
    test_clone_anonymous()
 
    test_push_wrong_path()
 

	
 

	
 
    test_push_wrong_credentials()
 

	
 
    test_logs(initial_logs)
0 comments (0 inline, 0 general)