3737from product_portfolio .models import ProductPackage
3838from product_portfolio .models import ProductRelationStatus
3939from product_portfolio .models import ProductSecuredManager
40- from product_portfolio .models import ProductStatus
4140from product_portfolio .models import ScanCodeProject
4241from product_portfolio .tests import make_product
4342from product_portfolio .tests import make_product_dependency
4443from product_portfolio .tests import make_product_item_purpose
4544from product_portfolio .tests import make_product_package
45+ from product_portfolio .tests import make_product_status
4646from vulnerabilities .tests import make_vulnerability
4747from workflow .models import RequestTemplate
4848
@@ -69,19 +69,15 @@ def setUp(self):
6969 )
7070
7171 def test_product_model_default_status_on_product_addition (self ):
72- status1 = ProductStatus .objects .create (
73- label = "S1" , text = "Status1" , default_on_addition = True , dataspace = self .dataspace
74- )
75- status2 = ProductStatus .objects .create (label = "S2" , text = "Status2" , dataspace = self .dataspace )
72+ status1 = make_product_status (default_on_addition = True , dataspace = self .dataspace )
73+ status2 = make_product_status (dataspace = self .dataspace )
7674
7775 # No status given at creation time, the default is set
78- p1 = Product . objects . create ( name = "P1" , dataspace = self .dataspace )
76+ p1 = make_product ( dataspace = self .dataspace , name = "P1" )
7977 self .assertEqual (status1 , p1 .configuration_status )
8078
8179 # A status is given at creation time, no default is set
82- p2 = Product .objects .create (
83- name = "P2" , configuration_status = status2 , dataspace = self .dataspace
84- )
80+ p2 = make_product (dataspace = self .dataspace , name = "P2" , configuration_status = status2 )
8581 self .assertEqual (status2 , p2 .configuration_status )
8682
8783 def test_product_model_get_attribution_url (self ):
@@ -105,6 +101,19 @@ def test_product_model_secured_manager(self):
105101 self .assertEqual (1 , Product .objects .get_queryset (self .super_user ).count ())
106102 self .assertIn (self .product1 , Product .objects .get_queryset (self .super_user ))
107103
104+ def test_product_model_secured_manager_get_queryset_exclude_locked (self ):
105+ qs = Product .objects .get_queryset (self .super_user )
106+ self .assertIn (self .product1 , qs )
107+ qs = Product .objects .get_queryset (self .super_user , exclude_locked = True )
108+ self .assertIn (self .product1 , qs )
109+
110+ locked_status = make_product_status (self .dataspace , is_locked = True )
111+ self .product1 .update (configuration_status = locked_status )
112+ qs = Product .objects .get_queryset (self .super_user )
113+ self .assertIn (self .product1 , qs )
114+ qs = Product .objects .get_queryset (self .super_user , exclude_locked = True )
115+ self .assertNotIn (self .product1 , qs )
116+
108117 def test_product_model_is_active (self ):
109118 qs = Product .objects .get_queryset (self .super_user )
110119 self .assertIn (self .product1 , qs )
@@ -490,14 +499,12 @@ def test_product_model_actions_on_status_change(self):
490499 dataspace = self .super_user .dataspace ,
491500 content_type = product_ct ,
492501 )
493-
494- status1 = ProductStatus . objects . create (
502+ status1 = make_product_status (
503+ self . dataspace ,
495504 label = "status1" ,
496505 text = "status1" ,
497506 request_to_generate = request_template1 ,
498- dataspace = self .dataspace ,
499507 )
500-
501508 product .configuration_status = status1
502509 product .last_modified_by = self .super_user
503510 self .assertTrue (product .has_changed ("configuration_status_id" ))
@@ -509,6 +516,19 @@ def test_product_model_actions_on_status_change(self):
509516 product .refresh_from_db ()
510517 self .assertEqual (1 , product .request_count )
511518
519+ def test_product_model_is_locked_property (self ):
520+ product = make_product (self .dataspace )
521+ self .assertFalse (product .is_locked )
522+
523+ status1 = make_product_status (self .dataspace , is_locked = False )
524+ product .update (configuration_status = status1 )
525+ product = Product .unsecured_objects .get (pk = product .pk )
526+ self .assertFalse (product .is_locked )
527+
528+ status1 .update (is_locked = True )
529+ product = Product .unsecured_objects .get (pk = product .pk )
530+ self .assertTrue (product .is_locked )
531+
512532 @mock .patch ("component_catalog.models.Package.update_from_purldb" )
513533 def test_product_model_improve_packages_from_purldb (self , mock_update_from_purldb ):
514534 mock_update_from_purldb .return_value = 1
0 commit comments