Changeset - 7f4943c90876
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 15 years ago 2011-02-01 02:16:27
marcin@python-works.com
fixed test hg operations script
1 file changed with 10 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rhodecode/tests/test_hg_operations.py
Show inline comments
 
@@ -52,56 +52,60 @@ class Command(object):
 
        """Runs command on the system with given ``args``.
 
        """
 

	
 
        command = cmd + ' ' + ' '.join(args)
 
        log.debug('Executing %s' % command)
 
        if DEBUG:
 
            print command
 
        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:
 

	
 
    if force and user:
 
        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.email = 'mail@mail.com'
 
        new_usr.name = 'test'
 
        new_usr.lastname = 'lasttestname'
 
        new_usr.active = True
 

	
 
        sa.add(new_usr)
 
        sa.commit()
 

	
 

	
 

	
 

	
 
#==============================================================================
 
# TESTS
 
#==============================================================================
 
def test_clone():
 
    cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
 

	
 
    try:
 
        shutil.rmtree(path, ignore_errors=True)
 
        os.makedirs(path)
 
        #print 'made dirs %s' % jn(path)
 
    except OSError:
 
        raise
 

	
 

	
 
    clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
 
                  {'user':USER,
 
@@ -237,35 +241,36 @@ def test_push_wrong_path():
 

	
 
    Command(cwd).execute("""echo '' > %s""" % added_file)
 
    Command(cwd).execute("""hg init %s""" % path)
 
    Command(cwd).execute("""hg add %s""" % added_file)
 

	
 
    for i in xrange(2):
 
        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)
 

	
 
    clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
 
                  {'user':USER,
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   'cloned_repo':HG_REPO + '_error',
 
                   'dest':jn(TESTS_TMP_PATH, HG_REPO)}
 

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

	
 

	
 
if __name__ == '__main__':
 
    create_test_user()
 
    #test_clone()
 
    #create_test_user()
 
    test_clone()
 
    test_clone_anonymous_ok()
 

	
 
    #test_clone_wrong_credentials()
 
    ##test_clone_anonymous_ok()
 

	
 
    #test_pull()
 
    test_push_new_file(3)
 
    #test_push_new_file(3)
 
    #test_push_wrong_path()
 
    #test_push_wrong_credentials()
 

	
 

	
0 comments (0 inline, 0 general)