How to use test_soft_fail method in assertpy

Best Python code snippet using assertpy_python

test_get_exit_code.py

Source:test_get_exit_code.py Github

copy

Full Screen

1import unittest2from checkov.common.bridgecrew.severities import BcSeverities, Severities3from checkov.common.models.enums import CheckResult4from checkov.common.output.report import Report5from checkov.common.output.record import Record6class TestGetExitCode(unittest.TestCase):7 def test_get_exit_code(self):8 record1 = Record(check_id='CKV_AWS_157',9 bc_check_id='BC_AWS_157',10 check_name="Some RDS check", check_result={"result": CheckResult.FAILED},11 code_block=None, file_path="./rds.tf",12 file_line_range='1:3',13 resource='aws_db_instance.sample', evaluations=None,14 check_class=None, file_abs_path=',.',15 severity=Severities[BcSeverities.LOW],16 entity_tags={17 'tag1': 'value1'18 })19 record2 = Record(check_id='CKV_AWS_16',20 bc_check_id='BC_AWS_16',21 check_name="Another RDS check",22 check_result={"result": CheckResult.FAILED},23 code_block=None, file_path="./rds.tf",24 file_line_range='1:3',25 resource='aws_db_instance.sample', evaluations=None,26 check_class=None, file_abs_path=',.',27 severity=Severities[BcSeverities.HIGH],28 entity_tags={29 'tag1': 'value1'30 })31 record3 = Record(check_id='CKV_AWS_161',32 bc_check_id='BC_AWS_161',33 check_name="Another RDS check",34 check_result={"result": CheckResult.PASSED},35 code_block=None, file_path="./rds.tf",36 file_line_range='1:3',37 resource='aws_db_instance.sample', evaluations=None,38 check_class=None, file_abs_path=',.',39 severity=Severities[BcSeverities.LOW],40 entity_tags={41 'tag1': 'value1'42 })43 record4 = Record(check_id='CKV_AWS_118',44 bc_check_id='BC_AWS_118',45 check_name="Another RDS check",46 check_result={"result": CheckResult.PASSED},47 code_block=None, file_path="./rds.tf",48 file_line_range='1:3',49 resource='aws_db_instance.sample', evaluations=None,50 check_class=None, file_abs_path=',.',51 severity=Severities[BcSeverities.HIGH],52 entity_tags={53 'tag1': 'value1'54 })55 r = Report("terraform")56 r.add_record(record1)57 r.add_record(record2)58 r.add_record(record3)59 r.add_record(record4)60 # When soft_fail=True, the exit code should always be 0.61 test_default = r.get_exit_code(soft_fail=False, soft_fail_on=None, hard_fail_on=None)62 test_soft_fail = r.get_exit_code(soft_fail=True, soft_fail_on=None, hard_fail_on=None)63 # When soft_fail_on=['check1', 'check2'], exit code should be 0 if the only failing checks are in the64 # soft_fail_on list65 positive_test_soft_fail_on_code = r.get_exit_code(None, soft_fail_on=['CKV_AWS_157', 'CKV_AWS_16'],66 hard_fail_on=None)67 positive_test_soft_fail_on_code_one_sev = r.get_exit_code(None, soft_fail_on=['LOW', 'CKV_AWS_16'],68 hard_fail_on=None)69 positive_test_soft_fail_on_code_two_sev = r.get_exit_code(None, soft_fail_on=['LOW', 'HIGH'],70 hard_fail_on=None)71 positive_test_soft_fail_on_code_bc_id = r.get_exit_code(None, soft_fail_on=['BC_AWS_157', 'BC_AWS_16'],72 hard_fail_on=None)73 negative_test_soft_fail_on_code = r.get_exit_code(None, soft_fail_on=['CKV_AWS_157'], hard_fail_on=None)74 negative_test_soft_fail_on_code_one_sev = r.get_exit_code(None, soft_fail_on=['LOW'], hard_fail_on=None)75 negative_test_soft_fail_on_code_bc_id = r.get_exit_code(None, soft_fail_on=['BC_AWS_157'], hard_fail_on=None)76 positive_test_soft_fail_on_wildcard_code = r.get_exit_code(None, soft_fail_on=['CKV_AWS*'])77 positive_test_soft_fail_on_wildcard_code_bc_id = r.get_exit_code(None, soft_fail_on=['BC_AWS*'])78 negative_test_soft_fail_on_wildcard_code = r.get_exit_code(None, soft_fail_on=['CKV_OTHER*'])79 negative_test_soft_fail_on_wildcard_code_bc_id = r.get_exit_code(None, soft_fail_on=['BC_OTHER*'])80 # When hard_fail_on=['check1', 'check2'], exit code should be 1 if any checks in the hard_fail_on list fail81 positive_test_hard_fail_on_code = r.get_exit_code(None, soft_fail_on=None, hard_fail_on=['CKV_AWS_157'])82 positive_test_hard_fail_on_code_one_sev = r.get_exit_code(None, soft_fail_on=None, hard_fail_on=['LOW'])83 positive_test_hard_fail_on_code_bc_id = r.get_exit_code(None, soft_fail_on=None, hard_fail_on=['BC_AWS_157'])84 negative_test_hard_fail_on_code = r.get_exit_code(None, soft_fail_on=None,85 hard_fail_on=['CKV_AWS_161', 'CKV_AWS_118'])86 negative_test_hard_fail_on_code_bc_id = r.get_exit_code(None, soft_fail_on=None,87 hard_fail_on=['BC_AWS_161', 'BC_AWS_118'])88 combined_test_soft_fail_sev_hard_fail_id = r.get_exit_code(None, soft_fail_on=['LOW', 'CKV_AWS_16'], hard_fail_on=['CKV_AWS_157'])89 combined_test_soft_fail_id_hard_fail_sev = r.get_exit_code(None, soft_fail_on=['CKV_AWS_16'], hard_fail_on=['HIGH'])90 combined_test_soft_fail_id_hard_fail_sev_fail = r.get_exit_code(True, soft_fail_on=['CKV_AWS_16'], hard_fail_on=['HIGH'])91 self.assertEqual(test_default, 1)92 self.assertEqual(test_soft_fail, 0)93 self.assertEqual(positive_test_soft_fail_on_code, 0)94 self.assertEqual(positive_test_soft_fail_on_code_one_sev, 0)95 self.assertEqual(positive_test_soft_fail_on_code_two_sev, 0)96 self.assertEqual(positive_test_soft_fail_on_code_bc_id, 0)97 self.assertEqual(negative_test_soft_fail_on_code, 1)98 self.assertEqual(negative_test_soft_fail_on_code_one_sev, 1)99 self.assertEqual(negative_test_soft_fail_on_code_bc_id, 1)100 self.assertEqual(positive_test_soft_fail_on_wildcard_code, 0)101 self.assertEqual(positive_test_soft_fail_on_wildcard_code_bc_id, 0)102 self.assertEqual(negative_test_soft_fail_on_wildcard_code, 1)103 self.assertEqual(negative_test_soft_fail_on_wildcard_code_bc_id, 1)104 self.assertEqual(positive_test_hard_fail_on_code, 1)105 self.assertEqual(positive_test_hard_fail_on_code_one_sev, 1)106 self.assertEqual(positive_test_hard_fail_on_code_bc_id, 1)107 self.assertEqual(negative_test_hard_fail_on_code, 0)108 self.assertEqual(negative_test_hard_fail_on_code_bc_id, 0)109 self.assertEqual(combined_test_soft_fail_sev_hard_fail_id, 1)110 self.assertEqual(combined_test_soft_fail_id_hard_fail_sev, 1)111 self.assertEqual(combined_test_soft_fail_id_hard_fail_sev_fail, 0)112if __name__ == '__main__':...

Full Screen

Full Screen

test_soft_fail.py

Source:test_soft_fail.py Github

copy

Full Screen

...45 ],46 ),47 ],48)49def test_soft_fail(empty_transition_history, ticker, max_fail_count, transitions):50 soft_fail = SoftFail(max_fail_count)51 history = empty_transition_history52 history.insert(next(ticker), State.OK)53 ts: Timestamp54 state: State55 expected: State56 for (ts, (state, expected)) in zip(ticker, transitions):57 history.insert(ts, state)58 processed_state = soft_fail.process("metric", state, ts, history)59 logger.info(f"ts={ts}, state={state}, processed_state={processed_state}")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful