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 indexing of directory listed and GNU packages #318

Merged
merged 10 commits into from
Mar 19, 2024
38 changes: 25 additions & 13 deletions minecode/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
# See https://aboutcode.org for more information about nexB OSS projects.
#

import os

from django.test import TestCase as DjangoTestCase
from packagedcode.maven import _parse
from packageurl import PackageURL

from minecode.route import NoRouteAvailable
from minecode.utils_test import JsonBasedTesting
from minecode.visitors import generic
from packagedb.models import Package

from packagedcode.maven import _parse
from packageurl import PackageURL


class GenericPriorityQueueTests(JsonBasedTesting, DjangoTestCase):
def test_process_request(self):
Expand All @@ -40,15 +38,10 @@ def test_process_request_no_download_url(self):
package_count = Package.objects.all().count()
self.assertEqual(0, package_count)

purl = 'pkg:generic/[email protected]'
error_msg = generic.process_request(purl)
purl = "pkg:generic/[email protected]"

self.assertEqual(
f'package_url {purl} does not contain a download_url qualifier',
error_msg
)
package_count = Package.objects.all().count()
self.assertEqual(0, package_count)
with self.assertRaises(NoRouteAvailable):
generic.process_request(purl)

def test_map_generic_package(self):
package_count = Package.objects.all().count()
Expand All @@ -66,3 +59,22 @@ def test_map_generic_package(self):
self.assertEqual('test', package.name)
self.assertEqual('1.0.0', package.version)
self.assertEqual('http://example.com/test.tar.gz', package.download_url)

def test_process_request_dir_listed(self):
package_count = Package.objects.all().count()
self.assertEqual(0, package_count)

purl = "pkg:generic/[email protected]"
error_msg = generic.process_request_dir_listed(purl)

self.assertEqual(None, error_msg)
package_count = Package.objects.all().count()
self.assertEqual(1, package_count)

package = Package.objects.first()
self.assertEqual("ipkg", package.name)
self.assertEqual("0.99.33", package.version)
self.assertEqual(
"https://web.archive.org/web/20090326020239/http:/handhelds.org/download/packages/ipkg/ipkg_0.99.33_arm.ipk",
package.download_url,
)
61 changes: 61 additions & 0 deletions minecode/tests/test_gnu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# purldb is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/purldb for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#


import os

from django.test import TestCase
from mock import patch

from minecode.utils_test import JsonBasedTesting
from minecode.visitors import gnu
from packagedb.models import Package


class GnuPriorityQueueTests(JsonBasedTesting, TestCase):
test_data_dir = os.path.join(os.path.dirname(__file__), "testfiles")

def setUp(self):
super(GnuPriorityQueueTests, self).setUp()
glibc_data_loc = self.get_test_loc("gnu/glibc/index.html")

with open(glibc_data_loc) as f:
self.glibc_data_content = f.read()

@patch("requests.get")
def test_process_request(self, mock_get):
mock_get.side_effect = [
type(
JonoYang marked this conversation as resolved.
Show resolved Hide resolved
"Response",
(),
{
"content": self.glibc_data_content.encode(),
"raise_for_status": lambda: None,
},
)
]

package_count = Package.objects.all().count()
self.assertEqual(0, package_count)

purl = "pkg:gnu/[email protected]"
error_msg = gnu.process_request(purl)

self.assertEqual(None, error_msg)
package_count = Package.objects.all().count()
self.assertEqual(1, package_count)

package = Package.objects.first()
self.assertEqual("glibc", package.name)
self.assertEqual("2.15", package.version)

self.assertEqual(
"https://ftp.gnu.org/pub/gnu/glibc/glibc-2.15.tar.gz",
package.download_url,
)
Loading
Loading