Skip to content

Commit 6c735b5

Browse files
committed
Test with secrets
1 parent 39d1739 commit 6c735b5

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from typing import Optional, Type
2+
3+
from steamship import Block, File
4+
from steamship.invocable import Config, InvocableResponse, create_handler
5+
from steamship.invocable.plugin_service import PluginRequest
6+
from steamship.plugin.blockifier.blockifier import Blockifier
7+
from steamship.plugin.inputs.raw_data_plugin_input import RawDataPluginInput
8+
from steamship.plugin.outputs.block_and_tag_plugin_output import BlockAndTagPluginOutput
9+
10+
# Note 1: this aligns with the same document in the internal Engine test.
11+
# Note 2: This should be duplicated from the test_importer because of the way our test system will
12+
# bundle this into an invocable deployment package (importing won't work!)
13+
HANDLE = "test-blockifier-plugin-v1"
14+
TEST_H1 = "A Poem"
15+
TEST_S1 = "Roses are red."
16+
TEST_S2 = "Violets are blue."
17+
TEST_S3 = "Sugar is sweet, and I love you."
18+
TEST_DOC = f"# {TEST_H1}\n\n{TEST_S1} {TEST_S2}\n\n{TEST_S3}\n"
19+
20+
21+
class DummyBlockifierPlugin(Blockifier):
22+
class DummyBlockifierConfig(Config):
23+
secret: Optional[str] = ""
24+
25+
config: DummyBlockifierConfig
26+
27+
@classmethod
28+
def config_cls(cls) -> Type[Config]:
29+
return cls.DummyBlockifierConfig
30+
31+
def run(
32+
self, request: PluginRequest[RawDataPluginInput]
33+
) -> InvocableResponse[BlockAndTagPluginOutput]:
34+
return InvocableResponse(
35+
data=BlockAndTagPluginOutput(
36+
file=File(
37+
blocks=[
38+
Block(
39+
text=self.config.secret,
40+
),
41+
]
42+
)
43+
)
44+
)
45+
46+
47+
handler = create_handler(DummyBlockifierPlugin)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from steamship_tests import PLUGINS_PATH
2+
from steamship_tests.utils.deployables import deploy_plugin
3+
from steamship_tests.utils.fixtures import get_steamship_client
4+
5+
from steamship import File
6+
7+
8+
def test_e2e_blockifier_plugin():
9+
client = get_steamship_client()
10+
blockifier_path = PLUGINS_PATH / "blockifiers" / "blockifier_with_secrets.py"
11+
with deploy_plugin(client, blockifier_path, "blockifier", secrets_toml='secret="FOO"') as (
12+
plugin,
13+
version,
14+
instance,
15+
):
16+
file = File.create(client=client, content="This is a test.")
17+
assert len(file.refresh().blocks) == 0
18+
file.blockify(plugin_instance=instance.handle).wait()
19+
file.refresh()
20+
assert len(file.blocks) == 1
21+
assert file.blocks[0].text == "FOO"
22+
file.delete()

tests/steamship_tests/utils/deployables.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from steamship.data.user import User
1616

1717

18-
def zip_deployable(file_path: Path, additional_requirements: Optional[List[str]] = None) -> bytes:
18+
def zip_deployable(
19+
file_path: Path,
20+
additional_requirements: Optional[List[str]] = None,
21+
secrets_toml: Optional[str] = None,
22+
) -> bytes:
1923
"""Prepare and zip a Steamship plugin."""
2024

2125
package_paths = [
@@ -42,6 +46,9 @@ def zip_deployable(file_path: Path, additional_requirements: Optional[List[str]]
4246
requirements_string += "\n" + "\n".join(additional_requirements)
4347
zip_file.writestr("requirements.txt", requirements_string)
4448

49+
if secrets_toml is not None:
50+
zip_file.writestr(".steamship/secrets.toml", secrets_toml)
51+
4552
# Now we'll copy in the whole assets directory so that our test files can access things there..
4653
for root, _, files in os.walk(TEST_ASSETS_PATH):
4754
for file in files:
@@ -65,6 +72,7 @@ def deploy_plugin(
6572
safe_load_handler: bool = False,
6673
wait_for_init: bool = True,
6774
streaming: Optional[bool] = None,
75+
secrets_toml: Optional[str] = None,
6876
):
6977
plugin = Plugin.create(
7078
client,
@@ -75,7 +83,7 @@ def deploy_plugin(
7583
is_public=False,
7684
)
7785

78-
zip_bytes = zip_deployable(py_path)
86+
zip_bytes = zip_deployable(py_path, secrets_toml=secrets_toml)
7987
hosting_handler = "steamship.invocable.entrypoint.safe_handler" if safe_load_handler else None
8088
plugin_version = PluginVersion.create(
8189
client,

0 commit comments

Comments
 (0)