mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +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/import_util.py',
 | 
			
		||||
    # Webhook integrations with incomplete coverage
 | 
			
		||||
    'zerver/webhooks/bitbucket2/view.py',
 | 
			
		||||
    'zerver/webhooks/freshdesk/view.py',
 | 
			
		||||
    'zerver/webhooks/github/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:
 | 
			
		||||
    commit_id = re.match('.*/commit/(?P<commit_id>[A-Za-z0-9]*$)',
 | 
			
		||||
                         payload['commit_status']['links']['commit']['href'])
 | 
			
		||||
    if commit_id:
 | 
			
		||||
        commit_info = "{}/{}".format(get_repository_url(payload['repository']),
 | 
			
		||||
                                     commit_id.group('commit_id'))
 | 
			
		||||
    else:
 | 
			
		||||
        commit_info = 'commit'
 | 
			
		||||
    commit_api_url = payload['commit_status']['links']['commit']['href']
 | 
			
		||||
    commit_id = commit_api_url.split('/')[-1]
 | 
			
		||||
 | 
			
		||||
    commit_info = "{}/{}".format(
 | 
			
		||||
        get_repository_url(payload['repository']),
 | 
			
		||||
        commit_id
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    return BITBUCKET_COMMIT_STATUS_CHANGED_BODY.format(
 | 
			
		||||
        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'):
 | 
			
		||||
        tag = change['old']
 | 
			
		||||
        action = 'removed'
 | 
			
		||||
    else:
 | 
			
		||||
        tag = change['new']
 | 
			
		||||
        action = None
 | 
			
		||||
 | 
			
		||||
    return get_push_tag_event_message(
 | 
			
		||||
        get_user_username(payload),
 | 
			
		||||
        tag.get('name'),
 | 
			
		||||
@@ -366,9 +364,6 @@ def get_repo_updated_body(payload: Dict[str, Any]) -> str:
 | 
			
		||||
 | 
			
		||||
    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:
 | 
			
		||||
    return pullrequest_payload['links']['html']['href']
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user