Skip to content

Commit

Permalink
Use url for resource.path in CKAN
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Apr 19, 2024
1 parent 9414e10 commit 43620eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions dplib/plugins/ckan/models/__spec__/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def test_ckan_package_to_dp():
assert len(package.resources) == 9
assert len(package.keywords) == 8
assert len(package.contributors) == 2
assert package.resources[0].path == "sample-linked.csv"
assert (
package.resources[0].path
== "https://raw.githubusercontent.com/datopian/CKAN_Demo_Datasets/main/resources/org1_sample.csv"
)
assert package.keywords[0] == "csv"
assert package.contributors[0].title == "Test Author"
assert package.contributors[0].roles == ["author"]
Expand Down Expand Up @@ -59,7 +62,7 @@ def test_ckan_package_from_dp_round_trip():
assert package.license_id == "cc-by"
assert len(package.resources) == 9
assert len(package.tags) == 8
assert package.resources[0].name == "sample-linked.csv"
assert package.resources[0].name == "org1_sample.csv"
assert package.tags[0].name == "csv"


Expand Down
8 changes: 5 additions & 3 deletions dplib/plugins/ckan/models/resource.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from typing import Optional

from dplib.helpers.resource import slugify_name
Expand All @@ -10,6 +11,7 @@
class CkanResource(Model):
"""CKAN Resource model"""

url: str
name: str
created: Optional[str] = None
description: Optional[str] = None
Expand All @@ -30,7 +32,7 @@ def to_dp(self) -> Resource:
Data Resource
"""
# Path/Name
resource = Resource(path=self.name, name=slugify_name(self.name))
resource = Resource(path=self.url, name=slugify_name(self.name))

# Description
if self.description:
Expand Down Expand Up @@ -67,8 +69,8 @@ def from_dp(cls, resource: Resource) -> Optional[CkanResource]:
if not resource.path or not isinstance(resource.path, str):
return

# Path
ckan = CkanResource(name=resource.path)
# Path/Name
ckan = CkanResource(url=resource.path, name=os.path.basename(resource.path))

# Description
if resource.description:
Expand Down

0 comments on commit 43620eb

Please sign in to comment.