generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from nexB/support-indexing-of-dir-listed-pack…
…ages Support indexing of directory listed and GNU packages
- Loading branch information
Showing
7 changed files
with
715 additions
and
19 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 |
---|---|---|
|
@@ -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): | ||
|
@@ -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() | ||
|
@@ -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, | ||
) |
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,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, | ||
) |
Oops, something went wrong.