Skip to content

Commit 15bd58d

Browse files
[SHIP-793] Allow tags to be returned in File Importers (#504)
Depends on https://github.com/nludb/nludb/pull/600 Allow FileImporters to return tags in the RawDataPluginOutput. Co-authored-by: Enias Cailliau <hello@enias.ai>
1 parent 9ee5541 commit 15bd58d

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/steamship/plugin/outputs/raw_data_plugin_output.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

33
import io
4-
from typing import Any, Optional, Type, Union
4+
from typing import Any, List, Optional, Type, Union
55

66
from pydantic import BaseModel
77

8+
from steamship import Tag
89
from steamship.base import MimeTypes
910
from steamship.plugin.outputs.plugin_output import PluginOutput
1011
from steamship.utils.binary_utils import flexi_create
@@ -30,6 +31,7 @@ class RawDataPluginOutput(PluginOutput):
3031

3132
data: Optional[str] = None # Note: This is **always** Base64 encoded.
3233
mime_type: Optional[str] = None
34+
tags: Optional[List[Tag]] = None
3335

3436
def __init__(
3537
self,
@@ -38,10 +40,11 @@ def __init__(
3840
_bytes: Union[bytes, io.BytesIO] = None,
3941
json: Any = None,
4042
mime_type: str = None,
43+
tags: Optional[List[Tag]] = None,
4144
**kwargs,
4245
):
4346
super().__init__()
44-
47+
self.tags = tags
4548
if base64string is not None:
4649
self.data = base64string
4750
self.mime_type = mime_type or MimeTypes.BINARY

tests/assets/plugins/importers/plugin_file_importer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from steamship import MimeTypes
1+
from steamship import MimeTypes, Tag
22
from steamship.invocable import InvocableResponse, create_handler
33
from steamship.invocable.plugin_service import PluginRequest
44
from steamship.plugin.file_importer import FileImporter
@@ -18,7 +18,13 @@ class TestFileImporterPlugin(FileImporter):
1818
def run(
1919
self, request: PluginRequest[FileImportPluginInput]
2020
) -> InvocableResponse[RawDataPluginOutput]:
21-
return InvocableResponse(data=RawDataPluginOutput(string=TEST_DOC, mime_type=MimeTypes.MKD))
21+
return InvocableResponse(
22+
data=RawDataPluginOutput(
23+
string=TEST_DOC,
24+
mime_type=MimeTypes.MKD,
25+
tags=[Tag(kind="test-kind", name="test-name")],
26+
)
27+
)
2228

2329

2430
handler = create_handler(TestFileImporterPlugin)

tests/steamship_tests/plugin/integration/test_e2e_file_importer.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ def test_e2e_importer(client: Steamship):
1616
instance,
1717
):
1818
# The test FileImporter should always return a string file with contents TEST_DOC
19-
file = File.create_with_plugin(client=client, plugin_instance=instance.handle)
20-
file.wait()
21-
file = file.output
19+
file_task = File.create_with_plugin(client=client, plugin_instance=instance.handle)
20+
file = file_task.wait()
21+
22+
assert len(file.tags) == 1
23+
assert file.tags[0].kind == "test-kind"
24+
assert file.tags[0].name == "test-name"
25+
2226
# Now fetch the data from Steamship and assert that it is the SAME as the data the FileImporter creates
2327
data = file.raw()
2428
assert data.decode("utf-8") == TEST_DOC
2529

30+
fetched_file = File.get(client, _id=file.id)
31+
assert len(fetched_file.tags) == 1
32+
assert fetched_file.tags[0].kind == "test-kind"
33+
assert fetched_file.tags[0].name == "test-name"
34+
2635
file.delete()

0 commit comments

Comments
 (0)