# HG changeset patch # User Marcin Kuzminski # Date 2011-02-15 00:36:50 # Node ID 15b60f83420c5b1698ba33b9a683abb93a88520a # Parent 9e93cad9357b5718a4bdcefedf4e66b56c077ed8 tests update diff --git a/rhodecode/tests/__init__.py b/rhodecode/tests/__init__.py --- a/rhodecode/tests/__init__.py +++ b/rhodecode/tests/__init__.py @@ -62,7 +62,6 @@ class TestController(TestCase): 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) diff --git a/rhodecode/tests/functional/test_files.py b/rhodecode/tests/functional/test_files.py --- a/rhodecode/tests/functional/test_files.py +++ b/rhodecode/tests/functional/test_files.py @@ -237,5 +237,71 @@ removed extra unicode conversion in diff 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' + diff --git a/rhodecode/tests/test_hg_operations.py b/rhodecode/tests/test_hg_operations.py --- a/rhodecode/tests/test_hg_operations.py +++ b/rhodecode/tests/test_hg_operations.py @@ -77,6 +77,8 @@ def create_test_user(force=True): 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() @@ -117,6 +119,19 @@ def create_test_repo(force=True): 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 #============================================================================== @@ -157,6 +172,12 @@ def test_clone_anonymous_ok(): 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, @@ -166,9 +187,17 @@ def test_clone_anonymous_ok(): 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) @@ -296,7 +325,7 @@ if __name__ == '__main__': #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()