File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
vulnerabilities/tests/pipelines Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1919from vulnerabilities .importer import AffectedPackage
2020from vulnerabilities .importer import Reference
2121from vulnerabilities .pipelines import VulnerableCodeBaseImporterPipeline
22+ from vulnerabilities .pipelines import VulnerableCodePipeline
23+ from vulnerabilities .tests .pipelines import TestLogger
2224
2325advisory_data1 = AdvisoryData (
2426 aliases = ["CVE-2020-13371337" ],
@@ -47,6 +49,33 @@ def get_advisory1(created_by="test_pipeline"):
4749 )
4850
4951
52+ class TestVulnerableCodePipeline (TestCase ):
53+ def test_on_failure (self ):
54+ class TestPipeline (VulnerableCodePipeline ):
55+ def __init__ (self , test_logger ):
56+ super ().__init__ ()
57+ self .log = test_logger .write
58+
59+ @classmethod
60+ def steps (cls ):
61+ return (cls .step1 ,)
62+
63+ def step1 (self ):
64+ raise Exception ("Something went wrong!" )
65+
66+ def on_failure (self ):
67+ self .log ("Doing cleanup." )
68+
69+ logger = TestLogger ()
70+ pipeline = TestPipeline (test_logger = logger )
71+
72+ pipeline .execute ()
73+ log_result = logger .getvalue ()
74+
75+ self .assertIn ("Pipeline failed" , log_result )
76+ self .assertIn ("Running [on_failure] tasks" , log_result )
77+
78+
5079class TestVulnerableCodeBaseImporterPipeline (TestCase ):
5180 @patch .object (
5281 VulnerableCodeBaseImporterPipeline ,
You can’t perform that action at this time.
0 commit comments