2525from django .core .exceptions import ValidationError
2626from django .test import TestCase
2727
28- from scanpipe .pipes .compliance_thresholds import ClarityThresholdsPolicy
28+ from scanpipe .pipes .compliance_thresholds import LicenseClarityThresholdsPolicy
2929from scanpipe .pipes .compliance_thresholds import ScorecardThresholdsPolicy
3030from scanpipe .pipes .compliance_thresholds import load_thresholds_from_file
3131from scanpipe .pipes .compliance_thresholds import load_thresholds_from_yaml
3232
3333
34- class ClarityThresholdsPolicyTest (TestCase ):
35- """Test ClarityThresholdsPolicy class functionality."""
34+ class LicenseClarityThresholdsPolicyTest (TestCase ):
35+ """Test LicenseClarityThresholdsPolicy class functionality."""
3636
3737 data = Path (__file__ ).parent .parent / "data"
3838
3939 def test_valid_thresholds_initialization (self ):
4040 thresholds = {80 : "ok" , 50 : "warning" , 20 : "error" }
41- policy = ClarityThresholdsPolicy (thresholds )
41+ policy = LicenseClarityThresholdsPolicy (thresholds )
4242 self .assertEqual (policy .thresholds , thresholds )
4343
4444 def test_string_keys_converted_to_integers (self ):
4545 thresholds = {"80" : "ok" , "50" : "warning" }
46- policy = ClarityThresholdsPolicy (thresholds )
46+ policy = LicenseClarityThresholdsPolicy (thresholds )
4747 expected = {80 : "ok" , 50 : "warning" }
4848 self .assertEqual (policy .thresholds , expected )
4949
5050 def test_invalid_threshold_key_raises_error (self ):
5151 with self .assertRaises (ValidationError ) as cm :
52- ClarityThresholdsPolicy ({"invalid" : "ok" })
52+ LicenseClarityThresholdsPolicy ({"invalid" : "ok" })
5353 self .assertIn ("must be integers" , str (cm .exception ))
5454
5555 def test_invalid_alert_value_raises_error (self ):
5656 with self .assertRaises (ValidationError ) as cm :
57- ClarityThresholdsPolicy ({80 : "invalid" })
57+ LicenseClarityThresholdsPolicy ({80 : "invalid" })
5858 self .assertIn ("must be one of 'ok', 'warning', 'error'" , str (cm .exception ))
5959
6060 def test_non_dict_input_raises_error (self ):
6161 with self .assertRaises (ValidationError ) as cm :
62- ClarityThresholdsPolicy ([80 , 50 ])
62+ LicenseClarityThresholdsPolicy ([80 , 50 ])
6363 self .assertIn ("must be a dictionary" , str (cm .exception ))
6464
6565 def test_duplicate_threshold_keys_raise_error (self ):
6666 with self .assertRaises (ValidationError ) as cm :
67- ClarityThresholdsPolicy ({80 : "ok" , "80" : "warning" })
67+ LicenseClarityThresholdsPolicy ({80 : "ok" , "80" : "warning" })
6868 self .assertIn ("Duplicate threshold key" , str (cm .exception ))
6969
7070 def test_overlapping_thresholds_wrong_order (self ):
7171 with self .assertRaises (ValidationError ) as cm :
72- ClarityThresholdsPolicy ({70 : "ok" , 80 : "warning" })
72+ LicenseClarityThresholdsPolicy ({70 : "ok" , 80 : "warning" })
7373 self .assertIn ("Thresholds must be strictly descending" , str (cm .exception ))
7474
7575 def test_float_threshold_keys (self ):
7676 thresholds = {80.5 : "ok" , 50.9 : "warning" }
77- policy = ClarityThresholdsPolicy (thresholds )
77+ policy = LicenseClarityThresholdsPolicy (thresholds )
7878 expected = {80 : "ok" , 50 : "warning" }
7979 self .assertEqual (policy .thresholds , expected )
8080
8181 def test_negative_threshold_values (self ):
8282 thresholds = {50 : "ok" , 0 : "warning" , - 10 : "error" }
83- policy = ClarityThresholdsPolicy (thresholds )
83+ policy = LicenseClarityThresholdsPolicy (thresholds )
8484 self .assertEqual (policy .get_alert_for_score (60 ), "ok" )
8585 self .assertEqual (policy .get_alert_for_score (25 ), "warning" )
8686 self .assertEqual (policy .get_alert_for_score (- 5 ), "error" )
8787 self .assertEqual (policy .get_alert_for_score (- 20 ), "error" )
8888
8989 def test_empty_thresholds_dict (self ):
90- policy = ClarityThresholdsPolicy ({})
90+ policy = LicenseClarityThresholdsPolicy ({})
9191 self .assertEqual (policy .get_alert_for_score (100 ), "error" )
9292 self .assertEqual (policy .get_alert_for_score (50 ), "error" )
9393 self .assertEqual (policy .get_alert_for_score (0 ), "error" )
9494 self .assertEqual (policy .get_alert_for_score (None ), "error" )
9595
9696 def test_very_high_threshold_values (self ):
9797 thresholds = {150 : "ok" , 100 : "warning" }
98- policy = ClarityThresholdsPolicy (thresholds )
98+ policy = LicenseClarityThresholdsPolicy (thresholds )
9999 self .assertEqual (policy .get_alert_for_score (100 ), "warning" )
100100 self .assertEqual (policy .get_alert_for_score (90 ), "error" )
101101 self .assertEqual (policy .get_alert_for_score (50 ), "error" )
@@ -108,7 +108,7 @@ def test_yaml_string_ok_and_warning(self):
108108 90: ok
109109 30: warning
110110"""
111- policy = load_thresholds_from_yaml (yaml_content , ClarityThresholdsPolicy )
111+ policy = load_thresholds_from_yaml (yaml_content , LicenseClarityThresholdsPolicy )
112112 self .assertEqual (policy .get_alert_for_score (95 ), "ok" )
113113 self .assertEqual (policy .get_alert_for_score (60 ), "warning" )
114114 self .assertEqual (policy .get_alert_for_score (20 ), "error" )
@@ -118,7 +118,7 @@ def test_yaml_string_single_threshold(self):
118118license_clarity_thresholds:
119119 80: ok
120120"""
121- policy = load_thresholds_from_yaml (yaml_content , ClarityThresholdsPolicy )
121+ policy = load_thresholds_from_yaml (yaml_content , LicenseClarityThresholdsPolicy )
122122 self .assertEqual (policy .get_alert_for_score (90 ), "ok" )
123123 self .assertEqual (policy .get_alert_for_score (79 ), "error" )
124124
@@ -128,42 +128,42 @@ def test_yaml_string_invalid_alert(self):
128128 80: great
129129"""
130130 with self .assertRaises (ValidationError ):
131- load_thresholds_from_yaml (yaml_content , ClarityThresholdsPolicy )
131+ load_thresholds_from_yaml (yaml_content , LicenseClarityThresholdsPolicy )
132132
133133 def test_yaml_string_invalid_key (self ):
134134 yaml_content = """
135135license_clarity_thresholds:
136136 eighty: ok
137137"""
138138 with self .assertRaises (ValidationError ):
139- load_thresholds_from_yaml (yaml_content , ClarityThresholdsPolicy )
139+ load_thresholds_from_yaml (yaml_content , LicenseClarityThresholdsPolicy )
140140
141141 def test_yaml_string_missing_key (self ):
142142 yaml_content = """
143143license_policies:
144144 - license_key: mit
145145"""
146146 with self .assertRaises (ValidationError ):
147- load_thresholds_from_yaml (yaml_content , ClarityThresholdsPolicy )
147+ load_thresholds_from_yaml (yaml_content , LicenseClarityThresholdsPolicy )
148148
149149 def test_yaml_string_invalid_yaml (self ):
150150 yaml_content = "license_clarity_thresholds: [80, 50"
151151 with self .assertRaises (ValidationError ):
152- load_thresholds_from_yaml (yaml_content , ClarityThresholdsPolicy )
152+ load_thresholds_from_yaml (yaml_content , LicenseClarityThresholdsPolicy )
153153
154154 def test_load_from_existing_file (self ):
155155 test_file = (
156156 self .data / "compliance-thresholds" / "clarity_sample_thresholds.yml"
157157 )
158- policy = load_thresholds_from_file (test_file , ClarityThresholdsPolicy )
158+ policy = load_thresholds_from_file (test_file , LicenseClarityThresholdsPolicy )
159159 self .assertIsNotNone (policy )
160160 self .assertEqual (policy .get_alert_for_score (95 ), "ok" )
161161 self .assertEqual (policy .get_alert_for_score (75 ), "warning" )
162162 self .assertEqual (policy .get_alert_for_score (50 ), "error" )
163163
164164 def test_load_from_nonexistent_file (self ):
165165 policy = load_thresholds_from_file (
166- "/nonexistent/file.yml" , ClarityThresholdsPolicy
166+ "/nonexistent/file.yml" , LicenseClarityThresholdsPolicy
167167 )
168168 self .assertIsNone (policy )
169169
0 commit comments