From 7073a43729b4d7f6ab14fa4498b0154cfc2c538b Mon Sep 17 00:00:00 2001 From: cjkindel Date: Wed, 28 Aug 2024 14:42:31 -0700 Subject: [PATCH] Convert env dict to env_var list --- .../griptape_cloud_structure_run_driver.py | 4 +++- .../test_griptape_cloud_structure_run_driver.py | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/griptape/drivers/structure_run/griptape_cloud_structure_run_driver.py b/griptape/drivers/structure_run/griptape_cloud_structure_run_driver.py index a6e2064b6..46b54c528 100644 --- a/griptape/drivers/structure_run/griptape_cloud_structure_run_driver.py +++ b/griptape/drivers/structure_run/griptape_cloud_structure_run_driver.py @@ -28,9 +28,11 @@ def try_run(self, *args: BaseArtifact) -> BaseArtifact | InfoArtifact: url = urljoin(self.base_url.strip("/"), f"/api/structures/{self.structure_id}/runs") + env_vars = [{"name": key, "value": value, "source": "manual"} for key, value in self.env.items()] + response: Response = post( url, - json={"args": [arg.value for arg in args], "env": self.env}, + json={"args": [arg.value for arg in args], "env_vars": env_vars}, headers=self.headers, ) response.raise_for_status() diff --git a/tests/unit/drivers/structure_run/test_griptape_cloud_structure_run_driver.py b/tests/unit/drivers/structure_run/test_griptape_cloud_structure_run_driver.py index bdd5cd3ed..ccc8ac303 100644 --- a/tests/unit/drivers/structure_run/test_griptape_cloud_structure_run_driver.py +++ b/tests/unit/drivers/structure_run/test_griptape_cloud_structure_run_driver.py @@ -5,12 +5,14 @@ class TestGriptapeCloudStructureRunDriver: @pytest.fixture() - def driver(self, mocker): - from griptape.drivers import GriptapeCloudStructureRunDriver - + def mock_requests_post(self, mocker): mock_response = mocker.Mock() mock_response.json.return_value = {"structure_run_id": 1} - mocker.patch("requests.post", return_value=mock_response) + return mocker.patch("requests.post", return_value=mock_response) + + @pytest.fixture() + def driver(self, mocker, mock_requests_post): + from griptape.drivers import GriptapeCloudStructureRunDriver mock_response = mocker.Mock() mock_response.json.return_value = { @@ -24,10 +26,15 @@ def driver(self, mocker): base_url="https://cloud-foo.griptape.ai", api_key="foo bar", structure_id="1", env={"key": "value"} ) - def test_run(self, driver): + def test_run(self, driver, mock_requests_post): result = driver.run(TextArtifact("foo bar")) assert isinstance(result, TextArtifact) assert result.value == "foo bar" + mock_requests_post.assert_called_once_with( + "https://cloud-foo.griptape.ai/api/structures/1/runs", + json={"args": ["foo bar"], "env_vars": [{"name": "key", "value": "value", "source": "manual"}]}, + headers={"Authorization": "Bearer foo bar"}, + ) def test_async_run(self, driver): driver.async_run = True