From 2ed3b46fad188bf4a1a22eadcee453f65d38425b Mon Sep 17 00:00:00 2001 From: Carmen Bianca Bakker Date: Wed, 12 Oct 2022 19:51:59 +0200 Subject: [PATCH] Support deprecated licenses for download Signed-off-by: Carmen Bianca Bakker --- CHANGELOG.md | 1 + src/reuse/download.py | 2 ++ tests/test_download.py | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index adc9cbcc1..d2a6a6a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/reuse/download.py b/src/reuse/download.py index 36bfdf523..5e17fb6ef 100644 --- a/src/reuse/download.py +++ b/src/reuse/download.py @@ -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? diff --git a/tests/test_download.py b/tests/test_download.py index b9fab17ba..b53e39358 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -5,6 +5,7 @@ """All tests for reuse.download""" from pathlib import Path +from unittest.mock import MagicMock import pytest import requests @@ -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))