Skip to content

Commit

Permalink
add tests for ckan utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rshewitt committed Feb 6, 2024
1 parent 35c3079 commit 6977d3e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from harvester.ckan_utils import munge_tag, munge_title_to_name
import pytest

# these tests are copied from
# https://github.com/ckan/ckan/blob/master/ckan/tests/lib/test_munge.py


class TestCKANUtils:
@pytest.mark.parametrize(
"original,expected",
[
("unchanged", "unchanged"),
("s", "s_"), # too short
("some spaces here", "some-spaces--here"),
("random:other%characters&_.here", "randomothercharactershere"),
("river-water-dashes", "river-water-dashes"),
],
)
def test_munge_tag_multiple_pass(self, original, expected):
"""Munge a list of tags muliple times gives expected results."""

first_munge = munge_tag(original)
assert first_munge == expected
second_munge = munge_tag(first_munge)
assert second_munge == expected

@pytest.mark.parametrize(
"original,expected",
[
("unchanged", "unchanged"),
("some spaces here &here", "some-spaces-here-here"),
("s", "s_"), # too short
("random:other%character&", "random-othercharacter"),
("u with umlaut \xfc", "u-with-umlaut-u"),
("reallylong" * 12, "reallylong" * 9 + "reall"),
("reallylong" * 12 + " - 2012", "reallylong" * 9 + "-2012"),
(
"10cm - 50cm Near InfraRed (NI) Digital Aerial Photography (AfA142)",
"10cm-50cm-near-infrared-ni-digital-aerial-photography-afa142",
),
],
)
def test_munge_title_to_name(self, original, expected):
"""Munge a list of names gives expected results."""
munge = munge_title_to_name(original)
assert munge == expected

1 comment on commit 6977d3e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
harvester
   __init__.py00100% 
   ckan_utils.py4222 95%
   harvest.py4116767 84%
   utils.py4377 84%
TOTAL4967685% 

Tests Skipped Failures Errors Time
22 0 💤 0 ❌ 0 🔥 2.228s ⏱️

Please sign in to comment.