|
43 | 43 | from product_portfolio.models import ProductComponent |
44 | 44 | from product_portfolio.models import ProductItemPurpose |
45 | 45 | from product_portfolio.models import ProductPackage |
| 46 | +from product_portfolio.models import ProductPolicyViolation |
46 | 47 | from product_portfolio.models import ProductRelationStatus |
47 | 48 | from product_portfolio.models import ProductStatus |
48 | 49 | from product_portfolio.models import ScanCodeProject |
@@ -717,6 +718,48 @@ def test_api_product_endpoint_manage_permissions_action(self): |
717 | 718 | self.assertIn("errors", response.data) |
718 | 719 |
|
719 | 720 |
|
| 721 | + def test_api_product_endpoint_policy_violations_action(self): |
| 722 | + url = reverse("api_v2:product-policy-violations", args=[self.product1.uuid]) |
| 723 | + |
| 724 | + self.client.login(username=self.base_user.username, password="secret") |
| 725 | + response = self.client.get(url) |
| 726 | + self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) |
| 727 | + |
| 728 | + add_perm(self.base_user, "add_product") |
| 729 | + assign_perm("view_product", self.base_user, self.product1) |
| 730 | + |
| 731 | + response = self.client.get(url) |
| 732 | + self.assertEqual(status.HTTP_200_OK, response.status_code) |
| 733 | + self.assertEqual([], response.data) |
| 734 | + |
| 735 | + violation = ProductPolicyViolation.objects.create( |
| 736 | + product=self.product1, |
| 737 | + dataspace=self.dataspace, |
| 738 | + rule_type="usage_policy_error", |
| 739 | + violation_count=5, |
| 740 | + ) |
| 741 | + |
| 742 | + response = self.client.get(url) |
| 743 | + self.assertEqual(status.HTTP_200_OK, response.status_code) |
| 744 | + self.assertEqual(1, len(response.data)) |
| 745 | + entry = response.data[0] |
| 746 | + self.assertEqual("usage_policy_error", entry["rule_type"]) |
| 747 | + self.assertEqual(5, entry["violation_count"]) |
| 748 | + self.assertFalse(entry["resolved"]) |
| 749 | + self.assertIsNone(entry["resolved_date"]) |
| 750 | + self.assertIn("rule_label", entry) |
| 751 | + self.assertIn("rule_description", entry) |
| 752 | + self.assertIn("rule_severity", entry) |
| 753 | + self.assertIn("detected_date", entry) |
| 754 | + |
| 755 | + violation.resolved = True |
| 756 | + violation.save() |
| 757 | + |
| 758 | + response = self.client.get(url) |
| 759 | + self.assertEqual(status.HTTP_200_OK, response.status_code) |
| 760 | + self.assertEqual([], response.data) |
| 761 | + |
| 762 | + |
720 | 763 | class ProductRelatedAPITestCase(TestCase): |
721 | 764 | def setUp(self): |
722 | 765 | self.dataspace = Dataspace.objects.create(name="nexB") |
|
0 commit comments