@@ -1187,6 +1187,48 @@ def test_scanpipe_management_command_check_compliance(self):
11871187 )
11881188 self .assertEqual (expected , out_value )
11891189
1190+ def test_scanpipe_management_command_check_clarity_compliance_only (self ):
1191+ project = Project .objects .create (name = "my_project_clarity" )
1192+
1193+ project .extra_data = {"clarity_compliance_alert" : "error" }
1194+ project .save (update_fields = ["extra_data" ])
1195+
1196+ out = StringIO ()
1197+ options = ["--project" , project .name ]
1198+ with self .assertRaises (SystemExit ) as cm :
1199+ call_command ("check-compliance" , * options , stderr = out )
1200+ self .assertEqual (cm .exception .code , 1 )
1201+ out_value = out .getvalue ().strip ()
1202+ expected = (
1203+ "1 compliance issues detected on this project."
1204+ "\n [License Clarity Compliance]\n > Alert Level: error"
1205+ )
1206+ self .assertEqual (expected , out_value )
1207+
1208+ def test_scanpipe_management_command_check_both_compliance_and_clarity (self ):
1209+ project = Project .objects .create (name = "my_project_both" )
1210+
1211+ make_package (
1212+ project ,
1213+ package_url = "pkg:generic/[email protected] " ,
1214+ compliance_alert = CodebaseResource .Compliance .ERROR ,
1215+ )
1216+ project .extra_data = {"clarity_compliance_alert" : "warning" }
1217+ project .save (update_fields = ["extra_data" ])
1218+
1219+ out = StringIO ()
1220+ options = ["--project" , project .name , "--fail-level" , "WARNING" ]
1221+ with self .assertRaises (SystemExit ) as cm :
1222+ call_command ("check-compliance" , * options , stderr = out )
1223+ self .assertEqual (cm .exception .code , 1 )
1224+ out_value = out .getvalue ().strip ()
1225+ expected = (
1226+ "2 compliance issues detected on this project."
1227+ "\n [packages]\n > ERROR: 1"
1228+ "\n [License Clarity Compliance]\n > Alert Level: warning"
1229+ )
1230+ self .assertEqual (expected , out_value )
1231+
11901232 def test_scanpipe_management_command_report (self ):
11911233 project1 = make_project ("project1" )
11921234 label1 = "label1"
0 commit comments