Skip to content

Commit f0171d5

Browse files
committed
Add test for gnu package indexing
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent c36ec1e commit f0171d5

2 files changed

Lines changed: 555 additions & 0 deletions

File tree

minecode/tests/test_gnu.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# purldb is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/purldb for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
11+
import os
12+
13+
from django.test import TestCase
14+
from mock import patch
15+
16+
from minecode.utils_test import JsonBasedTesting
17+
from minecode.visitors import gnu
18+
from packagedb.models import Package
19+
20+
21+
class GnuPriorityQueueTests(JsonBasedTesting, TestCase):
22+
test_data_dir = os.path.join(os.path.dirname(__file__), "testfiles")
23+
24+
def setUp(self):
25+
super(GnuPriorityQueueTests, self).setUp()
26+
glibc_data_loc = self.get_test_loc("gnu/glibc/index.html")
27+
28+
with open(glibc_data_loc) as f:
29+
self.glibc_data_content = f.read()
30+
31+
@patch("requests.get")
32+
def test_process_request(self, mock_get):
33+
mock_get.side_effect = [
34+
type(
35+
"Response",
36+
(),
37+
{
38+
"content": self.glibc_data_content.encode(),
39+
"raise_for_status": lambda: None,
40+
},
41+
)
42+
]
43+
44+
package_count = Package.objects.all().count()
45+
self.assertEqual(0, package_count)
46+
47+
purl = "pkg:gnu/glibc@2.15"
48+
error_msg = gnu.process_request(purl)
49+
50+
self.assertEqual(None, error_msg)
51+
package_count = Package.objects.all().count()
52+
self.assertEqual(1, package_count)
53+
54+
package = Package.objects.first()
55+
self.assertEqual("glibc", package.name)
56+
self.assertEqual("2.15", package.version)
57+
print(package.download_url)
58+
self.assertEqual(
59+
"https://ftp.gnu.org/pub/gnu/glibc/glibc-2.15.tar.gz",
60+
package.download_url,
61+
)

0 commit comments

Comments
 (0)