def test_create_pull_request(self): test_pr_id = 1 # set return values self.mock_validate_token.return_value = True self.mock_create_PR.return_value.id = test_pr_id response = create_pull_request( project=self._TEST_PROJECT_NAME, repository=self._TEST_REPOSITORY_NAME, source_branch=self._TEST_SOURCE_BRANCH, target_branch=self._TEST_TARGET_BRANCH, title=self._TEST_PR_TITLE, description=self._TEST_PR_DESCRIPTION, organization=self._TEST_DEVOPS_ORGANIZATION, detect='off') # assert self.mock_validate_token.assert_not_called() self.mock_create_PR.assert_called_once() self.mock_update_PR.assert_not_called() assert response.id == test_pr_id #compare the PR objects pr_object_from_create_call = self.mock_create_PR.call_args_list[0][1][ 'git_pull_request_to_create'] assert pr_object_from_create_call.title == self._TEST_PR_TITLE assert pr_object_from_create_call.description == '\n'.join( self._TEST_PR_DESCRIPTION) assert pr_object_from_create_call.source_ref_name == resolve_git_ref_heads( self._TEST_SOURCE_BRANCH) assert pr_object_from_create_call.target_ref_name == resolve_git_ref_heads( self._TEST_TARGET_BRANCH) assert pr_object_from_create_call.work_item_refs == None
def test_create_pull_request_with_auto_complete(self): test_pr_id = 1 merge_complete_message = 'merge complete message' #big setup because this object is passed around in create with auto complete flow pr_to_return = GitPullRequest() pr_to_return.pull_request_id = test_pr_id pr_to_return.repository = GitRepository() pr_to_return.repository.project = TeamProjectReference() self.mock_create_PR.return_value = pr_to_return self.mock_resolve_identity.return_value = 'resolved identity' response = create_pull_request( project=self._TEST_PROJECT_NAME, repository=self._TEST_REPOSITORY_NAME, source_branch=self._TEST_SOURCE_BRANCH, target_branch=self._TEST_TARGET_BRANCH, title=self._TEST_PR_TITLE, description=self._TEST_PR_DESCRIPTION, organization=self._TEST_DEVOPS_ORGANIZATION, auto_complete=True, merge_commit_message=merge_complete_message) # assert self.mock_create_PR.assert_called_once() self.mock_update_PR.assert_called_once() pr_id_from_udpate_call = self.mock_update_PR.call_args_list[0][1][ 'pull_request_id'] assert pr_id_from_udpate_call == test_pr_id update_object_from_update_call = self.mock_update_PR.call_args_list[0][ 1]['git_pull_request_to_update'] assert update_object_from_update_call.completion_options.merge_commit_message == merge_complete_message
def create_pull_request_azure_repo(organization, project, repository, source, target, message): from azext_devops.dev.repos.pull_request import create_pull_request pr = create_pull_request(project=project, repository=repository, source_branch=source, target_branch=target, title=message, description=['Creating Azure Pipeline for the repository.'], organization=organization) return pr