From 722f0402b1d7213f9fce3c2592117012ac1370d7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 04 2018 08:48:44 +0000 Subject: Add tests checking pagure's behavior when the commit message has a link Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/__init__.py b/tests/__init__.py index 007a756..101530e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -926,7 +926,8 @@ def add_commit_git_repo(folder, ncommits=10, filename='sources', def add_content_to_git( - folder, branch='master', filename='sources', content='foo'): + folder, branch='master', filename='sources', content='foo', + message=None): """ Create some more commits for the specified git repo. """ repo, newfolder, branch_ref_obj = _clone_and_top_commits( folder, branch, branch_ref=True) @@ -956,11 +957,12 @@ def add_content_to_git( committer = pygit2.Signature( 'Cecil Committer', 'cecil@committers.tld') branch_ref = "refs/heads/%s" % branch + message = message or 'Add content to file %s' % (filename) repo.create_commit( branch_ref, # the name of the reference to update author, committer, - 'Add content to file %s' % (filename), + message, # binary string representing the tree object ID tree, # list of binary strings representing parents of the new commit diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 5d5e3e8..7533572 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -2878,6 +2878,83 @@ class PagureFlaskRepotests(tests.Modeltests): 'text-muted fa-fw" data-glyph="spreadsheet"> Commits' '\n ', output_text) + def test_view_commit_with_full_link(self): + """ Test the view_commit endpoint when the commit message includes + an url. """ + + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + + folder = os.path.join(self.path, 'repos', 'test.git') + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(folder) + tests.create_projects_git(folder, bare=True) + # Add a commit with an url in the commit message + tests.add_content_to_git( + folder, branch='master', filename='sources', content='foo', + message='Test commit message\n\n' + 'Fixes http://example.com/pagure/issue/2' + ) + + # Add a README to the git repo - First commit + repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) + commit = repo.revparse_single('HEAD') + + # View first commit + output = self.app.get('/test/c/%s' % commit.oid.hex) + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn( + '#commit-overview-collapse', + output_text) + self.assertIn( + '
\n    '
+            'Test commit message\n    \n    '
+            'Fixes http://example.com/pagure/issue/2\n        '
+            '
', output_text) + self.assertIn( + '
file added
', output_text) + + def test_view_commit_with_short_link(self): + """ Test the view_commit endpoint when the commit message includes + an url. """ + + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + + folder = os.path.join(self.path, 'repos', 'test.git') + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(folder) + tests.create_projects_git(folder, bare=True) + # Add a commit with an url in the commit message + tests.add_content_to_git( + folder, branch='master', filename='sources', content='foo', + message='Test commit message\n\nFixes #2' + ) + + # Add a README to the git repo - First commit + repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) + commit = repo.revparse_single('HEAD') + + # View first commit + output = self.app.get('/test/c/%s' % commit.oid.hex) + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn( + '#commit-overview-collapse', + output_text) + self.assertIn( + '
\n    '
+            'Test commit message\n    \n    '
+            'Fixes #2\n        
', output_text) + self.assertIn( + '
file added
', output_text) + def test_view_commit_patch(self): """ Test the view_commit_patch endpoint. """