コード例 #1
0
ファイル: test_deployment.py プロジェクト: zviri/prefect
    def test_kube_kwargs_value_is_replaced(self, kube_secret, api_client):
        task = CreateNamespacedDeployment(body={"test": "a"},
                                          kube_kwargs={"test": "a"})

        task.run(kube_kwargs={"test": "b"})
        assert api_client.create_namespaced_deployment.call_args[1][
            "test"] == "b"
コード例 #2
0
ファイル: test_deployment.py プロジェクト: zviri/prefect
    def test_empty_body_value_is_updated(self, kube_secret, api_client):
        task = CreateNamespacedDeployment()

        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(KUBERNETES_API_KEY="test_key")):
                task.run(body={"test": "a"})
        assert api_client.create_namespaced_deployment.call_args[1][
            "body"] == {
                "test": "a"
            }
コード例 #3
0
ファイル: test_deployment.py プロジェクト: zviri/prefect
    def test_body_value_is_appended(self, kube_secret, api_client):
        task = CreateNamespacedDeployment(body={"test": "a"})

        task.run(body={"a": "test"})

        assert api_client.create_namespaced_deployment.call_args[1][
            "body"] == {
                "a": "test",
                "test": "a",
            }
コード例 #4
0
    def test_api_key_pulled_from_secret(self, monkeypatch):
        task = CreateNamespacedDeployment(body={"test": "test"})
        client = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.deployment.client", client)

        conf_call = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.deployment.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
コード例 #5
0
ファイル: test_deployment.py プロジェクト: zh0uquan/prefect
    def test_api_key_pulled_from_secret(self, monkeypatch):
        task = CreateNamespacedDeployment(body={"test": "test"})
        client = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.deployment.client",
                            client)

        api_key = {}
        conf_call = MagicMock()
        conf_call.return_value.api_key = api_key
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.deployment.client.Configuration",
            conf_call)
        task.run()
        assert api_key == {"authorization": "test_key"}
コード例 #6
0
    def test_empty_kube_kwargs_value_is_updated(self, monkeypatch):
        task = CreateNamespacedDeployment(body={"test": "a"})

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

        extensionsapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.deployment.client",
            MagicMock(ExtensionsV1beta1Api=MagicMock(return_value=extensionsapi)),
        )

        task.run(kube_kwargs={"test": "a"})
        assert extensionsapi.create_namespaced_deployment.call_args[1]["test"] == "a"
コード例 #7
0
    def test_kube_config_in_cluster(self, monkeypatch):
        config = MagicMock()
        monkeypatch.setattr("prefect.tasks.kubernetes.deployment.config",
                            config)

        extensionsapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.deployment.client",
            MagicMock(ExtensionsV1beta1Api=MagicMock(
                return_value=extensionsapi)),
        )

        task = CreateNamespacedDeployment(body={"test": "a"},
                                          kubernetes_api_key_secret=None)

        task.run(body={"test": "b"})
        assert config.load_incluster_config.called
コード例 #8
0
ファイル: test_deployment.py プロジェクト: zh0uquan/prefect
    def test_empty_body_value_is_updated(self, monkeypatch):
        task = CreateNamespacedDeployment()

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

        extensionsapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.deployment.client",
            MagicMock(ExtensionsV1beta1Api=MagicMock(
                return_value=extensionsapi)),
        )

        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(KUBERNETES_API_KEY="test_key")):
                task.run(body={"test": "a"})
        assert extensionsapi.create_namespaced_deployment.call_args[1][
            "body"] == {
                "test": "a"
            }
コード例 #9
0
    def test_body_value_is_appended(self, monkeypatch, kube_secret):
        task = CreateNamespacedDeployment(body={"test": "a"})

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

        extensionsapi = MagicMock()
        monkeypatch.setattr(
            "prefect.tasks.kubernetes.deployment.client",
            MagicMock(ExtensionsV1beta1Api=MagicMock(
                return_value=extensionsapi)),
        )

        task.run(body={"a": "test"})

        assert extensionsapi.create_namespaced_deployment.call_args[1][
            "body"] == {
                "a": "test",
                "test": "a",
            }
コード例 #10
0
ファイル: test_deployment.py プロジェクト: zh0uquan/prefect
 def test_invalid_body_raises_error(self):
     task = CreateNamespacedDeployment()
     with pytest.raises(ValueError):
         task.run(body=None)
コード例 #11
0
ファイル: test_deployment.py プロジェクト: zh0uquan/prefect
 def test_empty_body_raises_error(self):
     task = CreateNamespacedDeployment()
     with pytest.raises(ValueError):
         task.run()