-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use packaging.metadata to parse and validate upload metadata (#14718)
* Use packaging.metadata to parse/validate the metadata * Use a temporary fork of packaging * Linting * requires_python is already special-cased * Bump supported metadata versions * Small normalization change in requires_dist output * Source our _FORM_TO_RAW_MAPPING from packaging * Normalize dynamic values --------- Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
1,023 additions
and
1,017 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import pretend | ||
import pytest | ||
|
||
from webob.multidict import MultiDict | ||
from wtforms.validators import ValidationError | ||
|
||
from warehouse.forklift.forms import UploadForm, _validate_pep440_version | ||
|
||
|
||
class TestValidation: | ||
@pytest.mark.parametrize("version", ["1.0", "30a1", "1!1", "1.0-1", "v1.0"]) | ||
def test_validates_valid_pep440_version(self, version): | ||
form, field = pretend.stub(), pretend.stub(data=version) | ||
_validate_pep440_version(form, field) | ||
|
||
@pytest.mark.parametrize("version", ["dog", "1.0.dev.a1"]) | ||
def test_validates_invalid_pep440_version(self, version): | ||
form, field = pretend.stub(), pretend.stub(data=version) | ||
with pytest.raises(ValidationError): | ||
_validate_pep440_version(form, field) | ||
|
||
|
||
class TestUploadForm: | ||
@pytest.mark.parametrize( | ||
"data", | ||
[ | ||
# Test for singular supported digests | ||
{"filetype": "sdist", "md5_digest": "bad"}, | ||
{"filetype": "bdist_wheel", "pyversion": "3.4", "md5_digest": "bad"}, | ||
{"filetype": "sdist", "sha256_digest": "bad"}, | ||
{"filetype": "bdist_wheel", "pyversion": "3.4", "sha256_digest": "bad"}, | ||
{"filetype": "sdist", "blake2_256_digest": "bad"}, | ||
{"filetype": "bdist_wheel", "pyversion": "3.4", "blake2_256_digest": "bad"}, | ||
# Tests for multiple digests passing through | ||
{ | ||
"filetype": "sdist", | ||
"md5_digest": "bad", | ||
"sha256_digest": "bad", | ||
"blake2_256_digest": "bad", | ||
}, | ||
{ | ||
"filetype": "bdist_wheel", | ||
"pyversion": "3.4", | ||
"md5_digest": "bad", | ||
"sha256_digest": "bad", | ||
"blake2_256_digest": "bad", | ||
}, | ||
], | ||
) | ||
def test_full_validate_valid(self, data): | ||
form = UploadForm(MultiDict(data)) | ||
form.full_validate() | ||
|
||
@pytest.mark.parametrize( | ||
"data", | ||
[ | ||
{"filetype": "sdist", "pyversion": "3.4"}, | ||
{"filetype": "bdist_wheel"}, | ||
{"filetype": "bdist_wheel", "pyversion": "3.4"}, | ||
], | ||
) | ||
def test_full_validate_invalid(self, data): | ||
form = UploadForm(MultiDict(data)) | ||
with pytest.raises(ValidationError): | ||
form.full_validate() |
Oops, something went wrong.