Ejemplo n.º 1
0
    def setUp(self):
        self.init_mock_manager(DeployCommand)

        self.update_yaml_file_mock = self.monkey_patch(update_yaml_file)
        self.update_yaml_file_mock.return_value = True

        self.logging_mock = self.monkey_patch(logging)
        self.logging_mock.info.return_value = None

        self.uuid_mock = self.monkey_patch(uuid)
        self.uuid_mock.uuid4.return_value = UUID(
            "b973b5bb-64a6-4735-a840-3113d531b41c")

        self.git_repo_api_mock = self.create_mock(GitRepoApi)
        self.git_repo_api_mock.create_pull_request_to_default_branch.return_value = GitRepoApi.PullRequestIdAndUrl(
            42, "<url of dummy pr>")
        self.git_repo_api_mock.merge_pull_request.return_value = None
        self.git_repo_api_mock.delete_branch.return_value = None

        self.git_repo_api_factory_mock = self.monkey_patch(GitRepoApiFactory)
        self.git_repo_api_factory_mock.create.return_value = self.git_repo_api_mock

        self.git_repo_mock = self.monkey_patch(GitRepo)
        self.git_repo_mock.return_value = self.git_repo_mock
        self.git_repo_mock.__enter__.return_value = self.git_repo_mock
        self.git_repo_mock.__exit__.return_value = False
        self.git_repo_mock.clone.return_value = None
        self.git_repo_mock.new_branch.return_value = None
        self.git_repo_mock.commit.return_value = None
        self.git_repo_mock.push.return_value = None
        self.git_repo_mock.get_full_file_path.side_effect = lambda x: f"/tmp/created-tmp-dir/{x}"

        self.seal_mocks()
    def test_create_pull_request_to_default_branch(self, logging_mock):
        expected_return_value = GitRepoApi.PullRequestIdAndUrl(42, "<url>")
        self.__mock_repo_api.create_pull_request_to_default_branch.return_value = expected_return_value

        actual_return_value = self.__testee.create_pull_request_to_default_branch(
            from_branch="<from branch>",
            title="<title>",
            description="<description>")

        self.assertEqual(actual_return_value, expected_return_value)
        self.__mock_repo_api.create_pull_request_to_default_branch.assert_called_once_with(
            "<from branch>", "<title>", "<description>")
        logging_mock.info.assert_called_once_with(
            "Creating pull request from '%s' to default branch with title: %s",
            "<from branch>",
            "<title>",
        )
Ejemplo n.º 3
0
    def setUp(self):
        self.init_mock_manager(DeletePreviewCommand)

        self.os_mock = self.monkey_patch(os)
        self.os_mock.path.exists.return_value = True

        self.shutil_mock = self.monkey_patch(shutil)
        self.shutil_mock.rmtree.return_value = None

        self.logging_mock = self.monkey_patch(logging)
        self.logging_mock.info.return_value = None

        self.load_gitops_config_mock = self.monkey_patch(load_gitops_config)
        self.load_gitops_config_mock.return_value = GitOpsConfig(
            api_version=0,
            application_name="APP",
            preview_host_template="www.foo.bar",
            preview_template_organisation="PREVIEW_TEMPLATE_ORG",
            preview_template_repository="PREVIEW_TEMPLATE_REPO",
            preview_template_path_template=".preview-templates/my-app",
            preview_template_branch="template-branch",
            preview_target_organisation="PREVIEW_TARGET_ORG",
            preview_target_repository="PREVIEW_TARGET_REPO",
            preview_target_branch="target-branch",
            preview_target_namespace_template="APP-${PREVIEW_ID_HASH}-preview",
            preview_target_max_namespace_length=50,
            replacements={},
        )

        self.git_repo_api_mock = self.create_mock(GitRepoApi)
        self.git_repo_api_mock.create_pull_request.return_value = GitRepoApi.PullRequestIdAndUrl(
            42, "<url of dummy pr>")

        self.git_repo_api_factory_mock = self.monkey_patch(GitRepoApiFactory)
        self.git_repo_api_factory_mock.create.return_value = self.git_repo_api_mock

        self.git_repo_mock = self.monkey_patch(GitRepo)
        self.git_repo_mock.return_value = self.git_repo_mock
        self.git_repo_mock.__enter__.return_value = self.git_repo_mock
        self.git_repo_mock.__exit__.return_value = False
        self.git_repo_mock.get_full_file_path.side_effect = lambda x: f"/tmp/created-tmp-dir/{x}"
        self.git_repo_mock.clone.return_value = None
        self.git_repo_mock.commit.return_value = None
        self.git_repo_mock.push.return_value = None

        self.seal_mocks()
Ejemplo n.º 4
0
    def setUp(self):
        self.init_mock_manager(DeletePreviewCommand)

        self.os_mock = self.monkey_patch(os)
        self.os_mock.path.exists.return_value = True

        self.shutil_mock = self.monkey_patch(shutil)
        self.shutil_mock.rmtree.return_value = None

        self.logging_mock = self.monkey_patch(logging)
        self.logging_mock.info.return_value = None

        self.load_gitops_config_mock = self.monkey_patch(load_gitops_config)
        self.load_gitops_config_mock.return_value = GitOpsConfig(
            application_name="APP",
            team_config_org="TEAM_CONFIG_ORG",
            team_config_repo="TEAM_CONFIG_REPO",
            route_host_template="www.foo.bar",
            replacements=[],
        )

        self.git_repo_api_mock = self.create_mock(GitRepoApi)
        self.git_repo_api_mock.create_pull_request.return_value = GitRepoApi.PullRequestIdAndUrl(
            42, "<url of dummy pr>")

        self.git_repo_api_factory_mock = self.monkey_patch(GitRepoApiFactory)
        self.git_repo_api_factory_mock.create.return_value = self.git_repo_api_mock

        self.git_repo_mock = self.monkey_patch(GitRepo)
        self.git_repo_mock.return_value = self.git_repo_mock
        self.git_repo_mock.__enter__.return_value = self.git_repo_mock
        self.git_repo_mock.__exit__.return_value = False
        self.git_repo_mock.get_full_file_path.side_effect = lambda x: f"/tmp/created-tmp-dir/{x}"
        self.git_repo_mock.clone.return_value = None
        self.git_repo_mock.commit.return_value = None
        self.git_repo_mock.push.return_value = None

        self.seal_mocks()