Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
- def test_api_pull_request_open_project_token_different_project(self):
- """Test the api_pull_request_create method with the project token
- of a different project - fails"""
- 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=2)
- tests.create_tokens_acl(self.session)
- headers = {'Authorization': 'token foo_token'}
- data = {
- 'title': 'Test of PR',
- 'inicial comment': 'Some readme adjustment',
- 'branch_to': 'master',
- 'branch_from': 'test'
- }
- output = self.app.post(
- '/api/0/test/pull-request/new', headers=headers, data=data)
- self.assertEqual(output.status_code, 401)
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
- def test_api_pull_request_open_user_token_invalid_acls(self):
- """Test the api_pull_request_create method with the user token, but with
- no acls for opening pull request - fails"""
- 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)
- for acl in ("create_project", "fork_project", "modify_project",
- "update_watch_status"):
- tests.create_tokens_acl(self.session, acl_name=acl)
- headers = {'Authorization': 'token aaabbbcccddd'}
- data = {
- 'title': 'Test of PR',
- 'initial_comment': 'Some readme adjustment',
- 'branch_to': 'master',
- 'branch_from': 'test',
- }
- output = self.app.post(
- '/api/0/test/pull-request/new', headers=headers, data=data)
- self.assertEqual(output.status_code, 401)
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
- def test_api_pull_request_open_from_branch_to_origin(self):
- """Test the api_pull_request_create method from a fork to a master,
- with project token of a origin with all the acls"""
- tests.setup_for_my_test(self.session, self.path)
- tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'forks',
- 'pingou', 'vegetable.git'), branch='branch')
- tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'forks',
- 'pingou', 'vegetable.git'), branch='branch')
- tests.create_tokens_acl(self.session, token_id='iamparenttoken')
- tests.create_tokens_acl(self.session, token_id='iamforktoken')
- headers = {'Authorization': 'token iamforktoken'}
- data = {
- 'title': 'war of tomatoes',
- 'initial_comment': 'the manifest',
- 'branch_to': 'master',
- 'branch_from': 'branch',
- }
- output = self.app.post('/api/0/fork/pingou/vegetable/pull-request/new', headers=headers, data=data)
- self.assertEqual(output.status_code, 200)
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
- def test_api_pull_request_open_user_token(self):
- """Test the api_pull_request_create method of the flask api with the
- user token - passes"""
- 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)
- for acl in ("create_project", "fork_project", "modify_project",
- "update_watch_status", "pull_request_create"):
- tests.create_tokens_acl(self.session, acl_name=acl)
- headers = {'Authorization': 'token aaabbbcccddd'}
- data = {
- 'title': 'Test of PR',
- 'initial_comment': 'Some readme adjustment',
- 'branch_to': 'master',
- 'branch_from': 'test',
- }
- output = self.app.post(
- '/api/0/test/pull-request/new', headers=headers, data=data)
- self.assertEqual(output.status_code, 200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement