Add unit testing of gitlab trigger handler

This commit is contained in:
Joseph Schorr 2017-02-13 17:42:37 -05:00
parent 84b298f36b
commit 57528aa2bc
4 changed files with 287 additions and 7 deletions

View file

@ -48,6 +48,9 @@ GITLAB_WEBHOOK_PAYLOAD_SCHEMA = {
'items': {
'type': 'object',
'properties': {
'id': {
'type': 'string',
},
'url': {
'type': 'string',
},
@ -67,7 +70,7 @@ GITLAB_WEBHOOK_PAYLOAD_SCHEMA = {
'required': ['email'],
},
},
'required': ['url', 'message', 'timestamp'],
'required': ['id', 'url', 'message', 'timestamp'],
},
},
},
@ -282,7 +285,8 @@ class GitLabBuildTrigger(BuildTriggerHandler):
'id': namespace['path'],
'title': namespace['name'],
'avatar_url': repo['owner']['avatar_url'],
'score': 0,
'score': 1,
'url': gl_client.host + '/' + namespace['path'],
}
return list(namespaces.values())
@ -486,18 +490,18 @@ class GitLabBuildTrigger(BuildTriggerHandler):
def get_tag_sha(tag_name):
tags = gl_client.getrepositorytags(repo['id'])
if tags is False:
raise TriggerStartException('Could not find tags')
raise TriggerStartException('Could not find tag in repository')
for tag in tags:
if tag['name'] == tag_name:
return tag['commit']['id']
raise TriggerStartException('Could not find commit')
raise TriggerStartException('Could not find tag in repository')
def get_branch_sha(branch_name):
branch = gl_client.getbranch(repo['id'], branch_name)
if branch is False:
raise TriggerStartException('Could not find branch')
raise TriggerStartException('Could not find branch in repository')
return branch['commit']['id']