Пример #1
0
def test_reference_validator_eq():
    validators = [
        PackageReferenceValidator(resolve=True, require_version=True),
        PackageReferenceValidator(resolve=False, require_version=True),
        PackageReferenceValidator(resolve=True, require_version=False),
        PackageReferenceValidator(resolve=False, require_version=False),
    ]
    for index, validator in enumerate(validators):
        for index2, validator2 in enumerate(validators):
            if index != index2:
                assert validator != validator2
            else:
                assert validator == copy.deepcopy(validator2)
Пример #2
0
def test_manifest_v1_serializer_too_many_dependencies(user, manifest_v1_data):
    identity = UploaderIdentity.get_or_create_for_user(user)
    reference_strings = [
        f"user-package-{i}.{i}.{i}" for i in range(101)
    ]
    manifest_v1_data["dependencies"] = reference_strings
    serializer = ManifestV1Serializer(
        user=user,
        uploader=identity,
        data=manifest_v1_data,
    )
    # Patch the validator because we don't want to generate 101 actual packages here
    serializer.fields["dependencies"].child.validators = [PackageReferenceValidator(
        require_version=True,
        resolve=False  # Otherwise the same, but don't try to resolve the references
    )]
    assert serializer.is_valid() is False
    assert len(serializer.errors["dependencies"]) == 1
    assert "Ensure this field has no more than 100 elements." in str(serializer.errors["dependencies"][0])
Пример #3
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.validators.append(
         PackageReferenceValidator(require_version=True, resolve=True))
Пример #4
0
def test_reference_validator_resolve_version(package_version):
    validator = PackageReferenceValidator(resolve=True, require_version=True)
    validator(str(package_version.reference))
Пример #5
0
def test_reference_validator_unresolved():
    validator = PackageReferenceValidator(resolve=True, require_version=True)
    with pytest.raises(DjangoValidationError) as exc:
        validator("someUser-somePackage-1.0.0")
    assert "No matching package found for reference" in str(exc.value)
Пример #6
0
def test_reference_validator_invalid_reference():
    validator = PackageReferenceValidator(resolve=False, require_version=False)
    with pytest.raises(DjangoValidationError) as exc:
        validator("not a reference")
    assert "Invalid package reference" in str(exc.value)
Пример #7
0
def test_reference_validator_allow_versionless():
    validator = PackageReferenceValidator(resolve=False, require_version=False)
    validator("someUser-somePackage")
    validator("someUser-somePackage-1.0.0")
Пример #8
0
def test_reference_validator_require_version():
    validator = PackageReferenceValidator(resolve=False, require_version=True)
    with pytest.raises(DjangoValidationError) as exc:
        validator("someUser-somePackage")
    assert "Package reference is missing version" in str(exc.value)
    validator("someUser-somePackage-1.0.0")
Пример #9
0
def test_reference_validator_resolve_versionless(package_version):
    validator = PackageReferenceValidator(resolve=True, require_version=False)
    validator(str(package_version.reference.without_version))