Esempio n. 1
0
 def get_package(self, package_name):
     if package_name is None:
         raise NotFound()
     reference = PackageReference.parse(package_name)
     if not reference.instance:
         raise NotFound()
     return reference.instance
Esempio n. 2
0
 def __call__(self, value):
     from thunderstore.repository.package_reference import PackageReference
     try:
         reference = PackageReference.parse(value)
     except ValueError as exc:
         raise ValidationError(str(exc))
     if reference.version is None and self.require_version:
         raise ValidationError(
             f"Package reference is missing version: {reference}")
     if self.resolve and reference.instance is None:
         raise ValidationError(
             f"No matching package found for reference: {reference}")
Esempio n. 3
0
def test_manifest_v1_serializer_dependencies_valid(user, manifest_v1_data):
    reference = PackageReference.parse("actual_package-reference-1.0.0")
    PackageVersionFactory.create(
        package=PackageFactory.create(
            owner=UploaderIdentityFactory.create(name=reference.namespace, ),
            name=reference.name,
        ),
        name=reference.name,
        version_number=reference.version_str,
    )
    identity = UploaderIdentity.get_or_create_for_user(user)
    manifest_v1_data["dependencies"] = [str(reference)]
    serializer = ManifestV1Serializer(
        user=user,
        uploader=identity,
        data=manifest_v1_data,
    )
    assert serializer.is_valid() is True
Esempio n. 4
0
def test_utils_has_duplicate_packages(collection, expected):
    collection = [PackageReference.parse(x) for x in collection]
    assert has_duplicate_packages(collection) == expected
Esempio n. 5
0
def test_utils_does_contain_package(collection, reference, expected):
    collection = [PackageReference.parse(x) for x in collection]
    reference = PackageReference.parse(reference)
    assert does_contain_package(collection, reference) == expected
Esempio n. 6
0
 def to_internal_value(self, data):
     try:
         return PackageReference.parse(str(data))
     except ValueError as exc:
         raise ValidationError(str(exc))