From 80cb0cf6026ed75a64489bd5929ade6bbb620b91 Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Mon, 12 Apr 2021 22:53:11 -0400 Subject: [PATCH] Set up valid dxID --- stor/dx.py | 2 ++ stor/tests/test_dx.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/stor/dx.py b/stor/dx.py index abdb97dc..2ad28769 100644 --- a/stor/dx.py +++ b/stor/dx.py @@ -1210,6 +1210,8 @@ def canonical_resource(self): if utils.has_trailing_slash(self): raise ValueError('Invalid operation ({method}) on folder path ({path})' .format(path=self, method=sys._getframe(2).f_code.co_name)) + if utils.is_valid_dxid(self.resource, "file"): + return self.resource objects = [{ 'name': self.name, 'folder': ('/' + self.resource).parent, diff --git a/stor/tests/test_dx.py b/stor/tests/test_dx.py index 1a74c26e..471c3633 100644 --- a/stor/tests/test_dx.py +++ b/stor/tests/test_dx.py @@ -1960,3 +1960,17 @@ def test_content_type(self, mock_stat): self.assertEqual(DXPath('dx://P:/C/T').content_type, 'text/plain') mock_stat.return_value = {} self.assertEqual(DXPath('dx://P:/C/T').content_type, '') + + +class TestMixedPaths(DXTestCase): + def test_mixed_paths(self): + self.setup_temporary_project() + pth = stor.Path(f"dx://{self.project}:/mypath.txt") + with pth.open("w") as fp: + fp.write("sometext") + file_id = pth.canonical_path.name + project_id = pth.canonical_path.project + + assert stor.Path(f"dx://{project_id}:/{pth.name}").canonical_path == pth.canonical_path + assert stor.Path(f"dx://{project_id}:/{file_id}").canonical_path == pth.canonical_path + assert stor.Path(f"dx://{pth.project}:/{file_id}").canonical_path == pth.canonical_path