Exemplo n.º 1
0
def test_store_upload(tmpdir):
    with run_background_server(tmpdir, 55556) as srv:

        # register user
        srv.app.create_account("test_account", "password")

        base_url = "http://localhost:55556"

        assert client.list_public_files(base_url) == dict()

        # list public files of test_account
        assert client.list_files(base_url, "test_account", "") == dict()

        # upload public file
        data = StringIO.StringIO(
            "abc123abccdd")  # cStringIO for upload does not work !

        client.upload_file(base_url, "test_account", "password", "/abc.txt",
                           data)
        assert client.list_files(base_url, "test_account", "/") == {
            'abc.txt': "/test_account/abc.txt"
        }

        client.download_file(base_url, "test_account/abc.txt", tmpdir.strpath)
        tmp_file_path = tmpdir.join("abc.txt").strpath
        assert open(tmp_file_path, "r").read() == data.getvalue()

        # upload hidden file
        data = StringIO.StringIO("abc123abccdd")

        client.upload_file(base_url, "test_account", "password",
                           "/hidden/abcd.txt", data)
        cl = client.list_files
        assert cl(base_url, "test_account", "/") == {
            "abc.txt": "/test_account/abc.txt"
        }
        assert cl(base_url, "test_account", "/hidden") == {
            "abcd.txt": "/test_account/hidden/abcd.txt"
        }

        client.download_file(base_url, "test_account/hidden/abcd.txt",
                             tmpdir.strpath)
        tmp_file_path = tmpdir.join("abcd.txt").strpath
        assert open(tmp_file_path, "r").read() == data.getvalue()

        # list all public files
        assert client.list_public_files(base_url) == {
            'abc.txt': "/test_account/abc.txt"
        }

        # delete file
        client.delete_file(base_url, "test_account", "password",
                           "/hidden/abcd.txt")
        assert client.list_files(base_url, "test_account", "/hidden") == dict()
Exemplo n.º 2
0
def test_store_upload(tmpdir):
    with run_background_server(tmpdir, 55556) as srv:

        # register user
        srv.app.create_account("test_account", "password")

        base_url = "http://localhost:55556"

        assert client.list_public_files(base_url) == dict()

        # list public files of test_account
        assert client.list_files(base_url, "test_account", "") == dict()

        # upload public file
        data = StringIO.StringIO("abc123abccdd")  # cStringIO for upload does not work !

        client.upload_file(base_url, "test_account", "password", "/abc.txt", data)
        assert client.list_files(base_url, "test_account", "/") == {'abc.txt': "/test_account/abc.txt"}

        client.download_file(base_url, "test_account/abc.txt", tmpdir.strpath)
        tmp_file_path = tmpdir.join("abc.txt").strpath
        assert open(tmp_file_path, "r").read() == data.getvalue()

        # upload hidden file
        data = StringIO.StringIO("abc123abccdd")

        client.upload_file(base_url, "test_account", "password", "/hidden/abcd.txt", data)
        cl = client.list_files
        assert cl(base_url, "test_account", "/") == {"abc.txt": "/test_account/abc.txt"}
        assert cl(base_url, "test_account", "/hidden") == {"abcd.txt": "/test_account/hidden/abcd.txt"}

        client.download_file(base_url, "test_account/hidden/abcd.txt", tmpdir.strpath)
        tmp_file_path = tmpdir.join("abcd.txt").strpath
        assert open(tmp_file_path, "r").read() == data.getvalue()

        # list all public files
        assert client.list_public_files(base_url) == {'abc.txt': "/test_account/abc.txt"}

        # delete file
        client.delete_file(base_url, "test_account", "password", "/hidden/abcd.txt")
        assert client.list_files(base_url, "test_account", "/hidden") == dict()
Exemplo n.º 3
0
        data = StringIO.StringIO()  # empty file

        # register user
        srv.app.create_account("test_account", "password")

        # wrong pw
        with expect(401):
            client.upload_file(base_url, "test_account", "false_password",
                               "/abcd.txt", data)

        # wrong account
        with expect(401):
            client.upload_file(base_url, "none_exisiting_account",
                               "false_password", "/abcd.txt", data)

        # delete non existing
        with expect(404):
            client.delete_file(base_url, "test_account", "password",
                               "/abcd.txt")

        # download non existing
        with expect(404):
            client.download_file(base_url, "test_account", "abcd.txt",
                                 tmpdir.strpath)

        client.upload_file(base_url, "test_account", "password", "/abcd.txt",
                           data)
        with expect(409):
            client.upload_file(base_url, "test_account", "password",
                               "/abcd.txt", data)
Exemplo n.º 4
0
        raise Exception("expected HTTPError(%d)" % status_code)

    with run_background_server(tmpdir, 55557) as srv:

        base_url = "http://localhost:55557"
        data = StringIO.StringIO()  # empty file

        # register user
        srv.app.create_account("test_account", "password")

        # wrong pw
        with expect(401):
            client.upload_file(base_url, "test_account", "false_password", "/abcd.txt", data)

        # wrong account
        with expect(401):
            client.upload_file(base_url, "none_exisiting_account", "false_password", "/abcd.txt",
                               data)

        # delete non existing
        with expect(404):
            client.delete_file(base_url, "test_account", "password", "/abcd.txt")

        # download non existing
        with expect(404):
            client.download_file(base_url, "test_account", "abcd.txt", tmpdir.strpath)

        client.upload_file(base_url, "test_account", "password", "/abcd.txt", data)
        with expect(409):
            client.upload_file(base_url, "test_account", "password", "/abcd.txt", data)