From 0d5344174fee90a3cdd5c3aa041171ff50111bae Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 21 May 2021 11:57:32 -0400 Subject: [PATCH 1/2] First integration test for put/get. --- integration/test_get_put.py | 51 +++++++++++++++++++++++++++++++++++++ newsfragments/3715.minor | 0 2 files changed, 51 insertions(+) create mode 100644 integration/test_get_put.py create mode 100644 newsfragments/3715.minor diff --git a/integration/test_get_put.py b/integration/test_get_put.py new file mode 100644 index 000000000..16df70d38 --- /dev/null +++ b/integration/test_get_put.py @@ -0,0 +1,51 @@ +""" +Integration tests for getting and putting files, including reading from stdin +and stdout. +""" + +from subprocess import Popen, PIPE + +import pytest + +from .util import run_in_thread, cli + +DATA = b"abc123 this is not utf-8 decodable \xff\x00\x33 \x11" +try: + DATA.decode("utf-8") +except UnicodeDecodeError: + pass # great, what we want +else: + raise ValueError("BUG, the DATA string was decoded from UTF-8") + + +@pytest.fixture(scope="session") +def get_put_alias(alice): + cli(alice, "create-alias", "getput") + + +def read_bytes(path): + with open(path, "rb") as f: + return f.read() + + +@run_in_thread +def test_put_from_stdin(alice, get_put_alias, tmpdir): + """ + It's possible to upload a file via `tahoe put`'s STDIN, and then download + it to a file. + """ + tempfile = str(tmpdir.join("file")) + p = Popen( + ["tahoe", "--node-directory", alice.node_dir, "put", "-", "getput:fromstdin"], + stdin=PIPE + ) + p.stdin.write(DATA) + p.stdin.close() + assert p.wait() == 0 + + cli(alice, "get", "getput:fromstdin", tempfile) + assert read_bytes(tempfile) == DATA + + +def test_get_from_stdin(): + pass diff --git a/newsfragments/3715.minor b/newsfragments/3715.minor new file mode 100644 index 000000000..e69de29bb From 6adda0c43a937fa35a41f3f1961680efd5f8413b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 21 May 2021 12:02:20 -0400 Subject: [PATCH 2/2] A second integration test for get/put. --- integration/test_get_put.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/integration/test_get_put.py b/integration/test_get_put.py index 16df70d38..bbdc363ea 100644 --- a/integration/test_get_put.py +++ b/integration/test_get_put.py @@ -47,5 +47,18 @@ def test_put_from_stdin(alice, get_put_alias, tmpdir): assert read_bytes(tempfile) == DATA -def test_get_from_stdin(): - pass +def test_get_to_stdout(alice, get_put_alias, tmpdir): + """ + It's possible to upload a file, and then download it to stdout. + """ + tempfile = tmpdir.join("file") + with tempfile.open("wb") as f: + f.write(DATA) + cli(alice, "put", str(tempfile), "getput:tostdout") + + p = Popen( + ["tahoe", "--node-directory", alice.node_dir, "get", "getput:tostdout", "-"], + stdout=PIPE + ) + assert p.stdout.read() == DATA + assert p.wait() == 0