7575from scanpipe .pipes .input import copy_input
7676from scanpipe .tests import dependency_data1
7777from scanpipe .tests import dependency_data2
78+ from scanpipe .tests import global_policies
7879from scanpipe .tests import license_policies_index
7980from scanpipe .tests import make_dependency
8081from scanpipe .tests import make_message
@@ -697,21 +698,21 @@ def test_scanpipe_project_get_input_policies_file(self):
697698 policies_file_location = str (self .project1 .get_input_policies_file ())
698699 self .assertTrue (policies_file_location .endswith ("input/policies.yml" ))
699700
700- def test_scanpipe_project_model_get_policy_index (self ):
701- scanpipe_app .license_policies_index = None
702- self .assertFalse (self .project1 .policies_enabled )
703-
704- policies_from_app_settings = {"from" : "scanpipe_app" }
705- scanpipe_app .license_policies_index = policies_from_app_settings
706- self .assertEqual (policies_from_app_settings , self .project1 .get_policy_index ())
701+ @patch .object (scanpipe_app , "policies" , new = global_policies )
702+ def test_scanpipe_project_model_get_license_policy_index (self ):
703+ self .assertEqual (
704+ license_policies_index , self .project1 .get_license_policy_index ()
705+ )
707706
708707 policies_from_input_dir = {"license_policies" : [{"license_key" : "input_dir" }]}
709708 policies_file = self .project1 .input_path / "policies.yml"
710709 policies_file .touch ()
711710 policies_as_yaml = saneyaml .dump (policies_from_input_dir )
712711 policies_file .write_text (policies_as_yaml )
713712 expected_index_from_input = {"input_dir" : {"license_key" : "input_dir" }}
714- self .assertEqual (expected_index_from_input , self .project1 .get_policy_index ())
713+ self .assertEqual (
714+ expected_index_from_input , self .project1 .get_license_policy_index ()
715+ )
715716 # Refresh the instance to bypass the cached_property cache.
716717 self .project1 = Project .objects .get (uuid = self .project1 .uuid )
717718 self .assertTrue (self .project1 .policies_enabled )
@@ -723,10 +724,9 @@ def test_scanpipe_project_model_get_policy_index(self):
723724 self .project1 .settings = config
724725 self .project1 .save ()
725726 expected_index_from_env = {"project_env" : {"license_key" : "project_env" }}
726- self .assertEqual (expected_index_from_env , self .project1 .get_policy_index ())
727-
728- # Reset the index value
729- scanpipe_app .license_policies_index = None
727+ self .assertEqual (
728+ expected_index_from_env , self .project1 .get_license_policy_index ()
729+ )
730730
731731 def test_scanpipe_project_get_settings_as_yml (self ):
732732 self .assertEqual ("{}\n " , self .project1 .get_settings_as_yml ())
@@ -1547,28 +1547,31 @@ def test_scanpipe_codebase_resource_model_commoncode_methods_extracted_to_from(
15471547 self .assertEqual (extracted_dir_resource , archive_resource .extracted_to ())
15481548 self .assertEqual (archive_resource , extracted_dir_resource .extracted_from ())
15491549
1550+ @patch .object (scanpipe_app , "policies" , new = global_policies )
15501551 def test_scanpipe_codebase_resource_model_compliance_alert (self ):
1551- scanpipe_app .license_policies_index = license_policies_index
1552+ project_license_policies_index = self .project1 .policy_index
1553+ self .assertEqual (license_policies_index , project_license_policies_index )
1554+
15521555 resource = CodebaseResource .objects .create (project = self .project1 , path = "file" )
15531556 self .assertEqual ("" , resource .compliance_alert )
15541557
15551558 license_expression = "bsd-new"
1556- self .assertNotIn (license_expression , scanpipe_app . license_policies_index )
1559+ self .assertNotIn (license_expression , project_license_policies_index )
15571560 resource .update (detected_license_expression = license_expression )
15581561 self .assertEqual ("missing" , resource .compliance_alert )
15591562
15601563 license_expression = "apache-2.0"
1561- self .assertIn (license_expression , scanpipe_app . license_policies_index )
1564+ self .assertIn (license_expression , project_license_policies_index )
15621565 resource .update (detected_license_expression = license_expression )
15631566 self .assertEqual ("ok" , resource .compliance_alert )
15641567
15651568 license_expression = "mpl-2.0"
1566- self .assertIn (license_expression , scanpipe_app . license_policies_index )
1569+ self .assertIn (license_expression , project_license_policies_index )
15671570 resource .update (detected_license_expression = license_expression )
15681571 self .assertEqual ("warning" , resource .compliance_alert )
15691572
15701573 license_expression = "gpl-3.0"
1571- self .assertIn (license_expression , scanpipe_app . license_policies_index )
1574+ self .assertIn (license_expression , project_license_policies_index )
15721575 resource .update (detected_license_expression = license_expression )
15731576 self .assertEqual ("error" , resource .compliance_alert )
15741577
@@ -1584,11 +1587,8 @@ def test_scanpipe_codebase_resource_model_compliance_alert(self):
15841587 resource .update (detected_license_expression = license_expression )
15851588 self .assertEqual ("warning" , resource .compliance_alert )
15861589
1587- # Reset the index value
1588- scanpipe_app .license_policies_index = None
1589-
1590+ @patch .object (scanpipe_app , "policies" , new = global_policies )
15901591 def test_scanpipe_codebase_resource_model_compliance_alert_update_fields (self ):
1591- scanpipe_app .license_policies_index = license_policies_index
15921592 resource = CodebaseResource .objects .create (project = self .project1 , path = "file" )
15931593 self .assertEqual ("" , resource .compliance_alert )
15941594
@@ -1598,9 +1598,6 @@ def test_scanpipe_codebase_resource_model_compliance_alert_update_fields(self):
15981598 resource .refresh_from_db ()
15991599 self .assertEqual ("ok" , resource .compliance_alert )
16001600
1601- # Reset the index value
1602- scanpipe_app .license_policies_index = None
1603-
16041601 def test_scanpipe_scan_fields_model_mixin_methods (self ):
16051602 expected = [
16061603 "detected_license_expression" ,
@@ -2422,30 +2419,27 @@ def test_scanpipe_discovered_package_model_as_cyclonedx(self):
24222419 cyclonedx_component .evidence .licenses [0 ].value ,
24232420 )
24242421
2422+ @patch .object (scanpipe_app , "policies" , new = global_policies )
24252423 def test_scanpipe_discovered_package_model_compliance_alert (self ):
2426- scanpipe_app .license_policies_index = license_policies_index
24272424 package_data = package_data1 .copy ()
24282425 package_data ["declared_license_expression" ] = ""
24292426 package = DiscoveredPackage .create_from_data (self .project1 , package_data )
24302427 self .assertEqual ("" , package .compliance_alert )
24312428
24322429 license_expression = "bsd-new"
2433- self .assertNotIn (license_expression , scanpipe_app . license_policies_index )
2430+ self .assertNotIn (license_expression , self . project1 . policy_index )
24342431 package .update (declared_license_expression = license_expression )
24352432 self .assertEqual ("missing" , package .compliance_alert )
24362433
24372434 license_expression = "apache-2.0"
2438- self .assertIn (license_expression , scanpipe_app . license_policies_index )
2435+ self .assertIn (license_expression , self . project1 . policy_index )
24392436 package .update (declared_license_expression = license_expression )
24402437 self .assertEqual ("ok" , package .compliance_alert )
24412438
24422439 license_expression = "apache-2.0 AND mpl-2.0 OR gpl-3.0"
24432440 package .update (declared_license_expression = license_expression )
24442441 self .assertEqual ("error" , package .compliance_alert )
24452442
2446- # Reset the index value
2447- scanpipe_app .license_policies_index = None
2448-
24492443 def test_scanpipe_discovered_package_model_spdx_id (self ):
24502444 package1 = make_package (self .project1 , "pkg:type/a" )
24512445 expected = f"SPDXRef-scancodeio-discoveredpackage-{ package1 .uuid } "
0 commit comments