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,3 +1,4 @@ +# -*- coding: utf-8 -*- import os from rhodecode.tests import * from rhodecode.model.db import Repository @@ -12,6 +13,9 @@ ARCHIVE_SPECS = { '.zip': ('application/zip', 'zip', ''), } +HG_NODE_HISTORY = fixture.load_resource('hg_node_history_response.json') +GIT_NODE_HISTORY = fixture.load_resource('git_node_history_response.json') + def _set_downloads(repo_name, set_to): repo = Repository.get_by_repo_name(repo_name) @@ -107,207 +111,29 @@ removed extra unicode conversion in diff self.log_user() response = self.app.get(url(controller='files', action='history', repo_name=HG_REPO, - revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc', + revision='tip', f_path='vcs/nodes.py'), extra_environ={'HTTP_X_PARTIAL_XHR': '1'},) - #test or history - response.mustcontain(""" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -""") + self.assertEqual(response.body, HG_NODE_HISTORY) + + def test_file_source_history_git(self): + self.log_user() + response = self.app.get(url(controller='files', action='history', + repo_name=GIT_REPO, + revision='master', + f_path='vcs/nodes.py'), + extra_environ={'HTTP_X_PARTIAL_XHR': '1'},) + self.assertEqual(response.body, GIT_NODE_HISTORY) def test_file_annotation(self): self.log_user() response = self.app.get(url(controller='files', action='index', repo_name=HG_REPO, - revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc', + revision='tip', f_path='vcs/nodes.py', annotate=True)) - response.mustcontain("""Branch: default""") - - def test_file_annotation_history(self): - self.log_user() - response = self.app.get(url(controller='files', action='history', - repo_name=HG_REPO, - revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc', - f_path='vcs/nodes.py', - annotate=True), - extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) - - response.mustcontain(""" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -""") + response.mustcontain("""r356:25213a5fbb04""") def test_file_annotation_git(self): self.log_user() @@ -316,6 +142,49 @@ removed extra unicode conversion in diff revision='master', f_path='vcs/nodes.py', annotate=True)) + response.mustcontain("""r345:c994f0de03b2""") + + def test_file_annotation_history(self): + self.log_user() + response = self.app.get(url(controller='files', action='history', + repo_name=HG_REPO, + revision='tip', + f_path='vcs/nodes.py', + annotate=True), + extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) + + self.assertEqual(response.body, HG_NODE_HISTORY) + + def test_file_annotation_history_git(self): + self.log_user() + response = self.app.get(url(controller='files', action='history', + repo_name=GIT_REPO, + revision='master', + f_path='vcs/nodes.py', + annotate=True), + extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) + + self.assertEqual(response.body, GIT_NODE_HISTORY) + + def test_file_authors(self): + self.log_user() + response = self.app.get(url(controller='files', action='authors', + repo_name=HG_REPO, + revision='tip', + f_path='vcs/nodes.py', + annotate=True)) + response.mustcontain('Marcin Kuzminski') + response.mustcontain('Lukasz Balcerzak') + + def test_file_authors_git(self): + self.log_user() + response = self.app.get(url(controller='files', action='authors', + repo_name=GIT_REPO, + revision='master', + f_path='vcs/nodes.py', + annotate=True)) + response.mustcontain('Marcin Kuzminski') + response.mustcontain('Lukasz Balcerzak') def test_archival(self): self.log_user() @@ -385,7 +254,7 @@ removed extra unicode conversion in diff revision=rev, f_path=f_path), status=404) - msg = """Revision %s does not exist for this repository""" % (rev) + msg = """Such revision does not exist for this repository""" response.mustcontain(msg) def test_raw_file_wrong_f_path(self): @@ -422,7 +291,7 @@ removed extra unicode conversion in diff revision=rev, f_path=f_path), status=404) - msg = """Revision %s does not exist for this repository""" % (rev) + msg = """Such revision does not exist for this repository""" response.mustcontain(msg) def test_raw_wrong_f_path(self): @@ -732,3 +601,143 @@ removed extra unicode conversion in diff 'Successfully committed to vcs/nodes.py') finally: fixture.destroy_repo(repo.repo_name) + + # HG - delete + def test_delete_file_view_hg(self): + self.log_user() + response = self.app.get(url('files_delete_home', + repo_name=HG_REPO, + revision='tip', f_path='vcs/nodes.py')) + + def test_delete_file_view_not_on_branch_hg(self): + self.log_user() + repo = fixture.create_repo('test-delete-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_delete_home', + repo_name=repo.repo_name, + revision='tip', f_path='vcs/nodes.py'), + status=302) + self.checkSessionFlash(response, + 'You can only delete files with revision being a valid branch') + finally: + fixture.destroy_repo(repo.repo_name) + + def test_delete_file_view_commit_changes_hg(self): + self.log_user() + repo = fixture.create_repo('test-delete-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_delete_home', + repo_name=repo.repo_name, + revision=repo.scm_instance.DEFAULT_BRANCH_NAME, + f_path='vcs/nodes.py'), + params={ + 'message': 'i commited', + }, + status=302) + self.checkSessionFlash(response, + 'Successfully deleted file vcs/nodes.py') + finally: + fixture.destroy_repo(repo.repo_name) + + # GIT - delete + def test_delete_file_view_git(self): + self.log_user() + response = self.app.get(url('files_delete_home', + repo_name=HG_REPO, + revision='tip', f_path='vcs/nodes.py')) + + def test_delete_file_view_not_on_branch_git(self): + self.log_user() + repo = fixture.create_repo('test-delete-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_delete_home', + repo_name=repo.repo_name, + revision='tip', f_path='vcs/nodes.py'), + status=302) + self.checkSessionFlash(response, + 'You can only delete files with revision being a valid branch') + finally: + fixture.destroy_repo(repo.repo_name) + + def test_delete_file_view_commit_changes_git(self): + self.log_user() + repo = fixture.create_repo('test-delete-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_delete_home', + repo_name=repo.repo_name, + revision=repo.scm_instance.DEFAULT_BRANCH_NAME, + f_path='vcs/nodes.py'), + params={ + 'message': 'i commited', + }, + status=302) + self.checkSessionFlash(response, + 'Successfully deleted file vcs/nodes.py') + finally: + fixture.destroy_repo(repo.repo_name)