Skip to content

Commit 8c8b3e4

Browse files
committed
Add additional repo types
* Test that older packages are selected in check_for_duplicate_packages Signed-off-by: Jono Yang <[email protected]>
1 parent 8941b73 commit 8c8b3e4

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

minecode/indexing.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,32 @@ def check_for_duplicate_packages(package):
151151
return False
152152

153153
repo_types = [
154+
"apache",
155+
"bower",
156+
"composer",
157+
"cpan",
158+
"cran",
159+
"crate",
160+
"deb",
161+
"docker",
162+
"eclipse",
163+
"fdroid",
164+
"gem",
165+
"golang",
166+
"gstreamer",
154167
"maven",
155-
"pypi",
156168
"npm",
157-
"crate",
169+
"nuget",
170+
"openwrt",
171+
"pypi",
172+
"rpm",
158173
]
159-
git_repo_types = [
174+
source_repo_types = [
175+
"bitbucket",
160176
"github",
161177
"gitlab",
162-
"bitbucket",
178+
"googlecode",
179+
"sourceforge",
163180
]
164181

165182
# Check for dupes
@@ -169,7 +186,10 @@ def check_for_duplicate_packages(package):
169186
# TODO: This will probably have to be a task
170187
if (
171188
(package.type in repo_types and existing_package.type not in repo_types)
172-
or (package.type in git_repo_types and package.type not in git_repo_types)
189+
or (
190+
package.type in source_repo_types
191+
and existing_package.type not in source_repo_types
192+
)
173193
or (
174194
(existing_package.release_date and package.release_date)
175195
and (existing_package.release_date > package.release_date)
@@ -179,7 +199,7 @@ def check_for_duplicate_packages(package):
179199
package=package, existing_package=existing_package
180200
)
181201

182-
return bool(package.sha1) and bool(existing_packages)
202+
return bool(existing_packages)
183203

184204

185205
def index_package(

minecode/tests/test_indexing.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import json
1111
import os
12+
from datetime import datetime
1213

1314
from matchcode.models import ApproximateDirectoryContentIndex
1415
from matchcode.models import ApproximateDirectoryStructureIndex
@@ -185,7 +186,7 @@ def test_indexing_index_package_dwarf(self):
185186
expected_extra_data = scan_data["files"][0]["extra_data"]
186187
self.assertEqual(expected_extra_data, extra_data)
187188

188-
def test_update_package_relationships(self):
189+
def test_update_check_for_duplicate_packages(self):
189190
test_package1 = Package.objects.create(
190191
download_url="https://github.com//wagon-api/wagon-api-20040705.181715.jar",
191192
type="github",
@@ -208,11 +209,11 @@ def test_update_package_relationships(self):
208209
with open(scan_data_loc, "rb") as f:
209210
scan_data = json.loads(f.read())
210211

211-
indexing_errors = indexing.index_package_files(test_package1, scan_data)
212+
# Test that resources
213+
indexing.index_package_files(test_package1, scan_data)
212214
indexing.update_package_relationships(
213215
package=test_package2, existing_package=test_package1
214216
)
215-
216217
resources = Resource.objects.filter(package=test_package2)
217218
self.assertEqual(64, len(resources))
218219
resource_data = [r.to_dict() for r in resources]
@@ -222,3 +223,36 @@ def test_update_package_relationships(self):
222223
self.check_expected_results(
223224
resource_data, expected_resources_loc, regen=FIXTURES_REGEN
224225
)
226+
227+
def test_update_check_for_duplicate_packages_release_date(self):
228+
test_package1 = Package.objects.create(
229+
download_url="https://bitbucket.com//wagon-api/wagon-api-20040705.181715.jar",
230+
type="bitbucket",
231+
namespace="",
232+
name="wagon-api",
233+
version="20040705.181715",
234+
sha1="12345",
235+
release_date=datetime.now(),
236+
)
237+
test_package2 = Package.objects.create(
238+
download_url="https://github.com/wagon-api-20040705.181715.jar",
239+
type="github",
240+
namespace="",
241+
name="wagon-api",
242+
version="20040705.181715",
243+
sha1="12345",
244+
release_date=datetime.now(),
245+
)
246+
scan_data_loc = self.get_test_loc(
247+
"indexing/scancodeio_wagon-api-20040705.181715.json"
248+
)
249+
with open(scan_data_loc, "rb") as f:
250+
scan_data = json.loads(f.read())
251+
252+
# Test that resources are updated to use the older package
253+
indexing.index_package_files(test_package2, scan_data)
254+
indexing.update_package_relationships(
255+
package=test_package1, existing_package=test_package2
256+
)
257+
resources = Resource.objects.filter(package=test_package1)
258+
self.assertEqual(64, len(resources))

0 commit comments

Comments
 (0)