Skip to content

Commit

Permalink
Fix dataset csv export resources formats (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
maudetes authored Oct 8, 2024
1 parent 93b5929 commit 24fcd5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion udata/core/dataset/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DatasetCsvAdapter(csv.Adapter):
("archived", lambda o: o.archived or False),
("resources_count", lambda o: len(o.resources)),
("main_resources_count", lambda o: len([r for r in o.resources if r.type == "main"])),
("resources_formats", lambda o: ",".join(set(r.format for r in o.resources))),
("resources_formats", lambda o: ",".join(set(r.format for r in o.resources if r.format))),
"downloads",
("harvest.backend", lambda r: r.harvest and r.harvest.backend),
("harvest.domain", lambda r: r.harvest and r.harvest.domain),
Expand Down
11 changes: 9 additions & 2 deletions udata/tests/dataset/test_csv_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ def test_datasets_csv_adapter(self):
"backend": "dummy_backend",
"modified_at": date_modified,
"created_at": date_created,
"remote_url": "https://www.example.com/",
},
)
resources_dataset = DatasetFactory(
resources=[
ResourceFactory(
metrics={
"views": 42,
}
},
format="csv",
type="main",
),
ResourceFactory(
metrics={
"views": 1337,
}
},
format="json",
),
ResourceFactory(),
]
Expand All @@ -81,9 +85,12 @@ def test_datasets_csv_adapter(self):
assert harvest_dataset_values["harvest.modified_at"] == date_modified.isoformat()
assert harvest_dataset_values["harvest.backend"] == "dummy_backend"
assert harvest_dataset_values["harvest.domain"] == "example.com"
assert harvest_dataset_values["harvest.remote_url"] == "https://www.example.com/"
assert harvest_dataset_values["resources_count"] == 0
assert harvest_dataset_values["downloads"] == 0

resources_dataset_values = csv[str(resources_dataset.id)]
assert resources_dataset_values["resources_count"] == 3
assert resources_dataset_values["main_resources_count"] == 1
assert set(resources_dataset_values["resources_formats"].split(",")) == set(["csv", "json"])
assert resources_dataset_values["downloads"] == 1337 + 42

0 comments on commit 24fcd5b

Please sign in to comment.