Changeset - 15b60f83420c
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 15 years ago 2011-02-15 01:36:50
marcin@python-works.com
tests update
3 files changed with 96 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/tests/__init__.py
Show inline comments
 
@@ -41,32 +41,31 @@ HG_REPO = 'vcs_test_hg'
 
GIT_REPO = 'vcs_test_git'
 

	
 
NEW_HG_REPO = 'vcs_test_hg_new'
 
NEW_GIT_REPO = 'vcs_test_git_new'
 

	
 
HG_FORK = 'vcs_test_hg_fork'
 
GIT_FORK = 'vcs_test_git_fork'
 

	
 
class TestController(TestCase):
 

	
 
    def __init__(self, *args, **kwargs):
 
        wsgiapp = pylons.test.pylonsapp
 
        config = wsgiapp.config
 

	
 
        self.app = TestApp(wsgiapp)
 
        url._push_object(URLGenerator(config['routes.map'], environ))
 
        self.sa = meta.Session
 
        self.index_location = config['app_conf']['index_dir']
 
        TestCase.__init__(self, *args, **kwargs)
 

	
 
    def log_user(self, username='test_admin', password='test12'):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':username,
 
                                  'password':password})
 
        print response
 

	
 
        if 'invalid user name' in response.body:
 
            assert False, 'could not login using %s %s' % (username, password)
 

	
 
        assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
 
        assert response.session['rhodecode_user'].username == username, 'wrong logged in user got %s expected %s' % (response.session['rhodecode_user'].username, username)
 
        return response.follow()
rhodecode/tests/functional/test_files.py
Show inline comments
 
@@ -216,26 +216,92 @@ removed extra unicode conversion in diff
 

	
 
    def test_archival_wrong_ext(self):
 
        self.log_user()
 

	
 
        for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
 
            fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
 

	
 
            response = self.app.get(url(controller='files', action='archivefile',
 
                                        repo_name=HG_REPO,
 
                                        fname=fname))
 
            assert 'Unknown archive type' in response.body
 

	
 

	
 
    def test_archival_wrong_revision(self):
 
        self.log_user()
 

	
 
        for rev in ['00x000000', 'tar', 'wrong', '@##$@$424213232', '232dffcd']:
 
            fname = '%s.zip' % rev
 

	
 
            response = self.app.get(url(controller='files', action='archivefile',
 
                                        repo_name=HG_REPO,
 
                                        fname=fname))
 
            assert 'Unknown revision' in response.body
 

	
 
    #==========================================================================
 
    # RAW FILE
 
    #==========================================================================
 
    def test_raw_file_ok(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='files', action='rawfile',
 
                                    repo_name=HG_REPO,
 
                                    revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
 
                                    f_path='vcs/nodes.py'))
 
        assert False
 
        #TODO: put in more
 
    def test_raw_file_wrong_cs(self):
 
        self.log_user()
 
        rev = u'ERRORcce30c96924232dffcd24178a07ffeb5dfc'
 
        f_path = 'vcs/nodes.py'
 

	
 
        response = self.app.get(url(controller='files', action='rawfile',
 
                                    repo_name=HG_REPO,
 
                                    revision='ERRORce30c96924232dffcd24178a07ffeb5dfc',
 
                                    f_path='vcs/nodes.py'))
 
        print response.session['flash']
 
        assert """Revision %r does not exist for this repository""" % (rev) in response.session['flash'][0], 'No flash message'
 
        assert """%s""" % (HG_REPO) in response.session['flash'][0], 'No flash message'
 

	
 

	
 

	
 
    def test_raw_file_wrong_f_path(self):
 
        self.log_user()
 
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
 
        f_path = 'vcs/ERRORnodes.py'
 
        response = self.app.get(url(controller='files', action='rawfile',
 
                                    repo_name=HG_REPO,
 
                                    revision=rev,
 
                                    f_path=f_path))
 
        assert "There is no file nor directory at the given path %r at revision %r" % (f_path, rev) in response.session['flash'][0], 'No flash message'
 

	
 
    #==========================================================================
 
    # RAW
 
    #==========================================================================
 
    def test_raw_ok(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='files', action='raw',
 
                                    repo_name=HG_REPO,
 
                                    revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
 
                                    f_path='vcs/nodes.py'))
 
        assert False
 
        #TODO: put in more
 
    def test_raw_wrong_cs(self):
 
        self.log_user()
 
        rev = 'ERRORcce30c96924232dffcd24178a07ffeb5dfc'
 
        f_path = 'vcs/nodes.py'
 

	
 
        response = self.app.get(url(controller='files', action='raw',
 
                                    repo_name=HG_REPO,
 
                                    revision='ERRORce30c96924232dffcd24178a07ffeb5dfc',
 
                                    f_path='vcs/nodes.py'))
 
        assert "Cannot find revision %s" % rev in response.session['flash'][0], 'No flash message'
 

	
 
    def test_raw_wrong_f_path(self):
 
        self.log_user()
 
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
 
        f_path = 'vcs/ERRORnodes.py'
 
        response = self.app.get(url(controller='files', action='raw',
 
                                    repo_name=HG_REPO,
 
                                    revision=rev,
 
                                    f_path=f_path))
 
        assert "There is no file nor directory at the given path %r at revision %r" % (f_path, rev) in response.session['flash'][0], 'No flash message'
 

	
