Beispiel #1
0
    def test_finally_flow(self):
        """Validate behavior of flow in FINALLY mode.

        We check that finally flows run despite other's failure.
        """
        MockSubFlow.blocks = (SuccessBlock.params(mode=MODE_CRITICAL),)
        MockFlow.blocks = (SuccessBlock.params(mode=MODE_CRITICAL),
                           FailureBlock.params(mode=MODE_CRITICAL),
                           MockSubFlow.params(mode=MODE_FINALLY),
                           MockSubFlow.params(mode=MODE_CRITICAL),
                           MockSubFlow.params(mode=MODE_OPTIONAL))

        test_flow = MockFlow()
        self.run_test(test_flow)

        self.assertFalse(self.result.wasSuccessful(),
                         'Flow succeeded when it should have failed')

        self.assertEqual(self.result.testsRun, 1,
                         "Result didn't run the correct number of tests")

        self.assertEqual(len(self.result.failures), 1,
                         "Result didn't fail the correct number of tests")

        self.validate_blocks(test_flow, successes=2, failures=1, skips=2)

        # === Validate data object ===
        self.assertFalse(test_flow.data.success,
                         'Flow data result should have been False')

        self.assertEqual(test_flow.data.exception_type, TestOutcome.FAILED,
                         'Flow data status should have been failure')
Beispiel #2
0
    def test_sub_flow_inputs(self):
        """Test behavior of inputs validation of sub-flows in positive case.

        * First propagating parameter = resource from the upper flow's request.
        * Second propagating parameter = initial common data field.
        * Third propagating parameter = field injected to the sub-flow using
            'parametrize'.
        * The block validates it gets all three parameters.
        """
        FLOW_PARAMETER_NAME = 'some_parameter1'
        COMMON_PARAMETER_NAME = 'some_parameter2'

        FLOW_PARAMETER_VALUE = 'some_value1'
        COMMON_PARAMETER_VALUE = 'some_value2'

        class ResourceCheckingBlock(AttributeCheckingBlock):
            res1 = BlockInput()
            ATTRIBUTE_NAME = 'res1'

        class CommonCheckingBlock(AttributeCheckingBlock):
            ATTRIBUTE_NAME = COMMON_PARAMETER_NAME

        setattr(CommonCheckingBlock, COMMON_PARAMETER_NAME, BlockInput())

        class ParametrizeCheckingBlock(AttributeCheckingBlock):
            ATTRIBUTE_NAME = FLOW_PARAMETER_NAME

        setattr(ParametrizeCheckingBlock, FLOW_PARAMETER_NAME, BlockInput())

        MockSubFlow.blocks = (ResourceCheckingBlock,
                              CommonCheckingBlock,
                              ParametrizeCheckingBlock)

        class MainFlow(MockFlow):
            blocks = (MockSubFlow,)

        # No flow parameter and no common parameter
        with self.assertRaises(AttributeError):
            MainFlow()

        # Adding initial common field
        MainFlow.common = {COMMON_PARAMETER_NAME: COMMON_PARAMETER_VALUE}

        # No flow parameter
        with self.assertRaises(AttributeError):
            MainFlow()

        # Parametrizing the sub-flow
        MainFlow.blocks = (MockSubFlow.params(**{FLOW_PARAMETER_NAME:
                                                     FLOW_PARAMETER_VALUE}),)

        # Got all fields needed
        test_flow = MainFlow()

        self.run_test(test_flow)

        self.assertTrue(self.result.wasSuccessful(),
                        'Flow failed when it should have succeeded')

        self.validate_blocks(test_flow, successes=1)