示例#1
0
 def test_formatting(self):
     # The whole point of this function is to make sure this works:
     out = _(u"Point & click {start}here{end}!").format(
         start=HTML("<a href='http://edx.org'>"),
         end=HTML("</a>"),
     )
     self.assertEqual(
         unicode(out),
         u"Point &amp; click <a href='http://edx.org'>here</a>!",
     )
示例#2
0
 def test_formatting(self):
     # The whole point of this function is to make sure this works:
     out = _(u"Point & click {start}here{end}!").format(
         start=HTML("<a href='http://edx.org'>"),
         end=HTML("</a>"),
     )
     self.assertEqual(
         unicode(out),
         u"Point &amp; click <a href='http://edx.org'>here</a>!",
     )
示例#3
0
 def test_nested_formatting(self):
     # Sometimes, you have plain text, with html inserted, and the html has
     # plain text inserted.  It gets twisty...
     out = _(u"Send {start}email{end}").format(
         start=HTML("<a href='mailto:{email}'>").format(email="A&B"),
         end=HTML("</a>"),
     )
     self.assertEqual(
         unicode(out),
         u"Send <a href='mailto:A&amp;B'>email</a>",
     )
示例#4
0
 def test_nested_formatting(self):
     # Sometimes, you have plain text, with html inserted, and the html has
     # plain text inserted.  It gets twisty...
     out = _(u"Send {start}email{end}").format(
         start=HTML("<a href='mailto:{email}'>").format(email="A&B"),
         end=HTML("</a>"),
     )
     self.assertEqual(
         unicode(out),
         u"Send <a href='mailto:A&amp;B'>email</a>",
     )
示例#5
0
class FormatHtmlTest(unittest.TestCase):
    """Test that we can format plain strings and HTML into them properly."""
    @ddt.data(
        (u"hello", u"hello"),
        (u"<hello>", u"&lt;hello&gt;"),
        (u"It's cool", u"It&#39;s cool"),
        (u'"cool," she said.', u'&#34;cool,&#34; she said.'),
        (u"Stop & Shop", u"Stop &amp; Shop"),
        (u"<a>нтмℓ-єѕ¢αρє∂</a>", u"&lt;a&gt;нтмℓ-єѕ¢αρє∂&lt;/a&gt;"),
    )
    def test_simple(self, (before, after)):
        self.assertEqual(unicode(_(before)), after)  # pylint: disable=translation-of-non-string
        self.assertEqual(unicode(escape(before)), after)