Skip to content

Commit

Permalink
Support deprecated licenses for download
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca Bakker <[email protected]>
  • Loading branch information
carmenbianca committed Oct 12, 2022
1 parent 3450858 commit 2ed3b46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The versions follow [semantic versioning](https://semver.org).
### Fixed

- Sanitize xargs input in scripts documentation
- Support deprecated licences for `reuse download`. (#606)
- License identifiers in comments with symmetrical ASCII art frames are now
properly detected (#560)
- Fixed an error where copyright statements contained within a multi-line
Expand Down
2 changes: 2 additions & 0 deletions src/reuse/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def download_license(spdx_identifier: str) -> str:
:raises requests.RequestException: if the license could not be downloaded.
:return: The license text.
"""
if spdx_identifier not in ALL_NON_DEPRECATED_MAP:
spdx_identifier = f"deprecated_{spdx_identifier}"
# This is fairly naive, but I can't see anything wrong with it.
url = urljoin(_SPDX_REPOSITORY_BASE_URL, "".join((spdx_identifier, ".txt")))
# TODO: Cache result?
Expand Down
9 changes: 9 additions & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""All tests for reuse.download"""

from pathlib import Path
from unittest.mock import MagicMock

import pytest
import requests
Expand Down Expand Up @@ -49,6 +50,14 @@ def raise_exception(_):
download_license("hello world")


def test_download_deprecated(monkeypatch):
"""Adjust the requested file for deprecated licenses."""
mocked = MagicMock(return_value=MockResponse("hello", 200))
monkeypatch.setattr(requests, "get", mocked)
download_license("GPL-3.0")
assert "deprecated_GPL-3.0" in mocked.call_args[0][0]


def test_put_simple(fake_repository, monkeypatch):
"""Straightforward test."""
monkeypatch.setattr(requests, "get", lambda _: MockResponse("hello\n", 200))
Expand Down

0 comments on commit 2ed3b46

Please sign in to comment.