Skip to content

Commit

Permalink
Fix part of the failing unit tests #3
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 20, 2023
1 parent ecc3da4 commit 9edcf6b
Showing 1 changed file with 18 additions and 41 deletions.
59 changes: 18 additions & 41 deletions product_portfolio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def test_product_portfolio_detail_view_tab_imports_view(self):

def test_product_portfolio_detail_view_object_type_filter_in_inventory_tab(self):
self.client.login(username="nexb_user", password="secret")
url = self.product1.get_absolute_url()

pc_valid = ProductComponent.objects.create(
product=self.product1,
Expand All @@ -227,11 +226,12 @@ def test_product_portfolio_detail_view_object_type_filter_in_inventory_tab(self)
product=self.product1, package=self.package1, dataspace=self.dataspace
)

response = self.client.get(url)
response = self.client.get(self.product1.get_absolute_url())
self.assertContains(response, 'id="tab_inventory"')
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]

url = self.product1.get_url("tab_inventory")
response = self.client.get(url)
pc_filterset = response.context["inventory_items"][""]

expected = """
<div class="dropdown-menu" id="id_inventory-object_type">
Expand All @@ -253,45 +253,35 @@ def test_product_portfolio_detail_view_object_type_filter_in_inventory_tab(self)
self.assertContains(response, expected, html=True)

response = self.client.get(url + "?inventory-object_type=catalog")
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]
pc_filterset = response.context["inventory_items"][""]
self.assertIn(pc_valid, pc_filterset)
self.assertNotIn(pc2_custom, pc_filterset)
self.assertNotIn(pp1, pc_filterset)

response = self.client.get(url + "?inventory-object_type=custom")
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]
pc_filterset = response.context["inventory_items"][""]
self.assertNotIn(pc_valid, pc_filterset)
self.assertIn(pc2_custom, pc_filterset)
self.assertNotIn(pp1, pc_filterset)

response = self.client.get(url + "?inventory-object_type=package")
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]
pc_filterset = response.context["inventory_items"][""]
self.assertNotIn(pc_valid, pc_filterset)
self.assertNotIn(pc2_custom, pc_filterset)
self.assertIn(pp1, pc_filterset)

response = self.client.get(url + "?inventory-object_type=ANYTHINGELSE")
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]
self.assertEqual({"inventory_items": {}}, pc_filterset)
pc_filterset = response.context["inventory_items"]
self.assertEqual({}, pc_filterset)

response = self.client.get(url + "?inventory-is_deployed=no")
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]
pc_filterset = response.context["inventory_items"][""]
self.assertIn(pc_valid, pc_filterset)
self.assertNotIn(pc2_custom, pc_filterset)
self.assertNotIn(pp1, pc_filterset)

response = self.client.get(url + "?inventory-is_modified=yes")
pc_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]
pc_filterset = response.context["inventory_items"][""]
self.assertNotIn(pc_valid, pc_filterset)
self.assertIn(pc2_custom, pc_filterset)
self.assertNotIn(pp1, pc_filterset)
Expand Down Expand Up @@ -360,16 +350,14 @@ def test_product_portfolio_detail_view_inventory_tab_filters(self):
product=self.product1, package=package2, is_modified=False, dataspace=self.dataspace
)

url = self.product1.get_absolute_url()
url = self.product1.get_url("tab_inventory")
response = self.client.get(url)
self.assertContains(response, self.package1.filename)
self.assertContains(response, package2.filename)

data = {"inventory-is_modified": "yes"}
response = self.client.get(url, data=data)
pp_filterset = response.context["tabsets"]["Inventory"]["fields"][0][1]["inventory_items"][
""
]
pp_filterset = response.context["inventory_items"][""]
self.assertIn(pp1, pp_filterset)
self.assertNotIn(pp2, pp_filterset)

Expand Down Expand Up @@ -405,18 +393,9 @@ def test_product_portfolio_detail_view_inventory_tab_compliance_alerts(self):
dataspace=self.dataspace,
)

url = self.product1.get_absolute_url()
response = self.client.get(url)
# This is driven by the ProductComponent.component usage_policy, not from its
# licenses
self.assertNotContains(response, 'title="Compliance errors"')
self.assertNotContains(response, "table-danger")

self.component1.usage_policy = component_policy
self.component1.save()
url = self.product1.get_absolute_url()
url = self.product1.get_url("tab_inventory")
response = self.client.get(url)
self.assertContains(response, 'title="Compliance errors"')
self.assertContains(response, "Compliance errors")
self.assertContains(response, "table-danger")

def test_product_portfolio_detail_view_inventory_tab_purpose_icon(self):
Expand Down Expand Up @@ -510,7 +489,7 @@ def test_product_detail_view_inventory_tab_display_vulnerabilities(

def test_product_portfolio_detail_view_feature_field_grouping_in_inventory_tab(self):
self.client.login(username="nexb_user", password="secret")
url = self.product1.get_absolute_url()
url = self.product1.get_url("tab_inventory")
self.client.get(url)

pc_valid = ProductComponent.objects.create(
Expand All @@ -532,9 +511,7 @@ def test_product_portfolio_detail_view_feature_field_grouping_in_inventory_tab(s
)

response = self.client.get(url)
feature_grouped = response.context["tabsets"]["Inventory"]["fields"][0][1][
"inventory_items"
]
feature_grouped = response.context["inventory_items"]
expected = {
"f1": [pc2_custom, pp1],
"f2": [pc_valid],
Expand Down

0 comments on commit 9edcf6b

Please sign in to comment.