Add missing bitbucket test
This commit is contained in:
parent
497c90e7ea
commit
84b298f36b
2 changed files with 82 additions and 13 deletions
|
@ -35,7 +35,7 @@ BITBUCKET_WEBHOOK_PAYLOAD_SCHEMA = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'required': ['full_name'],
|
'required': ['full_name'],
|
||||||
},
|
}, # /Repository
|
||||||
'push': {
|
'push': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'properties': {
|
'properties': {
|
||||||
|
@ -91,10 +91,10 @@ BITBUCKET_WEBHOOK_PAYLOAD_SCHEMA = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'required': ['html', 'avatar'],
|
'required': ['html', 'avatar'],
|
||||||
},
|
}, # /User
|
||||||
},
|
},
|
||||||
'required': ['username'],
|
'required': ['username'],
|
||||||
},
|
}, # /Author
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'links': {
|
'links': {
|
||||||
|
@ -111,19 +111,19 @@ BITBUCKET_WEBHOOK_PAYLOAD_SCHEMA = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'required': ['html'],
|
'required': ['html'],
|
||||||
},
|
}, # /Links
|
||||||
},
|
},
|
||||||
'required': ['hash', 'message', 'date'],
|
'required': ['hash', 'message', 'date'],
|
||||||
},
|
}, # /Target
|
||||||
},
|
},
|
||||||
'required': ['target'],
|
'required': ['name', 'target'],
|
||||||
},
|
}, # /New
|
||||||
},
|
},
|
||||||
},
|
}, # /Changes item
|
||||||
},
|
}, # /Changes
|
||||||
},
|
},
|
||||||
'required': ['changes'],
|
'required': ['changes'],
|
||||||
},
|
}, # / Push
|
||||||
},
|
},
|
||||||
'actor': {
|
'actor': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
|
@ -157,9 +157,9 @@ BITBUCKET_WEBHOOK_PAYLOAD_SCHEMA = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'required': ['username'],
|
'required': ['username'],
|
||||||
},
|
}, # /Actor
|
||||||
'required': ['push', 'repository'],
|
'required': ['push', 'repository'],
|
||||||
}
|
} # /Root
|
||||||
|
|
||||||
BITBUCKET_COMMIT_INFO_SCHEMA = {
|
BITBUCKET_COMMIT_INFO_SCHEMA = {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
|
@ -242,7 +242,7 @@ def get_transformed_webhook_payload(bb_payload, default_branch=None):
|
||||||
config['default_branch'] = default_branch
|
config['default_branch'] = default_branch
|
||||||
config['git_url'] = 'git@bitbucket.org:%s.git' % repository_name
|
config['git_url'] = 'git@bitbucket.org:%s.git' % repository_name
|
||||||
|
|
||||||
config['commit_info.url'] = target['links.html.href']
|
config['commit_info.url'] = target['links.html.href'] or ''
|
||||||
config['commit_info.message'] = target['message']
|
config['commit_info.message'] = target['message']
|
||||||
config['commit_info.date'] = target['date']
|
config['commit_info.date'] = target['date']
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from buildtrigger.test.bitbucketmock import get_bitbucket_trigger
|
from buildtrigger.test.bitbucketmock import get_bitbucket_trigger
|
||||||
|
from buildtrigger.triggerutil import (SkipRequestException, ValidationRequestException,
|
||||||
|
InvalidPayloadException)
|
||||||
|
from endpoints.building import PreparedBuild
|
||||||
|
from util.morecollections import AttrDict
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def bitbucket_trigger():
|
def bitbucket_trigger():
|
||||||
|
@ -20,3 +25,67 @@ def test_load_dockerfile_contents(subdir, contents):
|
||||||
trigger = get_bitbucket_trigger(subdir)
|
trigger = get_bitbucket_trigger(subdir)
|
||||||
assert trigger.load_dockerfile_contents() == contents
|
assert trigger.load_dockerfile_contents() == contents
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('payload, expected_error, expected_message', [
|
||||||
|
('{}', InvalidPayloadException, "'push' is a required property"),
|
||||||
|
|
||||||
|
# Valid payload:
|
||||||
|
('''{
|
||||||
|
"push": {
|
||||||
|
"changes": [{
|
||||||
|
"new": {
|
||||||
|
"name": "somechange",
|
||||||
|
"target": {
|
||||||
|
"hash": "aaaaaaa",
|
||||||
|
"message": "foo",
|
||||||
|
"date": "now",
|
||||||
|
"links": {
|
||||||
|
"html": {
|
||||||
|
"href": "somelink"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"full_name": "foo/bar"
|
||||||
|
}
|
||||||
|
}''', None, None),
|
||||||
|
|
||||||
|
# Skip message:
|
||||||
|
('''{
|
||||||
|
"push": {
|
||||||
|
"changes": [{
|
||||||
|
"new": {
|
||||||
|
"name": "somechange",
|
||||||
|
"target": {
|
||||||
|
"hash": "aaaaaaa",
|
||||||
|
"message": "[skip build] foo",
|
||||||
|
"date": "now",
|
||||||
|
"links": {
|
||||||
|
"html": {
|
||||||
|
"href": "somelink"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"full_name": "foo/bar"
|
||||||
|
}
|
||||||
|
}''', SkipRequestException, ''),
|
||||||
|
])
|
||||||
|
def test_handle_trigger_request(bitbucket_trigger, payload, expected_error, expected_message):
|
||||||
|
def get_payload():
|
||||||
|
return json.loads(payload)
|
||||||
|
|
||||||
|
request = AttrDict(dict(get_json=get_payload))
|
||||||
|
|
||||||
|
if expected_error is not None:
|
||||||
|
with pytest.raises(expected_error) as ipe:
|
||||||
|
bitbucket_trigger.handle_trigger_request(request)
|
||||||
|
assert ipe.value.message == expected_message
|
||||||
|
else:
|
||||||
|
assert isinstance(bitbucket_trigger.handle_trigger_request(request), PreparedBuild)
|
||||||
|
|
Reference in a new issue