示例#1
0
    def test_make_context_attribute_based_templating_function_when_values_do_not_match_and_notify_user_is_false(
            self):
        apply_object_attributes_to_template_patcher = patch(
            'autotrail.helpers.step.apply_object_attributes_to_template',
            return_value='mock return')
        mock_apply_object_attributes_to_template = apply_object_attributes_to_template_patcher.start(
        )
        trail_env = MagicMock()
        trail_env.output = MagicMock()
        context = MagicMock()
        context.mock_attribute = MagicMock(return_value='expected value 1')

        templating_function = make_context_attribute_based_templating_function(
            'mock_attribute',
            'mock instruction using {value}',
            expected_value='expected value 2',
            notify_user=False)
        return_value = templating_function(trail_env, context)

        self.assertEqual(mock_apply_object_attributes_to_template.call_count,
                         0)
        self.assertEqual(return_value, None)
        self.assertEqual(len(trail_env.mock_calls), 0)

        apply_object_attributes_to_template_patcher.stop()
示例#2
0
    def test_make_context_attribute_based_templating_function_with_default_expected_value(
            self):
        apply_object_attributes_to_template_patcher = patch(
            'autotrail.helpers.step.apply_object_attributes_to_template',
            return_value='mock return')
        mock_apply_object_attributes_to_template = apply_object_attributes_to_template_patcher.start(
        )
        trail_env = MagicMock()
        context = MagicMock()
        context.mock_attribute = True

        templating_function = make_context_attribute_based_templating_function(
            'mock_attribute', 'mock instruction using {value}')
        return_value = templating_function(trail_env, context)

        mock_apply_object_attributes_to_template.assert_called_once_with(
            'mock instruction using {value}', context)
        self.assertEqual(return_value, 'mock return')
        self.assertEqual(len(trail_env.mock_calls), 0)

        apply_object_attributes_to_template_patcher.stop()