def test_empty_body_value_is_updated(self, kube_secret, api_client): task = CreateNamespacedPod() task.run(body={"test": "a"}) assert api_client.create_namespaced_pod.call_args[1]["body"] == { "test": "a" }
def test_kube_kwargs_value_is_appended(self, kube_secret, api_client): task = CreateNamespacedPod(body={"test": "a"}, kube_kwargs={"test": "a"}) task.run(kube_kwargs={"a": "test"}) assert api_client.create_namespaced_pod.call_args[1]["a"] == "test" assert api_client.create_namespaced_pod.call_args[1]["test"] == "a"
def test_body_value_is_appended(self, kube_secret, api_client): task = CreateNamespacedPod(body={"test": "a"}) task.run(body={"a": "test"}) assert api_client.create_namespaced_pod.call_args[1]["body"] == { "a": "test", "test": "a", }
def test_api_key_pulled_from_secret(self, monkeypatch): task = CreateNamespacedPod(body={"test": "test"}) client = MagicMock() monkeypatch.setattr("prefect.tasks.kubernetes.pod.client", client) conf_call = MagicMock() monkeypatch.setattr( "prefect.tasks.kubernetes.pod.client.Configuration", conf_call) with set_temporary_config({"cloud.use_local_secrets": True}): with prefect.context(secrets=dict(KUBERNETES_API_KEY="test_key")): task.run() assert conf_call.called
def test_api_key_pulled_from_secret(self, monkeypatch): task = CreateNamespacedPod(body={"test": "test"}) client = MagicMock() monkeypatch.setattr("prefect.tasks.kubernetes.pod.client", client) api_key = {} conf_call = MagicMock() conf_call.return_value.api_key = api_key monkeypatch.setattr( "prefect.tasks.kubernetes.pod.client.Configuration", conf_call) task.run() assert api_key == {"authorization": "test_key"}
def test_empty_kube_kwargs_value_is_updated(self, monkeypatch): task = CreateNamespacedPod(body={"test": "a"}) config = MagicMock() monkeypatch.setattr("prefect.tasks.kubernetes.pod.config", config) coreapi = MagicMock() monkeypatch.setattr( "prefect.tasks.kubernetes.pod.client", MagicMock(CoreV1Api=MagicMock(return_value=coreapi)), ) task.run(kube_kwargs={"test": "a"}) assert coreapi.create_namespaced_pod.call_args[1]["test"] == "a"
def test_body_value_is_replaced(self, monkeypatch, kube_secret): task = CreateNamespacedPod(body={"test": "a"}) config = MagicMock() monkeypatch.setattr("prefect.tasks.kubernetes.pod.config", config) coreapi = MagicMock() monkeypatch.setattr( "prefect.tasks.kubernetes.pod.client", MagicMock(CoreV1Api=MagicMock(return_value=coreapi)), ) task.run(body={"test": "b"}) assert coreapi.create_namespaced_pod.call_args[1]["body"] == {"test": "b"}
def test_kube_config_in_cluster(self, monkeypatch): config = MagicMock() monkeypatch.setattr("prefect.tasks.kubernetes.pod.config", config) coreapi = MagicMock() monkeypatch.setattr( "prefect.tasks.kubernetes.pod.client", MagicMock(CoreV1Api=MagicMock(return_value=coreapi)), ) task = CreateNamespacedPod(body={"test": "a"}, kubernetes_api_key_secret=None) task.run(body={"test": "b"}) assert config.load_incluster_config.called
def test_invalid_body_raises_error(self): task = CreateNamespacedPod() with pytest.raises(ValueError): task.run(body=None)
def test_empty_body_raises_error(self): task = CreateNamespacedPod() with pytest.raises(ValueError): task.run()