Skip to content

Commit

Permalink
Correctly handle (lack of) pluralization in license_file upload data (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin authored Nov 18, 2024
1 parent 3a3e946 commit 6d1f9aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4792,8 +4792,8 @@ def test_upload_succeeds_creates_release_metadata_2_4(
db_request.POST.extend(
[
("license_expression", "MIT OR Apache-2.0"),
("license_files", "LICENSE.APACHE"),
("license_files", "LICENSE.MIT"),
("license_file", "LICENSE.APACHE"),
("license_file", "LICENSE.MIT"),
]
)
if filetype == "bdist_wheel":
Expand Down Expand Up @@ -4900,8 +4900,8 @@ def test_upload_fails_missing_license_file_metadata_2_4(
db_request.POST.extend(
[
("license_expression", "MIT OR Apache-2.0"),
("license_files", "LICENSE"), # Does not exist in test data
("license_files", "LICENSE.MIT"),
("license_file", "LICENSE"), # Does not exist in test data
("license_file", "LICENSE.MIT"),
]
)
if filetype == "bdist_wheel":
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/forklift/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,27 @@ def _assert_invalid_metadata(exc, field):

class TestParse:
def test_valid_from_file(self):
meta = metadata.parse(b"Metadata-Version: 2.1\nName: foo\nVersion: 1.0\n")
meta = metadata.parse(
b"Metadata-Version: 2.4\nName: foo\nVersion: 1.0\n"
b"License-File: Something\nLicense-File: Something Else\n"
)
assert meta.name == "foo"
assert meta.version == Version("1.0")
assert meta.license_files == [
"Something",
"Something Else",
]

def test_valid_from_form(self):
data = MultiDict(metadata_version="2.1", name="spam", version="2.0")
data = MultiDict(metadata_version="2.4", name="spam", version="2.0")
data.extend([("license_file", "Something"), ("license_file", "Something Else")])
meta = metadata.parse(None, form_data=data)
assert meta.name == "spam"
assert meta.version == Version("2.0")
assert meta.license_files == [
"Something",
"Something Else",
]

def test_invalid_no_data(self):
with pytest.raises(metadata.NoMetadataError):
Expand Down
1 change: 1 addition & 0 deletions warehouse/forklift/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def _validate_metadata(metadata: Metadata, *, backfill: bool = False):
_override = {
"platforms": "platform",
"supported_platforms": "supported_platform",
"license_files": "license_file",
}
_FORM_TO_RAW_MAPPING = {_override.get(k, k): k for k in _RAW_TO_EMAIL_MAPPING}

Expand Down

0 comments on commit 6d1f9aa

Please sign in to comment.