@@ -698,6 +698,28 @@ def test_scanpipe_project_get_input_policies_file(self):
698698 policies_file_location = str (self .project1 .get_input_policies_file ())
699699 self .assertTrue (policies_file_location .endswith ("input/policies.yml" ))
700700
701+ @patch .object (scanpipe_app , "policies" , new = global_policies )
702+ def test_scanpipe_project_model_get_policies_dict (self ):
703+ self .assertEqual (scanpipe_app .policies , self .project1 .get_policies_dict ())
704+
705+ policies_from_input_dir = {"license_policies" : [{"license_key" : "input_dir" }]}
706+ policies_file = self .project1 .input_path / "policies.yml"
707+ policies_file .touch ()
708+ policies_as_yaml = saneyaml .dump (policies_from_input_dir )
709+ policies_file .write_text (policies_as_yaml )
710+ self .assertEqual (policies_from_input_dir , self .project1 .get_policies_dict ())
711+ # Refresh the instance to bypass the cached_property cache.
712+ self .project1 = Project .objects .get (uuid = self .project1 .uuid )
713+ self .assertTrue (self .project1 .license_policies_enabled )
714+
715+ policies_from_project_env = {
716+ "license_policies" : [{"license_key" : "project_env" }]
717+ }
718+ config = {"policies" : policies_from_project_env }
719+ self .project1 .settings = config
720+ self .project1 .save ()
721+ self .assertEqual (policies_from_project_env , self .project1 .get_policies_dict ())
722+
701723 @patch .object (scanpipe_app , "policies" , new = global_policies )
702724 def test_scanpipe_project_model_get_license_policy_index (self ):
703725 self .assertEqual (
@@ -715,7 +737,7 @@ def test_scanpipe_project_model_get_license_policy_index(self):
715737 )
716738 # Refresh the instance to bypass the cached_property cache.
717739 self .project1 = Project .objects .get (uuid = self .project1 .uuid )
718- self .assertTrue (self .project1 .policies_enabled )
740+ self .assertTrue (self .project1 .license_policies_enabled )
719741
720742 policies_from_project_env = {
721743 "license_policies" : [{"license_key" : "project_env" }]
@@ -728,6 +750,23 @@ def test_scanpipe_project_model_get_license_policy_index(self):
728750 expected_index_from_env , self .project1 .get_license_policy_index ()
729751 )
730752
753+ def test_scanpipe_models_license_policies_enabled (self ):
754+ resource1 = make_resource_file (self .project1 , path = "example" )
755+ package1 = make_package (self .project1 , "pkg:type/a" )
756+
757+ self .assertFalse (self .project1 .license_policies_enabled )
758+ self .assertFalse (resource1 .license_policies_enabled )
759+ self .assertFalse (package1 .license_policies_enabled )
760+
761+ with patch .object (scanpipe_app , "policies" , new = global_policies ):
762+ # Refresh the instance to bypass the cached_property cache.
763+ self .project1 = Project .objects .get (uuid = self .project1 .uuid )
764+ resource1 = self .project1 .codebaseresources .get ()
765+ package1 = self .project1 .discoveredpackages .get ()
766+ self .assertTrue (self .project1 .license_policies_enabled )
767+ self .assertTrue (resource1 .license_policies_enabled )
768+ self .assertTrue (package1 .license_policies_enabled )
769+
731770 def test_scanpipe_project_get_settings_as_yml (self ):
732771 self .assertEqual ("{}\n " , self .project1 .get_settings_as_yml ())
733772
@@ -1549,7 +1588,7 @@ def test_scanpipe_codebase_resource_model_commoncode_methods_extracted_to_from(
15491588
15501589 @patch .object (scanpipe_app , "policies" , new = global_policies )
15511590 def test_scanpipe_codebase_resource_model_compliance_alert (self ):
1552- project_license_policies_index = self .project1 .policy_index
1591+ project_license_policies_index = self .project1 .license_policy_index
15531592 self .assertEqual (license_policies_index , project_license_policies_index )
15541593
15551594 resource = CodebaseResource .objects .create (project = self .project1 , path = "file" )
@@ -2427,12 +2466,12 @@ def test_scanpipe_discovered_package_model_compliance_alert(self):
24272466 self .assertEqual ("" , package .compliance_alert )
24282467
24292468 license_expression = "bsd-new"
2430- self .assertNotIn (license_expression , self .project1 .policy_index )
2469+ self .assertNotIn (license_expression , self .project1 .license_policy_index )
24312470 package .update (declared_license_expression = license_expression )
24322471 self .assertEqual ("missing" , package .compliance_alert )
24332472
24342473 license_expression = "apache-2.0"
2435- self .assertIn (license_expression , self .project1 .policy_index )
2474+ self .assertIn (license_expression , self .project1 .license_policy_index )
24362475 package .update (declared_license_expression = license_expression )
24372476 self .assertEqual ("ok" , package .compliance_alert )
24382477
0 commit comments