コード例 #1
0
    def test_show_pull_request(self):
        test_pr_id = 1
        test_project_id = 20
        test_repository_id = 25

        # set return values
        self.mock_get_credential.return_value = self._TEST_PAT_TOKEN
        self.mock_validate_token.return_value = True

        #big setup because this object is passed around
        pr_to_return = GitPullRequest()
        pr_to_return.pull_request_id = test_pr_id
        pr_to_return.repository = GitRepository()
        pr_to_return.repository.id = test_repository_id
        pr_to_return.repository.project = TeamProjectReference()
        pr_to_return.repository.project.id = test_project_id
        self.mock_get_PR_byId.return_value = pr_to_return

        response = show_pull_request(
            id=test_pr_id,
            open=False,
            organization=self._TEST_DEVOPS_ORGANIZATION,
            detect='off')

        #assert
        self.mock_get_PR_byId.assert_called_once_with(test_pr_id)
        self.mock_get_PR.assert_called_once_with(
            project=test_project_id,
            repository_id=test_repository_id,
            pull_request_id=test_pr_id,
            include_commits=False,
            include_work_item_refs=True)
コード例 #2
0
    def test_queue_pr_policy(self):
        test_pr_id = 1
        test_project_id = 20
        test_repository_id = 25

        # set return values
        self.mock_get_credential.return_value = self._TEST_PAT_TOKEN
        self.mock_validate_token.return_value = True

        #big setup because this object is passed around
        pr_to_return = GitPullRequest()
        pr_to_return.pull_request_id = test_pr_id
        pr_to_return.repository = GitRepository()
        pr_to_return.repository.id = test_repository_id
        pr_to_return.repository.project = TeamProjectReference()
        pr_to_return.repository.project.id = test_project_id
        self.mock_get_PR_byId.return_value = pr_to_return

        response = queue_pr_policy(id=1,
                                   evaluation_id=2,
                                   organization=self._TEST_DEVOPS_ORGANIZATION,
                                   detect='off')

        #assert
        self.mock_get_PR_byId.assert_called_once()
        self.mock_requeue_policy_evaluation.assert_called_once()
コード例 #3
0
    def test_create_pull_request_with_auto_complete(self):

        test_pr_id = 1
        merge_complete_message = 'merge complete message'

        # set return values
        self.mock_get_credential.return_value = self._TEST_PAT_TOKEN
        self.mock_validate_token.return_value = True

        #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,
            detect='off')

        # 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