Skip to content

Commit

Permalink
SDK: add IO streams as raw content (#1736)
Browse files Browse the repository at this point in the history
* SDK: add IO streams as raw content

* Add test for export-import with a file
  • Loading branch information
jotare authored Jan 18, 2024
1 parent 7db59a7 commit 75bf4a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions nucliadb_sdk/nucliadb_sdk/tests/test_export_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from tempfile import NamedTemporaryFile
from uuid import uuid4

import pytest
Expand Down Expand Up @@ -54,6 +55,28 @@ def test_export_import_kb(src_kbid, dst_kbid, sdk: nucliadb_sdk.NucliaDB):
_check_kbs_are_equal(sdk, src_kbid, dst_kbid)


def test_export_import_with_files(src_kbid, dst_kbid, sdk: nucliadb_sdk.NucliaDB):
# Export src kb
resp = sdk.start_export(kbid=src_kbid)
export_id = resp.export_id
assert sdk.export_status(kbid=src_kbid, export_id=export_id).status == "finished"
export_generator = sdk.download_export(kbid=src_kbid, export_id=export_id)

# Store in a file
with NamedTemporaryFile() as f:
for chunk in export_generator():
f.write(chunk)

# Import to dst kb from a file
resp = sdk.start_import(kbid=dst_kbid, content=open(f.name, "rb"))
import_id = resp.import_id
assert (
sdk.import_status(kbid=dst_kbid, import_id=import_id).status == "finished"
)

_check_kbs_are_equal(sdk, src_kbid, dst_kbid)


async def test_export_import_kb_async(
src_kbid, dst_kbid, sdk, sdk_async: nucliadb_sdk.NucliaDB
):
Expand Down
1 change: 1 addition & 0 deletions nucliadb_sdk/nucliadb_sdk/v2/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def is_raw_request_content(content: Any) -> bool:
or isinstance(content, bytes)
or inspect.isgenerator(content)
or inspect.isasyncgen(content)
or isinstance(content, io.IOBase)
)


Expand Down

0 comments on commit 75bf4a5

Please sign in to comment.