Esempio n. 1
0
    def test_empty_placeholders_rendering(self):
        template = Template('dummy', [], '<style>p {color:red;}</style>',
                            '<body>{{content}}</body>', ['content'], None)
        r = renderer.HtmlRenderer(template, self.email_locale)
        placeholders = {'content': Placeholder('content', '')}

        actual = r.render(placeholders)
        self.assertEqual('<body></body>', actual)
Esempio n. 2
0
    def test_include_base_url(self):
        template = Template('dummy', [], '<style>body {}</style>',
                            '<body>{{base_url}}</body>', ['base_url'], None)
        placeholders = {}
        r = renderer.HtmlRenderer(template, self.email_locale)

        actual = r.render(placeholders)
        self.assertEqual('<body>images_base</body>', actual)
Esempio n. 3
0
    def test_empty_style(self):
        placeholders = {'content': Placeholder('content', 'dummy_content')}
        template = Template('dummy', [], '', '<body>{{content}}</body>',
                            ['content1'], None)
        r = renderer.HtmlRenderer(template, self.email_locale)

        actual = r.render(placeholders)
        self.assertEqual('<body><p>dummy_content</p></body>', actual)
Esempio n. 4
0
    def test_happy_path(self):
        placeholders = {'content1': Placeholder('content1', 'text1')}
        template = Template('dummy', [], '<style>body {}</style>',
                            '<body>{{content1}}</body>', ['content1'], None)
        r = renderer.HtmlRenderer(template, self.email_locale)

        actual = r.render(placeholders)
        self.assertEqual('<body><p>text1</p></body>', actual)
Esempio n. 5
0
    def test_inline_styles(self):
        template = Template('dummy', [], '<style>p {color:red;}</style>',
                            '<body>{{content}}</body>', ['content'], None)
        r = renderer.HtmlRenderer(template, self.email_locale)
        placeholders = {'content': Placeholder('content', 'dummy_content')}

        actual = r.render(placeholders)
        self.assertEqual(
            '<body><p style="color: red">dummy_content</p></body>', actual)
Esempio n. 6
0
    def test_fail_on_missing_placeholders(self):
        template = Template('dummy', [], '<style>body {}</style>',
                            '<body>{{content}}{{missing}}</body>',
                            ['content', 'missing'], None)
        r = renderer.HtmlRenderer(template, self.email_locale)
        placeholders = {'content': Placeholder('content', 'dummy_content')}

        with self.assertRaises(MissingTemplatePlaceholderError):
            r.render(placeholders)
    def setUp(self):
        settings = cmd.default_settings()._asdict()
        settings['templates'] = 'dummy_templates'
        settings['images'] = 'dummy_images'
        self.settings = cmd.Settings(**settings)

        self.email = Email('name', 'locale', 'path', 'full_path')
        self.template = Template('template_name', ['template_style'])
        self.renderer = renderer.HtmlRenderer(self.template, self.settings,
                                              self.email)
Esempio n. 8
0
    def test_rtl_locale(self):
        email_locale = 'he'
        template = Template('dummy', [], '<style>body {}</style>',
                            '<body>{{content}}</body>', ['content'], None)
        r = renderer.HtmlRenderer(template, email_locale)
        placeholders = {'content': Placeholder('content', 'dummy_content')}

        actual = r.render(placeholders)
        self.assertEqual(
            '<body dir="rtl">\n <p>\n  dummy_content\n </p>\n</body>', actual)
Esempio n. 9
0
 def _get_renderer(self, template_html, template_placeholders, **kwargs):
     template = Template(
         name='template_name',
         styles_names=['template_style.css', 'template_style2.css'],
         styles='',
         content=template_html,
         placeholders=template_placeholders,
         type=None)
     return renderer.HtmlRenderer(
         template, kwargs.get('email_locale', const.DEFAULT_LOCALE))
    def test_ignore_missing_placeholders(self, mock_read):
        html = '<body>{{content}}{{missing}}</body>'
        placeholders = {'content': 'dummy_content'}
        mock_read.side_effect = iter(['', html])
        settings = self.settings._asdict()
        settings['strict'] = False
        settings = cmd.Settings(**settings)
        r = renderer.HtmlRenderer(self.template, settings, self.email)

        actual = r.render(placeholders)

        self.assertEqual('<body><p>dummy_content</p></body>', actual)
Esempio n. 11
0
    def test_variant(self):
        placeholders = {
            'content1': Placeholder('content1',
                                    'text1',
                                    variants={'B': 'text2'})
        }
        template = Template('dummy', [], '<style>body {}</style>',
                            '<body>{{content1}}</body>', ['content1'], None)
        r = renderer.HtmlRenderer(template, self.email_locale)

        actual = r.render(placeholders, variant='B')
        self.assertEqual('<body><p>text2</p></body>', actual)
    def test_rtl_locale(self, mock_read):
        html = '<body>{{content}}</body>'
        placeholders = {'content': 'dummy_content'}
        mock_read.side_effect = iter(['', html])
        email_dict = self.email._asdict()
        email_dict['locale'] = 'ar'
        r = renderer.HtmlRenderer(self.template, self.settings,
                                  Email(**email_dict))

        actual = r.render(placeholders)

        self.assertEqual(
            '<body dir="rtl">\n <p>\n  dummy_content\n </p>\n</body>', actual)
Esempio n. 13
0
    def test_rtl_two_placeholders(self):
        email_locale = 'ar'
        template = Template(
            'dummy', [], '<style>body {}</style>',
            '<body><div>{{content1}}</div><div>{{content2}}</div></body>',
            ['content1', 'content2'], None)
        r = renderer.HtmlRenderer(template, email_locale)
        placeholders = {
            'content1': Placeholder('content1', 'dummy_content1'),
            'content2': Placeholder('content2', 'dummy_content2')
        }

        actual = r.render(placeholders)
        expected = '<body dir="rtl">\n <div>\n  <p>\n   dummy_content1\n  </p>\n </div>\n <div>\n  <p>\n   dummy_content2\n  </p>\n </div>\
\n</body>'

        self.assertEqual(expected, actual)
    def test_rtl_two_placeholders(self, mock_read):
        html = '<body><div>{{content1}}</div><div>{{content2}}</div></body>'
        placeholders = {
            'content1': 'dummy_content1',
            'content2': 'dummy_content2'
        }
        mock_read.side_effect = iter(['', html])
        email_dict = self.email._asdict()
        email_dict['locale'] = 'ar'
        r = renderer.HtmlRenderer(self.template, self.settings,
                                  Email(**email_dict))

        actual = r.render(placeholders)

        self.assertEqual((
            '<body dir="rtl">\n <div>\n  <p>\n   dummy_content1\n  '
            '</p>\n </div>\n <div>\n  <p>\n   dummy_content2\n  </p>\n </div>\n</body>'
        ), actual)