Skip to content

Commit

Permalink
Merge pull request #318 from nexB/support-indexing-of-dir-listed-pack…
Browse files Browse the repository at this point in the history
…ages

Support indexing of directory listed and GNU packages
  • Loading branch information
keshav-space authored Mar 19, 2024
2 parents e2c4d5c + 4953229 commit e676fc0
Show file tree
Hide file tree
Showing 7 changed files with 715 additions and 19 deletions.
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(
"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

0 comments on commit e676fc0

Please sign in to comment.