Example #1
0
    def test_kube_kwargs_value_is_appended(self, monkeypatch):
        task = ListNamespacedJob(kube_kwargs={"test": "a"})

        config = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.job.config", config)

        batchapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.job.client",
            MagicMock(BatchV1Api=MagicMock(return_value=batchapi)),
        )

        task.run(kube_kwargs={"a": "test"})
        assert batchapi.list_namespaced_job.call_args[1]["a"] == "test"
        assert batchapi.list_namespaced_job.call_args[1]["test"] == "a"
Example #2
0
    def test_kube_config_out_of_cluster(self, monkeypatch):
        config = MagicMock()
        config.load_incluster_config.side_effect = ConfigException()
        monkeypatch.setattr("prefect.tasks.kubernetes.job.config", config)

        batchapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.job.client",
            MagicMock(BatchV1Api=MagicMock(return_value=batchapi)),
        )

        task = ListNamespacedJob(kube_kwargs={"test": "a"},
                                 kubernetes_api_key_secret=None)

        task.run(kube_kwargs={"test": "b"})
        assert config.load_kube_config.called
Example #3
0
 def test_filled_initialization(self, kube_secret):
     task = ListNamespacedJob(
         namespace="test",
         kube_kwargs={"test": "test"},
         kubernetes_api_key_secret="test",
     )
     assert task.namespace == "test"
     assert task.kube_kwargs == {"test": "test"}
     assert task.kubernetes_api_key_secret == "test"
Example #4
0
 def test_empty_initialization(self, kube_secret):
     task = ListNamespacedJob()
     assert task.namespace == "default"
     assert task.kube_kwargs == {}
     assert task.kubernetes_api_key_secret == "KUBERNETES_API_KEY"
Example #5
0
    def test_empty_kube_kwargs_value_is_updated(self, kube_secret, api_client):
        task = ListNamespacedJob()

        task.run(kube_kwargs={"test": "a"})
        assert api_client.list_namespaced_job.call_args[1]["test"] == "a"
Example #6
0
    def test_kube_kwargs_value_is_appended(self, kube_secret, api_client):
        task = ListNamespacedJob(kube_kwargs={"test": "a"})

        task.run(kube_kwargs={"a": "test"})
        assert api_client.list_namespaced_job.call_args[1]["a"] == "test"
        assert api_client.list_namespaced_job.call_args[1]["test"] == "a"