예제 #1
0
 def test_wrong_header(self):
     headers = {'nonEvent': 'whatever'}
     payload_json = 'whatever'
     mock_request = Mock()
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {'error': "This does not appear to be from DCS."}
     self.assertEqual(output, expected)
예제 #2
0
 def test_missing_repo(self):
     headers = {'X-Gitea-Event': 'push'}
     payload_json = {'something': 'whatever'}
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {'error': "No repo URL specified for push."}
     self.assertEqual(output, expected)
예제 #3
0
 def test_blank(self):
     payload_json = ''
     mock_request = Mock()
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {
         'error':
         "No payload found. You must submit a POST request via a DCS webhook notification."
     }
     self.assertEqual(output, expected)
예제 #4
0
 def test_typical_full_json_success(self):
     headers = {'X-Gitea-Event': 'push'}
     with open('tests/Resources/webhook_post.json', 'rt') as json_file:
         payload_json = json.load(json_file)
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = True, payload_json
     self.assertEqual(output, expected)
예제 #5
0
 def test_bad_repo(self):
     headers = {'X-Gitea-Event': 'push'}
     payload_json = {'repository': {'html_url': 'whatever'}}
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {
         'error':
         "The repo for push does not belong to https://git.door43.org."
     }
     self.assertEqual(output, expected)
예제 #6
0
 def test_bad_header(self):
     headers = {'X-Gitea-Event': 'whatever'}
     payload_json = 'whatever'
     mock_request = Mock()
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {
         'error':
         "This does not appear to be a push, release, fork, or delete."
     }
     self.assertEqual(output, expected)
예제 #7
0
 def test_missing_commit_branch(self):
     headers = {'X-Gitea-Event': 'push'}
     payload_json = {
         'repository': {
             'html_url': 'https://git.door43.org/whatever'
         }
     }
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {'error': "No commits specified for push."}
     self.assertEqual(output, expected)
예제 #8
0
 def test_empty_release(self):
     headers = {'X-Gitea-Event': 'release'}
     payload_json = {
         'action': 'published',
         'repository': {
             'html_url': 'https://git.door43.org/whatever',
         },
     }
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = True, payload_json
     self.assertEqual(output, expected)
예제 #9
0
 def test_basic_json_success(self):
     headers = {'X-Gitea-Event': 'push'}
     payload_json = {
         'ref': 'refs/heads/master',
         'repository': {
             'html_url': 'https://git.door43.org/whatever',
             'default_branch': 'master',
         },
         'commits': ['some commit info'],
     }
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = True, payload_json
     self.assertEqual(output, expected)
예제 #10
0
 def test_empty_commits_entry(self):
     headers = {'X-Gitea-Event': 'push'}
     payload_json = {
         'ref': 'refs/heads/master',
         'repository': {
             'html_url': 'https://git.door43.org/whatever',
             'default_branch': 'master',
         },
         'commits': [],
     }
     mock_request = Mock(**{'get_json.return_value': payload_json})
     mock_request.headers = headers
     mock_request.data = payload_json
     output = check_posted_payload(mock_request, logging)
     expected = False, {'error': "No commits found for push."}
     self.assertEqual(output, expected)