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 @@ -1,6 +1,10 @@ +import os from rhodecode.tests import * from rhodecode.model.db import Repository from rhodecode.model.meta import Session +from rhodecode.tests.fixture import Fixture + +fixture = Fixture() ARCHIVE_SPECS = { '.tar.bz2': ('application/x-bzip2', 'tbz2', ''), @@ -25,11 +29,19 @@ class TestFilesController(TestController revision='tip', f_path='/')) # Test response... - response.mustcontain('docs') - response.mustcontain('tests') - response.mustcontain('vcs') - response.mustcontain('.hgignore') - response.mustcontain('MANIFEST.in') + response.mustcontain('docs') + response.mustcontain('vcs') + response.mustcontain('.gitignore') + response.mustcontain('.hgignore') + response.mustcontain('.hgtags') + response.mustcontain('.travis.yml') + response.mustcontain('MANIFEST.in') + response.mustcontain('README.rst') + response.mustcontain('run_test_and_report.sh') + response.mustcontain('setup.cfg') + response.mustcontain('setup.py') + response.mustcontain('test_and_report.sh') + response.mustcontain('tox.ini') def test_index_revision(self): self.log_user() @@ -79,7 +91,7 @@ class TestFilesController(TestController self.log_user() response = self.app.get(url(controller='files', action='index', repo_name=HG_REPO, - revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc', + revision='8911406ad776fdd3d0b9932a2e89677e57405a48', f_path='vcs/nodes.py')) response.mustcontain("""
Partially implemented #16. filecontent/commit message/author/node name are safe_unicode now. @@ -100,7 +112,41 @@ removed extra unicode conversion in diff extra_environ={'HTTP_X_PARTIAL_XHR': '1'},) #test or history response.mustcontain(""" - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -135,16 +181,23 @@ removed extra unicode conversion in diff - - - + + - - - - - + + + + + + + + + + + + + """) @@ -167,8 +220,42 @@ removed extra unicode conversion in diff annotate=True), extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) - response.mustcontain(""" - + response.mustcontain(""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -203,16 +290,23 @@ removed extra unicode conversion in diff - - - + + - - - - - + + + + + + + + + + + + + """) def test_file_annotation_git(self): @@ -352,26 +446,289 @@ removed extra unicode conversion in diff ) response.mustcontain("vcs/web/simplevcs/views/repository.py") + #HG - ADD FILE def test_add_file_view_hg(self): self.log_user() response = self.app.get(url('files_add_home', repo_name=HG_REPO, revision='tip', f_path='/')) + def test_add_file_into_hg_missing_content(self): + self.log_user() + response = self.app.post(url('files_add_home', + repo_name=HG_REPO, + revision='tip', f_path='/'), + params={ + 'content': '' + }, + status=302) + + self.checkSessionFlash(response, 'No content') + + def test_add_file_into_hg_missing_filename(self): + self.log_user() + response = self.app.post(url('files_add_home', + repo_name=HG_REPO, + revision='tip', f_path='/'), + params={ + 'content': "foo" + }, + status=302) + + self.checkSessionFlash(response, 'No filename') + + @parameterized.expand([ + ('/abs', 'foo'), + ('../rel', 'foo'), + ('file/../foo', 'foo'), + ]) + def test_add_file_into_hg_bad_filenames(self, location, filename): + self.log_user() + response = self.app.post(url('files_add_home', + repo_name=HG_REPO, + revision='tip', f_path='/'), + params={ + 'content': "foo", + 'filename': filename, + 'location': location + }, + status=302) + + self.checkSessionFlash(response, 'Location must be relative path and must not contain .. in path') + + @parameterized.expand([ + (1, '', 'foo.txt'), + (2, 'dir', 'foo.rst'), + (3, 'rel/dir', 'foo.bar'), + ]) + def test_add_file_into_hg(self, cnt, location, filename): + self.log_user() + repo = fixture.create_repo('commit-test-%s' % cnt, repo_type='hg') + response = self.app.post(url('files_add_home', + repo_name=repo.repo_name, + revision='tip', f_path='/'), + params={ + 'content': "foo", + 'filename': filename, + 'location': location + }, + status=302) + try: + self.checkSessionFlash(response, 'Successfully committed to %s' + % os.path.join(location, filename)) + finally: + fixture.destroy_repo(repo.repo_name) + + ##GIT - ADD FILE def test_add_file_view_git(self): self.log_user() response = self.app.get(url('files_add_home', repo_name=GIT_REPO, revision='tip', f_path='/')) + def test_add_file_into_git_missing_content(self): + self.log_user() + response = self.app.post(url('files_add_home', + repo_name=GIT_REPO, + revision='tip', f_path='/'), + params={ + 'content': '' + }, + status=302) + self.checkSessionFlash(response, 'No content') + + def test_add_file_into_git_missing_filename(self): + self.log_user() + response = self.app.post(url('files_add_home', + repo_name=GIT_REPO, + revision='tip', f_path='/'), + params={ + 'content': "foo" + }, + status=302) + + self.checkSessionFlash(response, 'No filename') + + @parameterized.expand([ + ('/abs', 'foo'), + ('../rel', 'foo'), + ('file/../foo', 'foo'), + ]) + def test_add_file_into_git_bad_filenames(self, location, filename): + self.log_user() + response = self.app.post(url('files_add_home', + repo_name=GIT_REPO, + revision='tip', f_path='/'), + params={ + 'content': "foo", + 'filename': filename, + 'location': location + }, + status=302) + + self.checkSessionFlash(response, 'Location must be relative path and must not contain .. in path') + + @parameterized.expand([ + (1, '', 'foo.txt'), + (2, 'dir', 'foo.rst'), + (3, 'rel/dir', 'foo.bar'), + ]) + def test_add_file_into_git(self, cnt, location, filename): + self.log_user() + repo = fixture.create_repo('commit-test-%s' % cnt, repo_type='git') + response = self.app.post(url('files_add_home', + repo_name=repo.repo_name, + revision='tip', f_path='/'), + params={ + 'content': "foo", + 'filename': filename, + 'location': location + }, + status=302) + try: + self.checkSessionFlash(response, 'Successfully committed to %s' + % os.path.join(location, filename)) + finally: + fixture.destroy_repo(repo.repo_name) + + #HG - EDIT def test_edit_file_view_hg(self): self.log_user() response = self.app.get(url('files_edit_home', repo_name=HG_REPO, revision='tip', f_path='vcs/nodes.py')) + def test_edit_file_view_not_on_branch_hg(self): + self.log_user() + repo = fixture.create_repo('test-edit-repo', repo_type='hg') + + ## add file + location = 'vcs' + filename = 'nodes.py' + response = self.app.post(url('files_add_home', + repo_name=repo.repo_name, + revision='tip', f_path='/'), + params={ + 'content': "def py():\n print 'hello'\n", + 'filename': filename, + 'location': location + }, + status=302) + response.follow() + try: + self.checkSessionFlash(response, 'Successfully committed to %s' + % os.path.join(location, filename)) + response = self.app.get(url('files_edit_home', + repo_name=repo.repo_name, + revision='tip', f_path='vcs/nodes.py'), + status=302) + self.checkSessionFlash(response, + 'You can only edit files with revision being a valid branch') + finally: + fixture.destroy_repo(repo.repo_name) + + def test_edit_file_view_commit_changes_hg(self): + self.log_user() + repo = fixture.create_repo('test-edit-repo', repo_type='hg') + + ## add file + location = 'vcs' + filename = 'nodes.py' + response = self.app.post(url('files_add_home', + repo_name=repo.repo_name, + revision='tip', + f_path='/'), + params={ + 'content': "def py():\n print 'hello'\n", + 'filename': filename, + 'location': location + }, + status=302) + response.follow() + try: + self.checkSessionFlash(response, 'Successfully committed to %s' + % os.path.join(location, filename)) + response = self.app.post(url('files_edit_home', + repo_name=repo.repo_name, + revision=repo.scm_instance.DEFAULT_BRANCH_NAME, + f_path='vcs/nodes.py'), + params={ + 'content': "def py():\n print 'hello world'\n", + 'message': 'i commited', + }, + status=302) + self.checkSessionFlash(response, + 'Successfully committed to vcs/nodes.py') + finally: + fixture.destroy_repo(repo.repo_name) + + #GIT - EDIT def test_edit_file_view_git(self): self.log_user() response = self.app.get(url('files_edit_home', repo_name=GIT_REPO, revision='tip', f_path='vcs/nodes.py')) + + def test_edit_file_view_not_on_branch_git(self): + self.log_user() + repo = fixture.create_repo('test-edit-repo', repo_type='git') + + ## add file + location = 'vcs' + filename = 'nodes.py' + response = self.app.post(url('files_add_home', + repo_name=repo.repo_name, + revision='tip', f_path='/'), + params={ + 'content': "def py():\n print 'hello'\n", + 'filename': filename, + 'location': location + }, + status=302) + response.follow() + try: + self.checkSessionFlash(response, 'Successfully committed to %s' + % os.path.join(location, filename)) + response = self.app.get(url('files_edit_home', + repo_name=repo.repo_name, + revision='tip', f_path='vcs/nodes.py'), + status=302) + self.checkSessionFlash(response, + 'You can only edit files with revision being a valid branch') + finally: + fixture.destroy_repo(repo.repo_name) + + def test_edit_file_view_commit_changes_git(self): + self.log_user() + repo = fixture.create_repo('test-edit-repo', repo_type='git') + + ## add file + location = 'vcs' + filename = 'nodes.py' + response = self.app.post(url('files_add_home', + repo_name=repo.repo_name, + revision='tip', + f_path='/'), + params={ + 'content': "def py():\n print 'hello'\n", + 'filename': filename, + 'location': location + }, + status=302) + response.follow() + try: + self.checkSessionFlash(response, 'Successfully committed to %s' + % os.path.join(location, filename)) + response = self.app.post(url('files_edit_home', + repo_name=repo.repo_name, + revision=repo.scm_instance.DEFAULT_BRANCH_NAME, + f_path='vcs/nodes.py'), + params={ + 'content': "def py():\n print 'hello world'\n", + 'message': 'i commited', + }, + status=302) + self.checkSessionFlash(response, + 'Successfully committed to vcs/nodes.py') + finally: + fixture.destroy_repo(repo.repo_name)