Add tests for build web hooks endpoint
This commit is contained in:
parent
0ea600628b
commit
6f567e0850
7 changed files with 64 additions and 12 deletions
|
@ -517,6 +517,9 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
|||
|
||||
def handle_trigger_request(self, request):
|
||||
payload = request.get_json()
|
||||
if payload is None:
|
||||
raise InvalidPayloadException('Missing payload')
|
||||
|
||||
logger.debug('Got BitBucket request: %s', payload)
|
||||
|
||||
repository = self._get_repository_client()
|
||||
|
|
|
@ -530,6 +530,8 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
|||
def handle_trigger_request(self, request):
|
||||
# Check the payload to see if we should skip it based on the lack of a head_commit.
|
||||
payload = request.get_json()
|
||||
if payload is None:
|
||||
raise InvalidPayloadException('Missing payload')
|
||||
|
||||
# This is for GitHub's probing/testing.
|
||||
if 'zen' in payload:
|
||||
|
@ -537,16 +539,16 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
|||
|
||||
# Lookup the default branch for the repository.
|
||||
if 'repository' not in payload:
|
||||
raise ValidationRequestException("Missing 'repository' on request")
|
||||
raise InvalidPayloadException("Missing 'repository' on request")
|
||||
|
||||
if 'owner' not in payload['repository']:
|
||||
raise ValidationRequestException("Missing 'owner' on repository")
|
||||
raise InvalidPayloadException("Missing 'owner' on repository")
|
||||
|
||||
if 'name' not in payload['repository']['owner']:
|
||||
raise ValidationRequestException("Missing owner 'name' on repository")
|
||||
raise InvalidPayloadException("Missing owner 'name' on repository")
|
||||
|
||||
if 'name' not in payload['repository']:
|
||||
raise ValidationRequestException("Missing 'name' on repository")
|
||||
raise InvalidPayloadException("Missing 'name' on repository")
|
||||
|
||||
default_branch = None
|
||||
lookup_user = None
|
||||
|
|
|
@ -514,7 +514,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
def handle_trigger_request(self, request):
|
||||
payload = request.get_json()
|
||||
if not payload:
|
||||
raise SkipRequestException()
|
||||
raise InvalidPayloadException()
|
||||
|
||||
logger.debug('GitLab trigger payload %s', payload)
|
||||
|
||||
|
@ -523,7 +523,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
repo = gl_client.getproject(self.config['build_source'])
|
||||
if repo is False:
|
||||
logger.debug('Skipping GitLab build; project %s not found', self.config['build_source'])
|
||||
raise SkipRequestException()
|
||||
raise InvalidPayloadException()
|
||||
|
||||
default_branch = repo['default_branch']
|
||||
metadata = get_transformed_webhook_payload(payload, default_branch=default_branch,
|
||||
|
|
|
@ -2,7 +2,8 @@ import json
|
|||
import pytest
|
||||
|
||||
from buildtrigger.test.githubmock import get_github_trigger
|
||||
from buildtrigger.triggerutil import SkipRequestException, ValidationRequestException
|
||||
from buildtrigger.triggerutil import (SkipRequestException, ValidationRequestException,
|
||||
InvalidPayloadException)
|
||||
from endpoints.building import PreparedBuild
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
|
@ -14,8 +15,8 @@ def github_trigger():
|
|||
@pytest.mark.parametrize('payload, expected_error, expected_message', [
|
||||
('{"zen": true}', SkipRequestException, ""),
|
||||
|
||||
('{}', ValidationRequestException, "Missing 'repository' on request"),
|
||||
('{"repository": "foo"}', ValidationRequestException, "Missing 'owner' on repository"),
|
||||
('{}', InvalidPayloadException, "Missing 'repository' on request"),
|
||||
('{"repository": "foo"}', InvalidPayloadException, "Missing 'owner' on repository"),
|
||||
|
||||
# Valid payload:
|
||||
('''{
|
||||
|
|
|
@ -36,7 +36,7 @@ def test_lookup_user(email, expected_response, gitlab_trigger):
|
|||
|
||||
|
||||
@pytest.mark.parametrize('payload, expected_error, expected_message', [
|
||||
('{}', SkipRequestException, ''),
|
||||
('{}', InvalidPayloadException, ''),
|
||||
|
||||
# Valid payload:
|
||||
('''{
|
||||
|
|
Reference in a new issue