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

Support deprecated licenses for download #606

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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