Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive license matching #2378

Merged
merged 2 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fix new harvester's form tooltip showup [#2371](https://github.com/opendatateam/udata/pull/2371)
- Fix responsive design of search results [#2372](https://github.com/opendatateam/udata/pull/2372)
- Fix non-unique ids in datasets' comments [#2374](https://github.com/opendatateam/udata/pull/2374)
- Case insensitive license matching [#2378](https://github.com/opendatateam/udata/pull/2378)

## 1.6.18 (2019-12-13)

Expand Down
4 changes: 2 additions & 2 deletions udata/core/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def guess_one(cls, text):
text = text.strip().lower() # Stored identifiers are lower case
slug = cls.slug.slugify(text) # Use slug as it normalize string
license = qs(
db.Q(id=text) | db.Q(slug=slug) | db.Q(url=text)
| db.Q(alternate_urls=text)
db.Q(id__iexact=text) | db.Q(slug=slug) | db.Q(url__iexact=text)
| db.Q(alternate_urls__iexact=text)
).first()
if license is None:
# Try to single match with a low Damerau-Levenshtein distance
Expand Down
20 changes: 20 additions & 0 deletions udata/tests/dataset/test_dataset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ def test_exact_match_by_id(self):
assert isinstance(found, License)
assert license.id == found.id

def test_imatch_by_id(self):
license = LicenseFactory(id='CAPS-ID')
found = License.guess(license.id)
assert isinstance(found, License)
assert license.id == found.id

def test_exact_match_by_id_with_spaces(self):
license = LicenseFactory()
found = License.guess(' {0} '.format(license.id))
Expand All @@ -313,13 +319,27 @@ def test_exact_match_by_url(self):
assert isinstance(found, License)
assert license.id == found.id

def test_imatch_by_url(self):
url = '%s/CAPS.php' % faker.uri()
license = LicenseFactory(url=url)
found = License.guess(license.url)
assert isinstance(found, License)
assert license.id == found.id

def test_exact_match_by_alternate_url(self):
alternate_url = faker.uri()
license = LicenseFactory(alternate_urls=[alternate_url])
found = License.guess(alternate_url)
assert isinstance(found, License)
assert license.id == found.id

def test_imatch_by_alternate_url(self):
alternate_url = '%s/CAPS.php' % faker.uri()
license = LicenseFactory(alternate_urls=[alternate_url])
found = License.guess(alternate_url)
assert isinstance(found, License)
assert license.id == found.id

def test_exact_match_by_title(self):
license = LicenseFactory()
found = License.guess(license.title)
Expand Down