Mercurial > p > roundup > code
comparison test/test_templating.py @ 6339:ab18fe956d45
Test StringHTMLProperty.wrapped(); test url, plain text for rst
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 12 Mar 2021 12:13:25 -0500 |
| parents | a70a0c138dd9 |
| children | a7e7314fb7d9 |
comparison
equal
deleted
inserted
replaced
| 6338:a70a0c138dd9 | 6339:ab18fe956d45 |
|---|---|
| 241 def test_string_email(self): | 241 def test_string_email(self): |
| 242 ''' test that email obscures the email ''' | 242 ''' test that email obscures the email ''' |
| 243 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'rouilj@foo.example.com') | 243 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'rouilj@foo.example.com') |
| 244 self.assertEqual(p.email(), 'rouilj at foo example ...') | 244 self.assertEqual(p.email(), 'rouilj at foo example ...') |
| 245 | 245 |
| 246 def test_string_wrapped(self): | |
| 247 test_string = ('A long string that needs to be wrapped to' | |
| 248 ' 80 characters and no more. Put in a link issue1.' | |
| 249 ' Put in <html> to be escaped. Put in a' | |
| 250 ' https://example.com/link as well. Let us see if' | |
| 251 ' it will wrap properly.' ) | |
| 252 test_result = ('A long string that needs to be wrapped to 80' | |
| 253 ' characters and no more. Put in a\n' | |
| 254 'link <a href="issue1">issue1</a>. Put in' | |
| 255 ' <html> to be escaped. Put in a <a' | |
| 256 ' href="https://example.com/link"' | |
| 257 ' rel="nofollow noopener">' | |
| 258 'https://example.com/link</a> as\n' | |
| 259 'well. Let us see if it will wrap properly.') | |
| 260 | |
| 261 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', | |
| 262 test_string) | |
| 263 self.assertEqual(p.wrapped(), test_result) | |
| 264 | |
| 246 def test_string_plain_or_hyperlinked(self): | 265 def test_string_plain_or_hyperlinked(self): |
| 247 ''' test that email obscures the email ''' | 266 ''' test that email obscures the email ''' |
| 248 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') | 267 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') |
| 249 self.assertEqual(p.plain(), 'A string <b> with rouilj@example.com embedded < html</b>') | 268 self.assertEqual(p.plain(), 'A string <b> with rouilj@example.com embedded < html</b>') |
| 250 self.assertEqual(p.plain(escape=1), 'A string <b> with rouilj@example.com embedded &lt; html</b>') | 269 self.assertEqual(p.plain(escape=1), 'A string <b> with rouilj@example.com embedded &lt; html</b>') |
| 310 # test case to make sure javascript and data url's aren't turned | 329 # test case to make sure javascript and data url's aren't turned |
| 311 # into links | 330 # into links |
| 312 s = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<badtag>\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==')) | 331 s = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<badtag>\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==')) |
| 313 s_result = '<div class="document">\n<p><badtag>\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==</p>\n</div>\n' | 332 s_result = '<div class="document">\n<p><badtag>\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==</p>\n</div>\n' |
| 314 | 333 |
| 334 # test url recognition | |
| 335 t = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'link is https://example.com/link for testing.')) | |
| 336 t_result = '<div class="document">\n<p>link is <a class="reference external" href="https://example.com/link">https://example.com/link</a> for testing.</p>\n</div>\n' | |
| 337 | |
| 338 # test text that doesn't need to be processed | |
| 339 u = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'Just a plain old string here. Nothig to process.')) | |
| 340 u_result = '<div class="document">\n<p>Just a plain old string here. Nothig to process.</p>\n</div>\n' | |
| 341 | |
| 315 self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n</div>\n')) | 342 self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n</div>\n')) |
| 316 self.assertEqual(q.rst(), u2s(q_result)) | 343 self.assertEqual(q.rst(), u2s(q_result)) |
| 317 self.assertEqual(r.rst(), u2s(r_result)) | 344 self.assertEqual(r.rst(), u2s(r_result)) |
| 318 self.assertEqual(s.rst(), u2s(s_result)) | 345 self.assertEqual(s.rst(), u2s(s_result)) |
| 346 self.assertEqual(t.rst(), u2s(t_result)) | |
| 347 self.assertEqual(u.rst(), u2s(u_result)) | |
| 319 | 348 |
| 320 @skip_stext | 349 @skip_stext |
| 321 def test_string_stext(self): | 350 def test_string_stext(self): |
| 322 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df')) | 351 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df')) |
| 323 self.assertEqual(p.stext(), u2s(u'<p>A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n')) | 352 self.assertEqual(p.stext(), u2s(u'<p>A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n')) |
