コード例 #1
0
    def assert_context_contains(self,
                                template_name,
                                data_key,
                                data_value,
                                expected_context=None):
        """Verify that FormattingLayer converts the `data` elements into a
        context variable similar to `expect_context`. If `expected_context` is
        not provided, assume that it should match `data_value`"""
        if expected_context is None:
            expected_context = dict(data_value)
        template_file = template_loc.format(template_name)
        with patch('regulations.generator.layers.formatting.loader') as ldr:
            # we will want to reference these templates later
            templates = defaultdict(Mock)
            ldr.get_template.side_effect = templates.__getitem__
            fl = FormattingLayer({})
            # materialize
            next(fl.replacements_for('', {data_key: data_value}))
            render = templates[template_file].render

        self.assertTrue(render.called)
        context = render.call_args[0][0]
        for key, value in expected_context.items():
            self.assertTrue(key in context)
            self.assertEqual(context[key], value)
コード例 #2
0
    def assert_context_contains(self, template_name, data_key, data_value,
                                expected_context=None):
        """Verify that FormattingLayer converts the `data` elements into a
        context variable similar to `expect_context`. If `expected_context` is
        not provided, assume that it should match `data_value`"""
        if expected_context is None:
            expected_context = dict(data_value)
        template_file = template_loc.format(template_name)
        with patch('regulations.generator.layers.formatting.loader') as ldr:
            # we will want to reference these templates later
            templates = defaultdict(Mock)
            ldr.get_template.side_effect = templates.__getitem__
            fl = FormattingLayer({})
            # materialize
            next(fl.replacements_for('', {data_key: data_value}))
            render = templates[template_file].render

        self.assertTrue(render.called)
        context = render.call_args[0][0]
        for key, value in expected_context.items():
            self.assertTrue(key in context)
            self.assertEqual(context[key], value)