Skip to content

Commit

Permalink
Add unit test #138
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Aug 5, 2024
1 parent e5820e2 commit 52d9b41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 1 addition & 5 deletions product_portfolio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,10 +1322,6 @@ def notify(self, verb, description):
)


class ProductDependencyQuerySet(ProductSecuredQuerySet):
pass


class ProductDependency(HistoryFieldsMixin, DataspacedModel):
product = models.ForeignKey(
to="product_portfolio.Product",
Expand Down Expand Up @@ -1400,7 +1396,7 @@ class ProductDependency(HistoryFieldsMixin, DataspacedModel):
help_text=_("True if this is a direct, first-level dependency relationship for a package."),
)

objects = DataspacedManager.from_queryset(ProductDependencyQuerySet)()
objects = DataspacedManager.from_queryset(ProductSecuredQuerySet)()

class Meta:
unique_together = (("product", "dependency_uid"), ("dataspace", "uuid"))
Expand Down
26 changes: 26 additions & 0 deletions product_portfolio/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,3 +917,29 @@ def test_product_dependency_model_save_validation(self):
["The 'for_package' cannot be the same as 'resolved_to_package'."],
cm.exception.messages,
)

def test_product_dependency_prackage_queryset_declared_dependencies_count(self):
package1 = Package.objects.create(filename="package1", dataspace=self.dataspace)
package2 = Package.objects.create(filename="package2", dataspace=self.dataspace)
ProductDependency.objects.create(
product=self.product1,
for_package=package1,
resolved_to_package=package2,
dataspace=self.dataspace,
)
product2 = Product.objects.create(name="Product2", dataspace=self.dataspace)
ProductDependency.objects.create(
product=product2,
for_package=package1,
resolved_to_package=package2,
dataspace=self.dataspace,
)

self.assertEqual(2, package1.declared_dependencies.count())
self.assertEqual(0, package1.resolved_from_dependencies.count())
self.assertEqual(0, package2.declared_dependencies.count())
self.assertEqual(2, package2.resolved_from_dependencies.count())

qs = Package.objects.declared_dependencies_count(product=self.product1)
annotated_package1 = qs.filter(pk=package1.pk)[0]
self.assertEqual(1, annotated_package1.declared_dependencies_count)

0 comments on commit 52d9b41

Please sign in to comment.