rhodecode/tests/test_hg_operations.py
Show inline comments
 
@@ -56,140 +56,169 @@ class Command(object):
 
        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):
 
    print 'creating test user'
 
    sa = get_session()
 

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

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

	
 
    if user is None or force:
 
        print 'creating new one'
 
        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
 
        new_usr.admin = True
 
        sa.add(new_usr)
 
        sa.commit()
 

	
 
    print 'done'
 

	
 

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

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

	
 

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

	
 
    if repo is None:
 
        print 'repo not found creating'
 

	
 
        form_data = {'repo_name':HG_REPO,
 
                     'repo_type':'hg',
 
                     'private':False, }
 
        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()
 
    user.active = enable
 
    sa.add(user)
 
    sa.commit()
 

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

	
 

	
 
#==============================================================================
 
# TESTS
 
#==============================================================================
 
def test_clone(no_errors=False):
 
    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,
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   'cloned_repo':HG_REPO,
 
                   'dest':path}
 

	
 
    stdout, stderr = Command(cwd).execute('hg clone', clone_url)
 

	
 
    if no_errors is False:
 
        assert """adding file changes""" in stdout, 'no messages about cloning'
 
        assert """abort""" not in stderr , 'got error from clone'
 

	
 

	
 

	
 
def test_clone_anonymous_ok():
 
    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
 

	
 

	
 
    print 'checking if anonymous access is enabled'
 
    anonymous_access = get_anonymous_access()
 
    if not anonymous_access:
 
        print 'not enabled, enabling it '
 
        set_anonymous_access(enable=True)
 

	
 
    clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \
 
                  {'user':USER,
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   'cloned_repo':HG_REPO,
 
                   'dest':path}
 

	
 
    stdout, stderr = Command(cwd).execute('hg clone', clone_url)
 
    print stdout, stderr
 

	
 

	
 
    assert """adding file changes""" in stdout, 'no messages about cloning'
 
    assert """abort""" not in stderr , 'got error from clone'
 

	
 
    #disable if it was enabled
 
    if not anonymous_access:
 
        print 'disabling anonymous access'
 
        set_anonymous_access(enable=False)
 

	
 

	
 
def test_clone_wrong_credentials():
 
    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 + 'error',
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   'cloned_repo':HG_REPO,
 
                   'dest':path}
 

	
 
    stdout, stderr = Command(cwd).execute('hg clone', clone_url)
 

	
 
    assert """abort: authorization failed""" in stderr , 'no error from wrong credentials'
 

	
 

	
 
def test_pull():
 
@@ -275,29 +304,29 @@ def test_push_wrong_path():
 
        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(force=False)
 
    create_test_repo()
 
    #test_push_modify_file()
 
    #test_clone()
 
    #test_clone_anonymous_ok()
 

	
 
    #test_clone_wrong_credentials()
 

	
 
    #test_pull()
 
    test_push_new_file(commits=3)
 
    test_push_new_file(commits=2)
 
    #test_push_wrong_path()
 
    #test_push_wrong_credentials()
 

	
 

	
0 comments (0 inline, 0 general)