Esempio n. 1
0
    def test_kube_kwargs_value_is_appended(self, kube_secret, api_client):
        task = ReadNamespacedService(service_name="test",
                                     kube_kwargs={"test": "a"})

        task.run(kube_kwargs={"a": "test"})
        assert api_client.read_namespaced_service.call_args[1]["a"] == "test"
        assert api_client.read_namespaced_service.call_args[1]["test"] == "a"
Esempio n. 2
0
    def test_api_key_pulled_from_secret(self, monkeypatch):
        task = ReadNamespacedService(service_name="test")
        client = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.service.client", client)

        api_key = {}
        conf_call = MagicMock()
        conf_call.return_value.api_key = api_key
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.service.client.Configuration", conf_call)
        task.run()
        assert api_key == {"authorization": "test_key"}
Esempio n. 3
0
    def test_api_key_pulled_from_secret(self, monkeypatch):
        task = ReadNamespacedService(service_name="test")
        client = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.service.client", client)

        conf_call = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.service.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
Esempio n. 4
0
    def test_empty_kube_kwargs_value_is_updated(self, monkeypatch):
        task = ReadNamespacedService(service_name="test")

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

        coreapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.service.client",
            MagicMock(CoreV1Api=MagicMock(return_value=coreapi)),
        )

        task.run(kube_kwargs={"test": "a"})
        assert coreapi.read_namespaced_service.call_args[1]["test"] == "a"
Esempio n. 5
0
 def test_invalid_body_raises_error(self):
     task = ReadNamespacedService()
     with pytest.raises(ValueError):
         task.run(service_name=None)
Esempio n. 6
0
 def test_empty_name_raises_error(self):
     task = ReadNamespacedService()
     with pytest.raises(ValueError):
         task.run()
Esempio n. 7
0
    def test_empty_kube_kwargs_value_is_updated(self, kube_secret, api_client):
        task = ReadNamespacedService(service_name="test")

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