Skip to content

Commit

Permalink
Convert env dict to env_var list
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkindel committed Aug 28, 2024
1 parent c1ee9f6 commit 7073a43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit 7073a43

Please sign in to comment.