Advertisement
lenkaseg

acls final tests/fork.oy

Feb 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.07 KB | None | 0 0
  1.     @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  2.     def test_api_pull_request_open_project_token_different_project(self):
  3.         """Test the api_pull_request_create method with the project token
  4.        of a different project - fails"""
  5.  
  6.         tests.create_projects(self.session)
  7.         tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  8.         tests.create_projects_git(os.path.join(self.path, 'requests'),
  9.                 bare=True)
  10.         tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  11.         tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
  12.                 branch='test')
  13.         tests.create_tokens(self.session, project_id=2)
  14.         tests.create_tokens_acl(self.session)
  15.  
  16.         headers = {'Authorization': 'token foo_token'}
  17.         data = {
  18.             'title': 'Test of PR',
  19.             'inicial comment': 'Some readme adjustment',
  20.             'branch_to': 'master',
  21.             'branch_from': 'test'
  22.             }
  23.  
  24.         output = self.app.post(
  25.                 '/api/0/test/pull-request/new', headers=headers, data=data)
  26.         self.assertEqual(output.status_code, 401)
  27.  
  28.  
  29.     @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  30.     def test_api_pull_request_open_user_token_invalid_acls(self):
  31.         """Test the api_pull_request_create method with the user token, but with
  32.        no acls for opening pull request - fails"""
  33.  
  34.         tests.create_projects(self.session)
  35.         tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  36.         tests.create_projects_git(os.path.join(self.path, 'requests'),
  37.                                   bare=True)
  38.         tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  39.         tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
  40.                                   branch='test')
  41.         tests.create_tokens(self.session, project_id=None)
  42.         for acl in ("create_project", "fork_project", "modify_project",
  43.                     "update_watch_status"):
  44.             tests.create_tokens_acl(self.session, acl_name=acl)
  45.  
  46.         headers = {'Authorization': 'token aaabbbcccddd'}
  47.         data = {
  48.             'title': 'Test of PR',
  49.             'initial_comment': 'Some readme adjustment',
  50.             'branch_to': 'master',
  51.             'branch_from': 'test',
  52.             }
  53.  
  54.         output = self.app.post(
  55.             '/api/0/test/pull-request/new', headers=headers, data=data)
  56.         self.assertEqual(output.status_code, 401)
  57.  
  58.     @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  59.     def test_api_pull_request_open_from_branch_to_origin(self):
  60.         """Test the api_pull_request_create method from a fork to a master,
  61.       with project token of a origin with all the acls"""
  62.  
  63.         tests.setup_for_my_test(self.session, self.path)
  64.         tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'forks',
  65.             'pingou', 'vegetable.git'), branch='branch')
  66.         tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'forks',
  67.             'pingou', 'vegetable.git'), branch='branch')
  68.         tests.create_tokens_acl(self.session, token_id='iamparenttoken')
  69.         tests.create_tokens_acl(self.session, token_id='iamforktoken')
  70.          
  71.         headers = {'Authorization': 'token iamforktoken'}
  72.        
  73.         data = {
  74.             'title': 'war of tomatoes',
  75.             'initial_comment': 'the manifest',
  76.             'branch_to': 'master',
  77.             'branch_from': 'branch',
  78.             }
  79.  
  80.         output = self.app.post('/api/0/fork/pingou/vegetable/pull-request/new', headers=headers, data=data)
  81.         self.assertEqual(output.status_code, 200)
  82.  
  83.  
  84.     @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  85.     def test_api_pull_request_open_user_token(self):
  86.         """Test the api_pull_request_create method of the flask api with the
  87.        user token - passes"""
  88.         tests.create_projects(self.session)
  89.         tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  90.         tests.create_projects_git(os.path.join(self.path, 'requests'),
  91.                                   bare=True)
  92.         tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  93.         tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
  94.                                   branch='test')
  95.         tests.create_tokens(self.session, project_id=None)
  96.         for acl in ("create_project", "fork_project", "modify_project",
  97.                     "update_watch_status", "pull_request_create"):
  98.             tests.create_tokens_acl(self.session, acl_name=acl)
  99.  
  100.         headers = {'Authorization': 'token aaabbbcccddd'}
  101.         data = {
  102.             'title': 'Test of PR',
  103.             'initial_comment': 'Some readme adjustment',
  104.             'branch_to': 'master',
  105.             'branch_from': 'test',
  106.             }
  107.  
  108.         output = self.app.post(
  109.             '/api/0/test/pull-request/new', headers=headers, data=data)
  110.         self.assertEqual(output.status_code, 200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement