~facundo/canonical-identity-provider/new-era-discharge

« back to all changes in this revision

Viewing changes to src/webui/tests/test_utils.py

[r=nataliabidart] Add mark_safe_lazy function and a test for the same.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2016 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
from __future__ import unicode_literals
 
5
 
 
6
from django.template import (
 
7
    Context,
 
8
    Template,
 
9
)
 
10
 
 
11
from identityprovider.tests.utils import SSOBaseTestCase
 
12
from webui.utils import mark_safe_lazy
 
13
 
 
14
 
 
15
class LazyMarkSafeTestCase(SSOBaseTestCase):
 
16
 
 
17
    def render_string_in_template(self, string):
 
18
        """Render 'string' in a template, return the result."""
 
19
        template = Template('{{ str }}')
 
20
        context = Context(dict(str=string))
 
21
        return template.render(context)
 
22
 
 
23
    def test_returns_safe_string(self):
 
24
        lazy_string = mark_safe_lazy("<b>Lazy</b>")
 
25
        observed = self.render_string_in_template(lazy_string)
 
26
        self.assertEqual("<b>Lazy</b>", observed)