Esempio n. 1
0
    def test_delete_missing_happy_flow(self):
        self.os_mock.path.exists.return_value = False

        args = DeletePreviewCommand.Args(
            username="******",
            password="******",
            git_user="******",
            git_email="GIT_EMAIL",
            organisation="ORGA",
            repository_name="REPO",
            git_provider=GitProvider.GITHUB,
            git_provider_url=None,
            preview_id="PREVIEW_ID",
            expect_preview_exists=False,
        )
        DeletePreviewCommand(args).execute()
        assert self.mock_manager.method_calls == [
            call.load_gitops_config(args, "ORGA", "REPO"),
            call.GitRepoApiFactory.create(args, "PREVIEW_TARGET_ORG",
                                          "PREVIEW_TARGET_REPO"),
            call.GitRepo(self.git_repo_api_mock),
            call.GitRepo.clone("target-branch"),
            call.logging.info("Preview folder name: %s",
                              "app-685912d3-preview"),
            call.GitRepo.get_full_file_path("app-685912d3-preview"),
            call.os.path.exists("/tmp/created-tmp-dir/app-685912d3-preview"),
            call.logging.info(
                "No preview environment for '%s' and preview id '%s'. I'm done here.",
                "APP", "PREVIEW_ID"),
        ]
Esempio n. 2
0
 def test_delete_existing_happy_flow(self):
     args = DeletePreviewCommand.Args(
         username="******",
         password="******",
         git_user="******",
         git_email="GIT_EMAIL",
         organisation="ORGA",
         repository_name="REPO",
         git_provider=GitProvider.GITHUB,
         git_provider_url=None,
         preview_id="PREVIEW_ID",
         expect_preview_exists=False,
     )
     DeletePreviewCommand(args).execute()
     assert self.mock_manager.method_calls == [
         call.load_gitops_config(args, "ORGA", "REPO"),
         call.GitRepoApiFactory.create(args, "PREVIEW_TARGET_ORG",
                                       "PREVIEW_TARGET_REPO"),
         call.GitRepo(self.git_repo_api_mock),
         call.GitRepo.clone("target-branch"),
         call.logging.info("Preview folder name: %s",
                           "app-685912d3-preview"),
         call.GitRepo.get_full_file_path("app-685912d3-preview"),
         call.os.path.exists("/tmp/created-tmp-dir/app-685912d3-preview"),
         call.shutil.rmtree("/tmp/created-tmp-dir/app-685912d3-preview",
                            ignore_errors=True),
         call.GitRepo.commit(
             "GIT_USER", "GIT_EMAIL",
             "Delete preview environment for 'APP' and preview id 'PREVIEW_ID'."
         ),
         call.GitRepo.push(),
     ]
Esempio n. 3
0
    def test_delete_missing_but_expected_error(self):
        self.os_mock.path.exists.return_value = False

        args = DeletePreviewCommand.Args(
            username="******",
            password="******",
            git_user="******",
            git_email="GIT_EMAIL",
            organisation="ORGA",
            repository_name="REPO",
            git_provider=GitProvider.GITHUB,
            git_provider_url=None,
            preview_id="PREVIEW_ID",
            expect_preview_exists=True,  # we expect an existing preview
        )
        with pytest.raises(GitOpsException) as ex:
            DeletePreviewCommand(args).execute()
        self.assertEqual(
            str(ex.value),
            "There was no preview with name: app-685912d3-preview")

        assert self.mock_manager.method_calls == [
            call.load_gitops_config(args, "ORGA", "REPO"),
            call.GitRepoApiFactory.create(args, "PREVIEW_TARGET_ORG",
                                          "PREVIEW_TARGET_REPO"),
            call.GitRepo(self.git_repo_api_mock),
            call.GitRepo.clone("target-branch"),
            call.logging.info("Preview folder name: %s",
                              "app-685912d3-preview"),
            call.GitRepo.get_full_file_path("app-685912d3-preview"),
            call.os.path.exists("/tmp/created-tmp-dir/app-685912d3-preview"),
        ]
Esempio n. 4
0
    def test_missing_gitops_config_yaml_error(self):
        self.load_gitops_config_mock.side_effect = GitOpsException()

        args = DeletePreviewCommand.Args(
            username="******",
            password="******",
            git_user="******",
            git_email="GIT_EMAIL",
            organisation="ORGA",
            repository_name="REPO",
            git_provider=GitProvider.GITHUB,
            git_provider_url=None,
            preview_id="PREVIEW_ID",
            expect_preview_exists=True,  # we expect an existing preview
        )
        with pytest.raises(GitOpsException):
            DeletePreviewCommand(args).execute()
        assert self.mock_manager.method_calls == [
            call.load_gitops_config(args, "ORGA", "REPO"),
        ]