From 02a7ccc7e94abe6c9d402fcf7b9e654e1dfc6f5d Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: May 22 2017 20:37:00 +0000 Subject: For PR test, make actual commits Signed-off-by: Patrick Uiterwijk --- diff --git a/tests/__init__.py b/tests/__init__.py index 2cbcf34..b263f27 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -57,7 +57,6 @@ PAGLOG.setLevel(logging.CRITICAL) PAGLOG.handlers = [] CONFIG_TEMPLATE = """ -PAGURE_CI_SERVICES = ['jenkins'] GIT_FOLDER = '%(path)s/repos' DOCS_FOLDER = '%(path)s/docs' TICKETS_FOLDER = '%(path)s/tickets' @@ -258,7 +257,7 @@ class Modeltests(unittest.TestCase): self.broker.terminate() # Remove testdir - shutil.rmtree(self.path) + #shutil.rmtree(self.path) self.path = None def get_csrf(self, url='/new'): @@ -561,11 +560,12 @@ Dev instance: http://209.132.184.222/ (/!\\ May change unexpectedly, it's a dev shutil.rmtree(newfolder) -def add_commit_git_repo(folder, ncommits=10, filename='sources'): +def add_commit_git_repo(folder, ncommits=10, filename='sources', + branch='master'): """ Create some more commits for the specified git repo. """ if not os.path.exists(folder): os.makedirs(folder) - brepo = pygit2.init_repository(folder, bare=True) + pygit2.init_repository(folder, bare=True) newfolder = tempfile.mkdtemp(prefix='pagure-tests') repo = pygit2.clone_repository(folder, newfolder) @@ -593,7 +593,7 @@ def add_commit_git_repo(folder, ncommits=10, filename='sources'): committer = pygit2.Signature( 'Cecil Committer', 'cecil@committers.tld') repo.create_commit( - 'refs/heads/master', # the name of the reference to update + 'refs/heads/master', author, committer, 'Add row %s to %s file' % (index, filename), @@ -605,10 +605,7 @@ def add_commit_git_repo(folder, ncommits=10, filename='sources'): # Push to origin ori_remote = repo.remotes[0] - master_ref = repo.lookup_reference('HEAD').resolve() - refname = '%s:%s' % (master_ref.name, master_ref.name) - - PagureRepo.push(ori_remote, refname) + PagureRepo.push(ori_remote, 'HEAD:refs/heads/%s' % branch) shutil.rmtree(newfolder) diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py index f088c38..dfcb704 100644 --- a/tests/test_pagure_flask_api_fork.py +++ b/tests/test_pagure_flask_api_fork.py @@ -483,13 +483,17 @@ class PagureFlaskApiForktests(tests.Modeltests): ) @patch('pagure.lib.notify.send_email') - @patch('pagure.lib.git.merge_pull_request') - def test_api_pull_request_merge(self, mpr, send_email): + def test_api_pull_request_merge(self, send_email): """ Test the api_pull_request_merge method of the flask api. """ - mpr.return_value = 'Changes merged!' send_email.return_value = True tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + tests.create_projects_git(os.path.join(self.path, 'requests'), + bare=True) + tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) + tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'), + branch='test') tests.create_tokens(self.session) tests.create_tokens_acl(self.session) @@ -499,7 +503,7 @@ class PagureFlaskApiForktests(tests.Modeltests): req = pagure.lib.new_pull_request( session=self.session, repo_from=forked_repo, - branch_from='master', + branch_from='test', repo_to=repo, branch_to='master', title='test pull-request', @@ -596,13 +600,17 @@ class PagureFlaskApiForktests(tests.Modeltests): ) @patch('pagure.lib.notify.send_email') - @patch('pagure.lib.git.merge_pull_request') - def test_api_pull_request_merge_user_token(self, mpr, send_email): + def test_api_pull_request_merge_user_token(self, send_email): """ Test the api_pull_request_merge method of the flask api. """ - mpr.return_value = 'Changes merged!' send_email.return_value = True tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + tests.create_projects_git(os.path.join(self.path, 'requests'), + bare=True) + tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) + tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'), + branch='test') tests.create_tokens(self.session, project_id=None) tests.create_tokens_acl(self.session) @@ -612,7 +620,7 @@ class PagureFlaskApiForktests(tests.Modeltests): req = pagure.lib.new_pull_request( session=self.session, repo_from=forked_repo, - branch_from='master', + branch_from='test', repo_to=repo, branch_to='master', title='test pull-request', diff --git a/tests/test_pagure_flask_api_ui_private_repo.py b/tests/test_pagure_flask_api_ui_private_repo.py index e952475..5f60edd 100644 --- a/tests/test_pagure_flask_api_ui_private_repo.py +++ b/tests/test_pagure_flask_api_ui_private_repo.py @@ -1811,10 +1811,8 @@ class PagurePrivateRepotest(tests.Modeltests): ) @patch('pagure.lib.notify.send_email') - @patch('pagure.lib.git.merge_pull_request') - def test_api_private_repo_pr_merge(self, mpr, send_email): + def test_api_private_repo_pr_merge(self, send_email): """ Test the api_pull_request_merge method of the flask api. """ - mpr.return_value = 'Changes merged!' send_email.return_value = True pagure.APP.config['REQUESTS_FOLDER'] = None @@ -1830,6 +1828,15 @@ class PagurePrivateRepotest(tests.Modeltests): self.session.add(item) self.session.commit() + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + tests.create_projects_git(os.path.join(self.path, 'requests'), + bare=True) + tests.add_readme_git_repo(os.path.join(self.path, 'repos', + 'test4.git')) + tests.add_commit_git_repo(os.path.join(self.path, 'repos', + 'test4.git'), + branch='test') tests.create_tokens(self.session) tests.create_tokens_acl(self.session) @@ -1850,7 +1857,7 @@ class PagurePrivateRepotest(tests.Modeltests): req = pagure.lib.new_pull_request( session=self.session, repo_from=forked_repo, - branch_from='master', + branch_from='test', repo_to=repo, branch_to='master', title='test pull-request',