From 39a810d1e5cd1d587674597c75e73ac4c2fcf4a7 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Sun, 29 Dec 2024 13:07:11 +0100 Subject: [PATCH] Add test for opener --- src/pcloud/pcloudfs.py | 4 +--- src/pcloud/tests/test_pyfs.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pcloud/pcloudfs.py b/src/pcloud/pcloudfs.py index 403b8ab..4e286fa 100644 --- a/src/pcloud/pcloudfs.py +++ b/src/pcloud/pcloudfs.py @@ -397,11 +397,9 @@ class PCloudOpener(Opener): @staticmethod def open_fs(fs_url, parse_result, writeable, create, cwd): _, _, directory = parse_result.resource.partition("/") + endpoint = "api" if "+" in parse_result.protocol: _, endpoint = parse_result.protocol.split("+") - else: - endpoint = "api" - print(f"Endpoint: {endpoint}") fs = PCloudFS( username=parse_result.username, password=parse_result.password, diff --git a/src/pcloud/tests/test_pyfs.py b/src/pcloud/tests/test_pyfs.py index fdc7ed2..61cb10a 100644 --- a/src/pcloud/tests/test_pyfs.py +++ b/src/pcloud/tests/test_pyfs.py @@ -4,10 +4,13 @@ from fs import errors from fs.test import FSTestCases +from fs import opener from pcloud.pcloudfs import PCloudFS +from urllib.parse import quote class TestpCloudFS(FSTestCases, unittest.TestCase): + @classmethod def setUpClass(cls): username = os.environ.get("PCLOUD_USERNAME") @@ -68,3 +71,11 @@ def test_remove(self): error_msg = "resource 'foo/bar/egg/test.txt' not found" with self.assertRaisesRegex(errors.ResourceNotFound, error_msg): self.fs.remove("foo/bar/egg/test.txt") + + # Test custom functionality + + def test_fs_opener(self): + username = quote(os.environ.get("PCLOUD_USERNAME")) + password = os.environ.get("PCLOUD_PASSWORD") + with opener.open_fs(f"pcloud+eapi://{username}:{password}@/") as pcloud_fs: + assert pcloud_fs.pcloud.endpoint == "https://eapi.pcloud.com/"