Exemplo n.º 1
0
        class FlowWithCommon(MockFlow):
            common = {'pipe_target': PipeTo('wrong_field')}

            blocks = (create_writer_block(inject_name='wrong_field',
                                          inject_value='wrong_value').params(
                wrong_field='wrong_value'),  # To pass input validation
                      create_writer_block(inject_name='some_name',
                                          inject_value='some_value'),
                      create_reader_block(inject_name='pipe_target',
                                          inject_value='some_value').params(
                          pipe_target='some_value'))
Exemplo n.º 2
0
    def test_sub_flow_propagating_share(self):
        """Test behavior of the common object in sub-flow.

        * Check that fields shared in the upper flow are available to all.
        * Check that fields shared in sub-flow are not available in the top.
        """
        upper_field_name = 'upper_field'
        upper_field_value = 'some_value1'

        sub_field_name = 'sub_field'
        sub_field_value = 'some_value2'

        UpperWritingBlock = create_writer_block(inject_name=upper_field_name,
                                                inject_value=upper_field_value)

        SubWritingBlock = create_writer_block(inject_name=sub_field_name,
                                              inject_value=sub_field_value)

        class UpperCheckingBlock(AttributeCheckingBlock):
            ATTRIBUTE_NAME = upper_field_name

        class SubCheckingBlock(AttributeCheckingBlock):
            ATTRIBUTE_NAME = sub_field_name

        class FailingSubCheckingBlock(MockBlock):
            ATTRIBUTE_NAME = sub_field_name

            def test_attr_doesnt_exists(self):
                self.assertFalse(hasattr(self, self.ATTRIBUTE_NAME))

        MockSubFlow.blocks = (FailingSubCheckingBlock,  # Not injected yet
                              UpperCheckingBlock,  # Injected from upper
                              SubWritingBlock,
                              SubCheckingBlock)

        class MainFlow(MockFlow):
            blocks = (UpperWritingBlock,
                      MockSubFlow,
                      FailingSubCheckingBlock)  # Not available in upper

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

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

        self.validate_blocks(test_flow, successes=3)
Exemplo n.º 3
0
    def test_shared_data_priority(self):
        """Test that shared data has higher priority than default values."""
        MockFlow.blocks = (create_writer_block(inject_value='some_value'),
                           create_reader_block(inject_value='some_value',
                                               default='default_value'))

        test_flow = MockFlow()
        self.run_test(test_flow)

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

        self.validate_blocks(test_flow, successes=2)
Exemplo n.º 4
0
    def test_pipes_happy_flow(self):
        """Validate parametrize behavior when using pipes."""
        MockFlow.blocks = (
            create_writer_block(inject_name='some_name'),
            create_reader_block(inject_name='pipe_target').params(
                pipe_target=PipeTo('some_name')))

        test_flow = MockFlow()
        self.run_test(test_flow)

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

        self.validate_blocks(test_flow, successes=2)
Exemplo n.º 5
0
    def test_inputs_happy_flow(self):
        """Test behavior of inputs validation of blocks in positive case.

        * The flow locks a resource.
        * It's first block shares a value.
        * The second block validates it has both the result and the shared
            value using the 'inputs' field.
        """
        MockFlow.blocks = (create_writer_block(inject_value='some_value'),
                           create_reader_block(inject_value='some_value'))

        test_flow = MockFlow()
        self.run_test(test_flow)

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

        self.validate_blocks(test_flow, successes=2)
Exemplo n.º 6
0
    def test_pipes_in_common(self):
        """Validate parametrize behavior when using pipes in common."""
        ReadingBlock = create_reader_block(inject_name='pipe_target',
                                           inject_value=5)
        # The params is just so the input validation can find the piped field
        WritingBlock = create_writer_block(inject_name='some_name',
                                           inject_value=5).params(some_name=3)

        class FlowWithCommon(MockFlow):
            common = {'pipe_target': PipeTo('some_name')}

            blocks = (WritingBlock, ReadingBlock)

        test_flow = FlowWithCommon()
        self.run_test(test_flow)

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

        self.validate_blocks(test_flow, successes=2)
Exemplo n.º 7
0
        class FlowWithCommon(MockFlow):
            common = {'pipe_target': 'wrong_value'}

            blocks = (create_writer_block(inject_name='some_name'),
                      create_reader_block(inject_name='pipe_target').params(
                          pipe_target=PipeTo('some_name')))