diff --git a/tests/test_progit_flask_ui_fork.py b/tests/test_progit_flask_ui_fork.py index 7f2a3fb..d944333 100644 --- a/tests/test_progit_flask_ui_fork.py +++ b/tests/test_progit_flask_ui_fork.py @@ -1277,6 +1277,83 @@ index 0000000..2a552bb self.assertIn( '
  • Request created
  • ', output.data) + @patch('pagure.lib.notify.send_email') + def test_new_request_pull_empty_repo(self, send_email): + """ Test the new_request_pull endpoint against an empty repo. """ + send_email.return_value = True + + self.test_fork_project() + + tests.create_projects_git( + os.path.join(tests.HERE, 'requests'), bare=True) + + repo = pagure.lib.get_project(self.session, 'test') + fork = pagure.lib.get_project(self.session, 'test', user='foo') + + # Create a git repo to play with + gitrepo = os.path.join(tests.HERE, 'repos', 'test.git') + repo = pygit2.init_repository(gitrepo, bare=True) + + # Create a fork of this repo + newpath = tempfile.mkdtemp(prefix='pagure-fork-test') + gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git') + new_repo = pygit2.clone_repository(gitrepo, newpath) + + # Edit the sources file again + with open(os.path.join(newpath, 'sources'), 'w') as stream: + stream.write('foo\n bar\nbaz\n boose') + new_repo.index.add('sources') + new_repo.index.write() + + # Commits the files added + tree = new_repo.index.write_tree() + author = pygit2.Signature( + 'Alice Author', 'alice@authors.tld') + committer = pygit2.Signature( + 'Cecil Committer', 'cecil@committers.tld') + new_repo.create_commit( + 'refs/heads/feature', + author, + committer, + 'A commit on branch feature', + tree, + [] + ) + refname = 'refs/heads/feature' + ori_remote = new_repo.remotes[0] + ori_remote.push(refname) + + user = tests.FakeUser() + user.username = 'foo' + with tests.user_set(pagure.APP, user): + output = self.app.get('/fork/foo/test/diff/master..feature') + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Pull request # - test - Pagure', + output.data) + self.assertIn( + '

    No commits found

    ', output.data) + self.assertIn( + '', output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + 'csrf_token': csrf_token, + 'title': 'foo bar PR', + } + + output = self.app.post( + '/test/diff/master..feature', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Overview - test - Pagure', output.data) + self.assertIn( + '
  • Fork is empty, there are no commits to ' + 'request pulling
  • ', output.data) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskForktests)