Skip to content

Commit

Permalink
Fix ProjectItemResource.path in case the resource's URL is None
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen committed Mar 1, 2024
1 parent e0d0f0b commit 49d3348
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions spine_engine/project_item/project_item_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ def url(self):
def url(self, url):
self._url = url
self._parsed_url = urlparse(self._url)
self._filepath = url2pathname(self._parsed_url.path)

@property
def path(self):
"""Returns the resource path in the local syntax, as obtained from parsing the url."""
if not self._filepath:
self._filepath = url2pathname(self._parsed_url.path)
self._filepath = url2pathname(self._parsed_url.path) if self._parsed_url.path else ""
return self._filepath

@property
Expand Down
11 changes: 11 additions & 0 deletions tests/project_item/test_project_item_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ def test_schema_is_stored_in_metadata(self):
resource = url_resource("project item", "sqlite:///path/do/db.sqlite", "my database", schema="my_schema")
self.assertEqual(resource.metadata, {"schema": "my_schema"})

def test_url_setter_works_when_url_is_set_to_none(self):
resource = url_resource("project item", "sqlite:///path/do/db.sqlite", "my database")
resource.url = None
self.assertIsNone(resource.url)


class TestTransientFileResource(unittest.TestCase):
def test_path_works_even_when_resource_has_no_url(self):
resource = transient_file_resource("Provider", "files@Provider")
self.assertEqual(resource.path, "")


class TestGetSource(unittest.TestCase):
def test_file_resource(self):
Expand Down

0 comments on commit 49d3348

Please sign in to comment.