Skip to content

Commit

Permalink
Add test for opener
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Dec 29, 2024
1 parent 2ed7485 commit 57ab0a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/pcloud/pcloudfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/pcloud/tests/test_pyfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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/"

0 comments on commit 57ab0a9

Please sign in to comment.