mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
webhooks/bitbucket2: Improve test coverage.
The lack of coverage was due to: * An unused function that was never used anywhere. * get_commit_status_changed_body was using a regex where it didn't really need to use one. And there was an if statement that assumed that the payload might NOT contain the URL to the commit. However, I checked the payload and there shouldn't be any instances where a commit event is generated but there is no URL to the commit. * get_push_tag_body had an `else` condition that really can't happen in any payload. I verified this by checking the BitBucket webhook docs.
This commit is contained in:
@@ -100,7 +100,6 @@ not_yet_fully_covered = {
|
|||||||
'zerver/data_import/gitter.py',
|
'zerver/data_import/gitter.py',
|
||||||
'zerver/data_import/import_util.py',
|
'zerver/data_import/import_util.py',
|
||||||
# Webhook integrations with incomplete coverage
|
# Webhook integrations with incomplete coverage
|
||||||
'zerver/webhooks/bitbucket2/view.py',
|
|
||||||
'zerver/webhooks/freshdesk/view.py',
|
'zerver/webhooks/freshdesk/view.py',
|
||||||
'zerver/webhooks/github/view.py',
|
'zerver/webhooks/github/view.py',
|
||||||
'zerver/webhooks/github_legacy/view.py',
|
'zerver/webhooks/github_legacy/view.py',
|
||||||
|
|||||||
@@ -226,13 +226,13 @@ def get_commit_comment_body(payload: Dict[str, Any]) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_commit_status_changed_body(payload: Dict[str, Any]) -> str:
|
def get_commit_status_changed_body(payload: Dict[str, Any]) -> str:
|
||||||
commit_id = re.match('.*/commit/(?P<commit_id>[A-Za-z0-9]*$)',
|
commit_api_url = payload['commit_status']['links']['commit']['href']
|
||||||
payload['commit_status']['links']['commit']['href'])
|
commit_id = commit_api_url.split('/')[-1]
|
||||||
if commit_id:
|
|
||||||
commit_info = "{}/{}".format(get_repository_url(payload['repository']),
|
commit_info = "{}/{}".format(
|
||||||
commit_id.group('commit_id'))
|
get_repository_url(payload['repository']),
|
||||||
else:
|
commit_id
|
||||||
commit_info = 'commit'
|
)
|
||||||
|
|
||||||
return BITBUCKET_COMMIT_STATUS_CHANGED_BODY.format(
|
return BITBUCKET_COMMIT_STATUS_CHANGED_BODY.format(
|
||||||
key=payload['commit_status']['key'],
|
key=payload['commit_status']['key'],
|
||||||
@@ -331,9 +331,7 @@ def get_push_tag_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str:
|
|||||||
elif change.get('closed'):
|
elif change.get('closed'):
|
||||||
tag = change['old']
|
tag = change['old']
|
||||||
action = 'removed'
|
action = 'removed'
|
||||||
else:
|
|
||||||
tag = change['new']
|
|
||||||
action = None
|
|
||||||
return get_push_tag_event_message(
|
return get_push_tag_event_message(
|
||||||
get_user_username(payload),
|
get_user_username(payload),
|
||||||
tag.get('name'),
|
tag.get('name'),
|
||||||
@@ -366,9 +364,6 @@ def get_repo_updated_body(payload: Dict[str, Any]) -> str:
|
|||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def get_pull_request_title(pullrequest_payload: Dict[str, Any]) -> str:
|
|
||||||
return pullrequest_payload['title']
|
|
||||||
|
|
||||||
def get_pull_request_url(pullrequest_payload: Dict[str, Any]) -> str:
|
def get_pull_request_url(pullrequest_payload: Dict[str, Any]) -> str:
|
||||||
return pullrequest_payload['links']['html']['href']
|
return pullrequest_payload['links']['html']['href']
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user