def test_hello_world_and(self): # First set the condition to true so we see Hello World! in the out put. actionPass = SampleOutAction( "I have a true action condition... Hello World!") actionPass.addAndCondition(SampleCondition(True)) Engine(actions=[actionPass], data=EngineData()).execute() # output: I have a true action condition... Hello World! # Now we set the condition to false to prevent SampleAction from execution. actionFail = SampleOutAction("I have a false condition...") actionFail.addAndCondition(SampleCondition(False)) Engine(actions=[actionFail], data=EngineData()).execute() # No output. # Now back to true but with a EnginePipeline condition set to false. actionFailWithGeneralCondition1 = SampleOutAction( "I have a true action condition but a false pipeline condition...") actionFailWithGeneralCondition1.addAndCondition(SampleCondition(True)) Engine(actions=[actionFailWithGeneralCondition1], data=EngineData(), ands=[SampleCondition(False)]).execute() # No output. # Now back to true but with a EnginePipeline condition set to true. actionFailWithGeneralCondition2 = SampleOutAction( "I have a true action condition and a true pipeline condition... Hello World!" ) actionFailWithGeneralCondition2.addAndCondition(SampleCondition(True)) Engine(actions=[actionFailWithGeneralCondition2], data=EngineData(), ands=[SampleCondition(True)]).execute()
def test_hello_world_or(self): # First set one condition true and one false... actionPass = SampleOutAction( "I have 2 conditions true and false... Hello World!") actionPass.addOrCondition(SampleCondition(True)).addOrCondition( SampleCondition(True)) Engine(actions=[actionPass], data=EngineData()).execute() # output: I have 2 conditions true and false... Hello World! # Then we set both conditions false actionFail = SampleOutAction( "I have 2 conditions false and false... Hello World!") actionFail.addOrCondition(SampleCondition(False)).addOrCondition( SampleCondition(False)) Engine(actions=[actionFail], data=EngineData()).execute() # No output. # Then we set both conditions false, and we pass a pipeline true condition... actionPassWithGeneralCondition = SampleOutAction( "I have 2 conditions false and false, with a true pipeline condition... Hello World!" ) actionPassWithGeneralCondition.addOrCondition( SampleCondition(False)).addOrCondition(SampleCondition(False)) Engine(actions=[actionPassWithGeneralCondition], data=EngineData(), ors=[SampleCondition(True)]).execute()
def test_engine_pipeline_TrueFalse_2actions_fail(self): d = self.d() Engine(actions=[self.a1(), self.a2()], data=d, ands=[self.f(), self.t()]).execute() assert d.get("key1") is None assert d.get("key2") is None
def test_TrueFalseOrs_pass(self): a1 = self.a1().addOrCondition(self.t()).addOrCondition(self.f()) a2 = self.a2().addOrCondition(self.t()).addOrCondition(self.f()) data = self.d() Engine(actions=[a1, a2], data=data).execute() assert data.get("key1") == "one" assert data.get("key2") == "two"
def test_TrueTrueOrs_TrueFalseAnds_fails(self): d = self.d() a1 = self.a1() a1.addOrCondition(self.t()).addOrCondition(self.t()).addAndCondition( self.t()).addAndCondition(self.f()) Engine(actions=[a1], data=d).execute() assert d.get("key1") is None
def test_FalseOrCondition_fail(self): a1 = self.a1().addOrCondition(self.f()) a2 = self.a2().addOrCondition(self.f()) data = self.d() Engine(actions=[a1, a2], data=data).execute() assert data.get("key1") is None assert data.get("key2") is None
def test_FalseFalse_FalseTrue_Ors_Condition_2actions_fail_pass(self): a1 = self.a1().addOrCondition(self.f()).addOrCondition(self.f()) a2 = self.a2().addOrCondition(self.f()).addOrCondition(self.t()) data = self.d() Engine(actions=[a1, a2], data=data).execute() assert data.get("key1") is None assert data.get("key2") == "two"
def test_TrueFalseAndCondition_2actions_1pass_2fail(self): a1 = self.a1().addAndCondition(self.t()).addAndCondition(self.t()) a2 = self.a2().addAndCondition(self.f()).addAndCondition(self.t()) data = self.d() Engine(actions=[a1, a2], data=data).execute() assert data.get("key1") == "one" assert data.get("key2") is None
def test_engine_pipeline_pass(self): d = self.d() Engine(actions=[self.a1(), self.a2(), self.a3()], data=d, ands=[self.f(), self.t()]).execute() assert d.get("key1") is None assert d.get("key2") is None assert d.get("key3") is None
def test_engine_pipeline_TrueFalseOr_TrueTrueAnd_2actions_pass(self): d = self.d() Engine(actions=[self.a1(), self.a2()], data=d, ors=[self.f(), self.t()], ands=[self.t(), self.t()]).execute() assert d.get("key1") == "one" assert d.get("key2") == "two"
def test_NullEngineData_fail(self): result = None try: Engine(actions=SampleAction("key1", "one"), data=None) except Exception as e: result = e finally: assert isinstance(result, Exception)
def test_EmptyActions_fail(self): result = None try: Engine(actions=[], data=EngineData()) except Exception as e: result = e finally: assert isinstance(result, EngineException)
def test_engine_pipeline_fail_pass_fail(self): d = self.d() a2 = self.a2().addOrCondition(self.t()) Engine(actions=[self.a1(), a2, self.a3()], data=d, ors=[self.f()], ands=[self.t()]).execute() assert d.get("key1") is None assert d.get("key2") == "two" assert d.get("key3") is None
def test_engine_pipeline_fail_fail_pass(self): d = self.d() a1 = self.a1().addOrCondition(self.t()).addAndCondition(self.f()) a2 = self.a2().addOrCondition(self.t()).addAndCondition(self.f()) a3 = self.a3().addOrCondition(self.t()) Engine(actions=[a1, a2, a3], data=d, ors=[self.f()], ands=[self.t()]).execute() assert d.get("key1") is None assert d.get("key2") is None assert d.get("key3") == "three"
def test_allTogether(self): d = self.d() a1 = self.a1() a1 = self.a1().addOrCondition(self.t()).addOrCondition( self.t()).addAndCondition(self.t()).addAndCondition(self.f()) a2 = self.a2().addOrCondition(self.t()).addOrCondition( self.f()).addAndCondition(self.t()) a3 = self.a3().addAndCondition(self.f()) Engine(actions=[a1, a2, a3], data=d).execute() assert d.get("key1") is None assert d.get("key2") == "two" assert d.get("key3") is None
def test_engine_pipeline_True_pass(self): d = self.d() Engine(actions=[self.a1()], data=d, ands=[self.t()]).execute() assert d.get("key1") == "one"
def test_NoConditions_pass(self): data = EngineData() Engine(actions=[self.a1(), self.a2()], data=data).execute() assert data.get("key1") == "one" assert data.get("key2") == "two"
def test_helloWorld(self): Engine(actions=[SampleOutAction(content="Hello World!")], data=EngineData()).execute()
def test_FalseAnd_general_TrueOr_TrueAnd_fail(self): d = self.d() a1 = self.a1().addAndCondition(self.f()) Engine(actions=[a1], data=d, ors=[self.t()], ands=[self.t()]).execute() assert d.get("key1") is None
def test_TrueOr_general_FalseOr_TrueAnd_pass(self): d = self.d() a1 = self.a1().addOrCondition(self.t()) Engine(actions=[a1], data=d, ors=[self.f()], ands=[self.t()]).execute() assert d.get("key1") == "one"
def test_engine_pipeline_False_fail(self): d = self.d() Engine(actions=[self.a1()], data=d, ors=[self.f()]).execute() assert d.get("key1") is None