From 025aab81f5a721c1d05d2abd906898b3dde23883 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 02 2017 11:15:29 +0000 Subject: Adjust button title on the 'Fork and Edit' action When viewing the main project while the user already forked it, change the label of the button from "Fork and Edit" to "Edit in your fork" Fixes https://pagure.io/pagure/issue/2558 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/file.html b/pagure/templates/file.html index 8777091..b73035b 100644 --- a/pagure/templates/file.html +++ b/pagure/templates/file.html @@ -129,7 +129,11 @@ branchname=branchname, filename=filename) }}"> {{ forkbuttonform.csrf_token }} diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py index b1dba26..990c9f5 100644 --- a/tests/test_pagure_flask_ui_fork.py +++ b/tests/test_pagure_flask_ui_fork.py @@ -2312,14 +2312,14 @@ index 0000000..2a552bb output = self.app.get('/test/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertIn( - 'Fork and Edit\n \n', + 'Edit in your fork\n \n', output.data) # Check fork-edit doesn't show for binary output = self.app.get('/test/blob/master/f/test.jpg') self.assertEqual(output.status_code, 200) self.assertNotIn( - 'Fork and Edit\n \n', + 'Edit in your fork\n \n', output.data) @patch('pagure.lib.notify.send_email') @@ -2371,7 +2371,6 @@ index 0000000..2a552bb # UI test for deleted main output = self.app.get('/fork/foo/test') self.assertEqual(output.status_code, 200) - print output.data self.assertIn('Fork from a deleted repository\n', output.data) # Testing commit endpoint diff --git a/tests/test_pagure_flask_ui_repo_view_file.py b/tests/test_pagure_flask_ui_repo_view_file.py index a79df78..d906bb3 100644 --- a/tests/test_pagure_flask_ui_repo_view_file.py +++ b/tests/test_pagure_flask_ui_repo_view_file.py @@ -239,7 +239,7 @@ class PagureFlaskRepoViewFiletests(LocalBasetests): 'onclick="fork_project.submit();">\n ' ' Fork and Edit', output.data) - def test_view_file_fork_and_edit_logged_out(self): + def test_view_file_fork_and_edit_logged_in(self): """ Test the view_file fork and edit button presence when logged in. """ @@ -258,17 +258,31 @@ class PagureFlaskRepoViewFiletests(LocalBasetests): ' Fork and Edit', output.data) -class PagureFlaskRepoViewFileForktests(PagureFlaskRepoViewFiletests): +class PagureFlaskRepoViewFileForktests(LocalBasetests): """ Tests for view_file endpoint of the flask pagure app for a fork """ def setUp(self): """ Set up the environnment, ran before every tests. """ super(PagureFlaskRepoViewFileForktests, self).setUp() + tests.create_projects(self.session) + tests.create_projects_git( + os.path.join(self.path, 'repos'), bare=True) + + # Add some content to the git repo + tests.add_content_git_repo( + os.path.join(self.path, 'repos', 'test.git')) + tests.add_readme_git_repo( + os.path.join(self.path, 'repos', 'test.git')) + tests.add_binary_git_repo( + os.path.join(self.path, 'repos', 'test.git'), 'test.jpg') + tests.add_binary_git_repo( + os.path.join(self.path, 'repos', 'test.git'), 'test_binary') + # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou - name='test3', + name='test', description='test project #3', is_fork=True, parent_id=1, @@ -278,27 +292,27 @@ class PagureFlaskRepoViewFileForktests(PagureFlaskRepoViewFiletests): self.session.commit() tests.add_content_git_repo( - os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) + os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) tests.add_readme_git_repo( - os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git')) + os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git')) tests.add_commit_git_repo( - os.path.join(self.path, 'repos', 'forks', 'pingou', 'test3.git'), + os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'), ncommits=10) def test_view_file_nested_file_in_fork(self): """ Test the view_file with a nested file in fork. """ # Verify the nav links correctly when viewing a file/folder in a fork. output = self.app.get( - '/fork/pingou/test3/blob/master/f/folder1/folder2/file') + '/fork/pingou/test/blob/master/f/folder1/folder2/file') self.assertEqual(output.status_code, 200) self.assertIn( - '
  • \n' + '
  • \n' '   ' 'folder2\n
  • ', output.data) def test_view_file_in_branch_in_fork(self): """ Test the view_file in a specific branch of a fork. """ - output = self.app.get('/fork/pingou/test3/blob/master/f/sources') + output = self.app.get('/fork/pingou/test/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertIn('', output.data) self.assertIn( @@ -312,7 +326,7 @@ class PagureFlaskRepoViewFileForktests(PagureFlaskRepoViewFiletests): """ Test the view_file on a text file on a fork when logged out. """ # not logged in, no edit button but fork & edit is there - output = self.app.get('/fork/pingou/test3/blob/master/f/sources') + output = self.app.get('/fork/pingou/test/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertNotIn( '' + 'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">' 'Edit', output.data) self.assertNotIn( 'onclick="fork_project.submit();">\n ' @@ -348,16 +362,34 @@ class PagureFlaskRepoViewFileForktests(PagureFlaskRepoViewFiletests): # is there user = tests.FakeUser(username='foo') with tests.user_set(pagure.APP, user): - output = self.app.get('/fork/pingou/test3/blob/master/f/sources') + output = self.app.get('/fork/pingou/test/blob/master/f/sources') self.assertEqual(output.status_code, 200) self.assertNotIn( '' + 'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">' 'Edit', output.data) self.assertIn( 'onclick="fork_project.submit();">\n ' ' Fork and Edit', output.data) + def test_view_file_fork_and_edit_on_project(self): + """ Test the view_file on a text file on somone else's fork when + logged in. + """ + + # logged in and seeing the project you forked + user = tests.FakeUser(username='pingou') + with tests.user_set(pagure.APP, user): + output = self.app.get('/test/blob/master/f/sources') + self.assertEqual(output.status_code, 200) + self.assertIn( + '' + 'Edit', output.data) + self.assertIn( + 'onclick="fork_project.submit();">\n ' + ' Edit in your fork', output.data) + if __name__ == '__main__': unittest.main(verbosity=2)