예제 #1
0
    def test_download_and_save_lib(self, mock_osclients, mock_requests):

        mock_requests.get.content.return_value = "some_binary_content"
        mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
        mock_sahara.job_binary_internals.create.return_value = (
            mock.MagicMock(id=42))

        sahara_ctx = sahara_job_binaries.SaharaJobBinaries(self.context)

        sahara_ctx.context["tenants"]["0"]["sahara"] = {"mains": []}
        sahara_ctx.context["tenants"]["0"]["sahara"]["libs"] = []

        sahara_ctx.download_and_save_lib(sahara=mock_sahara,
                                         lib_type="mains",
                                         name="test_binary",
                                         download_url="http://somewhere",
                                         tenant_id="0")

        sahara_ctx.download_and_save_lib(sahara=mock_sahara,
                                         lib_type="libs",
                                         name="test_binary_2",
                                         download_url="http://somewhere",
                                         tenant_id="0")

        mock_requests.get.assert_called_once_with("http://somewhere")
예제 #2
0
    def test_setup_and_cleanup(self, mock_osclients,
                               mock_sahara_job_binaries_download_and_save_lib,
                               mock_cleanup):

        mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()

        sahara_ctx = sahara_job_binaries.SaharaJobBinaries(self.context)

        download_calls = []

        for i in range(self.tenants_num):
            download_calls.append(
                mock.call(sahara=mock_sahara,
                          lib_type="mains",
                          name="test.jar",
                          download_url="http://example.com/test.jar",
                          tenant_id=str(i)))
            download_calls.append(
                mock.call(sahara=mock_sahara,
                          lib_type="libs",
                          name="test.jar",
                          download_url="http://example.com/test.jar",
                          tenant_id=str(i)))

        sahara_ctx.setup()

        (mock_sahara_job_binaries_download_and_save_lib.assert_has_calls(
            download_calls))

        sahara_ctx.cleanup()

        mock_cleanup.assert_called_once_with(
            names=["sahara.job_binary_internals", "sahara.job_binaries"],
            users=self.context["users"])