Skip to content

Commit

Permalink
Refine the product comparison logic for Packages #113 (#114)
Browse files Browse the repository at this point in the history
* Refine the product comparison logic for Packages #113

Signed-off-by: tdruez <tdruez@nexb.com>

* Refactor the ProductTreeComparisonView as class based view #113

Signed-off-by: tdruez <tdruez@nexb.com>

---------

Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed May 10, 2024
1 parent 5a34bdd commit 86fcc7f
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 124 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -57,6 +57,11 @@ Release notes
- Display full commit in the version displayed in the UI
https://github.com/nexB/dejacode/issues/88

- Refine the Product comparison logic for Packages.
The type and namespace fields are now used along the name field to match similar
Packages (excluding the version).
https://github.com/nexB/dejacode/issues/113

### Version 5.0.1

- Improve the stability of the "Check for new Package versions" feature.
Expand Down
49 changes: 49 additions & 0 deletions product_portfolio/tests/test_views.py
Expand Up @@ -1228,6 +1228,55 @@ def test_product_portfolio_product_tree_comparison_view_proper(self):
expected_disposition = "attachment; filename=product_comparison.xlsx"
self.assertEqual(expected_disposition, response.headers.get("Content-Disposition"))

def test_product_portfolio_product_tree_comparison_view_package_identifier(self):
self.client.login(username="nexb_user", password="secret")
url = resolve_url(
"product_portfolio:product_tree_comparison",
left_uuid=self.product1.uuid,
right_uuid=self.product2.uuid,
)

p1 = Package(dataspace=self.dataspace)
p1.set_package_url("pkg:bar/baz/pypdf@4.1.0")
p1.save()
pp1 = ProductPackage.objects.create(
product=self.product1, package=p1, dataspace=self.dataspace
)

# Same name different type and namespace
p2 = Package(dataspace=self.dataspace)
p2.set_package_url("pkg:github/py-pdf/pypdf@4.2.0")
p2.save()
pp2 = ProductPackage.objects.create(
product=self.product2, package=p2, dataspace=self.dataspace
)

response = self.client.get(url)
expected = [("removed", pp1, None, None), ("added", None, pp2, None)]
self.assertEqual(expected, response.context["rows"])

# Same type, namespace, name combo
p2.set_package_url("pkg:bar/baz/pypdf@4.2.0")
p2.save()
response = self.client.get(url)
expected = [("updated", pp1, pp2, None)]
self.assertEqual(expected, response.context["rows"])

# More than 2 packages with same unique identifier
p3 = Package(dataspace=self.dataspace)
p3.set_package_url("pkg:bar/baz/pypdf@4.3.0")
p3.save()
pp3 = ProductPackage.objects.create(
product=self.product2, package=p3, dataspace=self.dataspace
)
response = self.client.get(url)
expected = [
("removed", pp1, None, None),
("added", None, pp2, None),
("added", None, pp3, None),
]
self.assertEqual(expected, response.context["rows"])

def test_product_portfolio_product_tree_comparison_view_secured_access(self):
self.client.login(username=self.basic_user.username, password="secret")
url = resolve_url(
Expand Down
4 changes: 2 additions & 2 deletions product_portfolio/urls.py
Expand Up @@ -22,6 +22,7 @@
from product_portfolio.views import ProductSendAboutFilesView
from product_portfolio.views import ProductTabCodebaseView
from product_portfolio.views import ProductTabImportsView
from product_portfolio.views import ProductTreeComparisonView
from product_portfolio.views import ProductUpdateView
from product_portfolio.views import PullProjectDataFromScanCodeIOView
from product_portfolio.views import add_customcomponent_ajax_view
Expand All @@ -30,7 +31,6 @@
from product_portfolio.views import import_from_scan_view
from product_portfolio.views import import_packages_from_scancodeio_view
from product_portfolio.views import license_summary_view
from product_portfolio.views import product_tree_comparison_view
from product_portfolio.views import scan_all_packages_view
from product_portfolio.views import scancodeio_project_status_view

Expand Down Expand Up @@ -67,7 +67,7 @@ def product_path(path_segment, view):
),
path(
"compare/<uuid:left_uuid>/<uuid:right_uuid>/",
product_tree_comparison_view,
ProductTreeComparisonView.as_view(),
name="product_tree_comparison",
),
path(
Expand Down

0 comments on commit 86fcc7f

Please sign in to comment.