annotate test/test_templating.py @ 6991:3085aac22f3a

New markdown2 release changed output with code highlighting code highight div generated/used by pygments is on a separate line in 2.4.4 release of markdown2.
author John Rouillard <rouilj@ieee.org>
date Sat, 01 Oct 2022 21:31:27 -0400
parents 234fefd7568a
children a5f30372ef7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
1 from __future__ import print_function
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2 import unittest
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 from cgi import FieldStorage, MiniFieldStorage
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
5 from roundup.cgi.templating import *
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5378
diff changeset
6 from .test_actions import MockNull, true
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
8
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
9 import pytest
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
10 from .pytest_patcher import mark_class
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
11
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
12 if ReStructuredText:
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
13 skip_rst = lambda func, *args, **kwargs: func
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
14 else:
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
15 skip_rst = mark_class(pytest.mark.skip(
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
16 reason='ReStructuredText not available'))
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
17
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
18 if StructuredText:
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
19 skip_stext = lambda func, *args, **kwargs: func
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
20 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
21 skip_stext = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
22 reason='StructuredText not available'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
23
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
24 import roundup.cgi.templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
25 if roundup.cgi.templating._import_mistune():
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
26 skip_mistune = lambda func, *args, **kwargs: func
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
27 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
28 skip_mistune = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
29 reason='mistune not available'))
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
30
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
31 if roundup.cgi.templating._import_markdown2():
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
32 skip_markdown2 = lambda func, *args, **kwargs: func
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
33 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
34 skip_markdown2 = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
35 reason='markdown2 not available'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
36
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
37 if roundup.cgi.templating._import_markdown():
6097
90a1470edbea added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6096
diff changeset
38 skip_markdown = lambda func, *args, **kwargs: func
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
39 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
40 skip_markdown = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
41 reason='markdown not available'))
6097
90a1470edbea added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6096
diff changeset
42
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
43 from roundup.anypy.strings import u2s, s2u
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
44
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
45 from roundup.backends.sessions_common import SessionCommon
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
46
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
47 class MockDatabase(MockNull, SessionCommon):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48 def getclass(self, name):
6337
316c2c32dace Make testing mock smarter. Make getclass fail for invalid classes.
John Rouillard <rouilj@ieee.org>
parents: 6336
diff changeset
49 # limit class names
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
50 if name not in [ 'issue', 'user', 'status' ]:
6337
316c2c32dace Make testing mock smarter. Make getclass fail for invalid classes.
John Rouillard <rouilj@ieee.org>
parents: 6336
diff changeset
51 raise KeyError('There is no class called "%s"' % name)
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
52 # Class returned must have hasnode(id) method that returns true
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
53 # otherwise designators like 'issue1' can't be hyperlinked.
6338
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
54 self.classes[name].hasnode = lambda id: True if int(id) < 10 else False
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
55 return self.classes[name]
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
56
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
57 # setup for csrf testing of otks database api
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
58 storage = {}
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
59 def set(self, key, **props):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
60 MockDatabase.storage[key] = {}
6817
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
61 if '__timestamp' not in props:
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
62 props['__timestamp'] = time.time() - 7*24*3600
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
63 MockDatabase.storage[key].update(props)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
64
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
65 def get(self, key, field, default=None):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
66 if key not in MockDatabase.storage:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
67 return default
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
68 return MockDatabase.storage[key][field]
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
69
6817
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
70 def getall(self, key):
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
71 if key not in MockDatabase.storage:
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
72 return default
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
73 return MockDatabase.storage[key]
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
74
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
75 def exists(self,key):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
76 return key in MockDatabase.storage
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
77
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
78 def getOTKManager(self):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
79 return MockDatabase()
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
80
6817
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
81 def lifetime(self, seconds):
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
82 return time.time() - 7*24*3600 + seconds
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
83
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
84 class TemplatingTestCase(unittest.TestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
85 def setUp(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
86 self.form = FieldStorage()
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
87 self.client = MockNull()
3972
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
88 self.client.db = db = MockDatabase()
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
89 db.security.hasPermission = lambda *args, **kw: True
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
90 self.client.form = self.form
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
91
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
92 # add client props for testing anti_csrf_nonce
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
93 self.client.session_api = MockNull(_sid="1234567890")
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
94 self.client.db.getuid = lambda : 10
6277
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
95 self.client.db.config = {'WEB_CSRF_TOKEN_LIFETIME': 10, 'MARKDOWN_BREAK_ON_NEWLINE': False }
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
96
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97 class HTMLDatabaseTestCase(TemplatingTestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
98 def test_HTMLDatabase___getitem__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
99 db = HTMLDatabase(self.client)
5649
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
100 self.assertTrue(isinstance(db['issue'], HTMLClass))
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
101 # following assertions are invalid
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
102 # since roundup/cgi/templating.py r1.173.
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
103 # HTMLItem is function, not class,
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
104 # but HTMLUserClass and HTMLUser are passed on.
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
105 # these classes are no more. they have ceased to be.
5649
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
106 #self.assertTrue(isinstance(db['user'], HTMLUserClass))
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
107 #self.assertTrue(isinstance(db['issue1'], HTMLItem))
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
108 #self.assertTrue(isinstance(db['user1'], HTMLUser))
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
109
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
110 def test_HTMLDatabase___getattr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
111 db = HTMLDatabase(self.client)
5649
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
112 self.assertTrue(isinstance(db.issue, HTMLClass))
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
113 # see comment in test_HTMLDatabase___getitem__
5649
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
114 #self.assertTrue(isinstance(db.user, HTMLUserClass))
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
115 #self.assertTrue(isinstance(db.issue1, HTMLItem))
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
116 #self.assertTrue(isinstance(db.user1, HTMLUser))
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
117
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
118 def test_HTMLDatabase_classes(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
119 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
120 db._db.classes = {'issue':MockNull(), 'user': MockNull()}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
121 db.classes()
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
122
6689
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
123 def test_HTMLDatabase_list(self):
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
124 # The list method used to produce a traceback when a None value
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
125 # for an order attribute of a class was encountered. This
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
126 # happens when the 'get' of the order attribute for a numeric
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
127 # id produced a None value. So we put '23' as a key into the
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
128 # list and set things up that a None value is returned on 'get'.
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
129
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
130 # This keeps db.issue static, otherwise it changes for each call
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
131 db = MockNull(issue = HTMLDatabase(self.client).issue)
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
132 db.issue._klass.list = lambda : ['23', 'a', 'b']
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
133 # Make db.getclass return something that has a sensible 'get' method
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
134 mock = MockNull(get = lambda x, y : None)
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
135 db.issue._db.getclass = lambda x : mock
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
136 l = db.issue.list()
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
137
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
138 class FunctionsTestCase(TemplatingTestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
139 def test_lookupIds(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
140 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
141 def lookup(key):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
142 if key == 'ok':
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
143 return '1'
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
144 if key == 'fail':
5378
35ea9b1efc14 Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5376
diff changeset
145 raise KeyError('fail')
3587
2372597ebbdb *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2716
diff changeset
146 return key
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
147 db._db.classes = {'issue': MockNull(lookup=lookup)}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
148 prop = MockNull(classname='issue')
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
149 self.assertEqual(lookupIds(db._db, prop, ['1','2']), ['1','2'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
150 self.assertEqual(lookupIds(db._db, prop, ['ok','2']), ['1','2'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
151 self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail'], 1),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
152 ['1', 'fail'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
153 self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail']), ['1'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
154
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
155 def test_lookupKeys(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
156 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
157 def get(entry, key):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
158 return {'1': 'green', '2': 'eggs'}.get(entry, entry)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
159 shrubbery = MockNull(get=get)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
160 db._db.classes = {'shrubbery': shrubbery}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
161 self.assertEqual(lookupKeys(shrubbery, 'spam', ['1','2']),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
162 ['green', 'eggs'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
163 self.assertEqual(lookupKeys(shrubbery, 'spam', ['ok','2']), ['ok',
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
164 'eggs'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
165
3972
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
166 class HTMLClassTestCase(TemplatingTestCase) :
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
167
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
168 def test_link(self):
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
169 """Make sure lookup of a Link property works even in the
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
170 presence of multiple values in the form."""
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
171 def lookup(key) :
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
172 self.assertEqual(key, key.strip())
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
173 return "Status%s"%key
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
174 self.form.list.append(MiniFieldStorage("issue@status", "1"))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
175 self.form.list.append(MiniFieldStorage("issue@status", "2"))
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
176 status = hyperdb.Link("status")
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
177 self.client.db.classes = dict \
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
178 ( issue = MockNull(getprops = lambda : dict(status = status))
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
179 , status = MockNull(get = lambda id, name : id, lookup = lookup)
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
180 )
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
181 self.client.form = self.form
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
182 cls = HTMLClass(self.client, "issue")
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
183
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
184 s = cls["status"]
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
185 self.assertEqual(s._value, '1')
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
186
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
187 def test_link_default(self):
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
188 """Make sure default value for link is returned
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
189 if new item and no value in form."""
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
190 def lookup(key) :
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
191 self.assertEqual(key, key.strip())
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
192 return "Status%s"%key
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
193 status = hyperdb.Link("status")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
194 # set default_value
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
195 status.__dict__['_Type__default_value'] = "4"
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
196
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
197 self.client.db.classes = dict \
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
198 ( issue = MockNull(getprops = lambda : dict(status = status))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
199 , status = MockNull(get = lambda id, name : id, lookup = lookup, get_default_value = lambda: 4)
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
200 )
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
201 self.client.form = self.form
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
202
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
203 cls = HTMLClass(self.client, "issue")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
204 s = cls["status"]
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
205 self.assertEqual(s._value, '4')
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
206
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
207 def test_link_with_value_and_default(self):
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
208 """Make sure default value is not used if there
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
209 is a value in the form."""
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
210 def lookup(key) :
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
211 self.assertEqual(key, key.strip())
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
212 return "Status%s"%key
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
213 self.form.list.append(MiniFieldStorage("issue@status", "2"))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
214 self.form.list.append(MiniFieldStorage("issue@status", "1"))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
215 status = hyperdb.Link("status")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
216 # set default_value
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
217 status.__dict__['_Type__default_value'] = "4"
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
218
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
219 self.client.db.classes = dict \
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
220 ( issue = MockNull(getprops = lambda : dict(status = status))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
221 , status = MockNull(get = lambda id, name : id, lookup = lookup, get_default_value = lambda: 4)
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
222 )
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
223 self.client.form = self.form
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
224
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
225 cls = HTMLClass(self.client, "issue")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
226 s = cls["status"]
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
227 self.assertEqual(s._value, '2')
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
228
3972
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
229 def test_multilink(self):
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
230 """`lookup` of an item will fail if leading or trailing whitespace
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
231 has not been stripped.
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
232 """
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
233 def lookup(key) :
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
234 self.assertEqual(key, key.strip())
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
235 return "User%s"%key
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
236 self.form.list.append(MiniFieldStorage("nosy", "1, 2"))
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
237 nosy = hyperdb.Multilink("user")
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
238 self.client.db.classes = dict \
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
239 ( issue = MockNull(getprops = lambda : dict(nosy = nosy))
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
240 , user = MockNull(get = lambda id, name : id, lookup = lookup)
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
241 )
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
242 cls = HTMLClass(self.client, "issue")
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
243 cls["nosy"]
eee76dd4a09f 'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents: 3587
diff changeset
244
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
245 def test_anti_csrf_nonce(self):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
246 '''call the csrf creation function and do basic length test
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
247
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
248 Store the data in a mock db with the same api as the otk
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
249 db. Make sure nonce is 54 chars long. Lookup the nonce in
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
250 db and retrieve data. Verify that the nonce lifetime is
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
251 correct (within 1 second of 1 week - lifetime), the uid is
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
252 correct (1), the dummy sid is correct.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
253
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
254 Consider three cases:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
255 * create nonce via module function setting lifetime
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
256 * create nonce via TemplatingUtils method setting lifetime
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
257 * create nonce via module function with default lifetime
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
258
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
259 '''
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
260
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
261 # the value below is number of seconds in a week.
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
262 week_seconds = 604800
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
263
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
264 otks=self.client.db.getOTKManager()
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
265
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
266 for test in [ 'module', 'template', 'default_time' ]:
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
267 print("Testing:", test)
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
268
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
269 if test == 'module':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
270 # test the module function
5488
52cb53eedf77 reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5485
diff changeset
271 nonce1 = anti_csrf_nonce(self.client, lifetime=1)
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
272 # lifetime * 60 is the offset
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
273 greater_than = week_seconds - 1 * 60
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
274 elif test == 'template':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
275 # call the function through the TemplatingUtils class
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
276 cls = TemplatingUtils(self.client)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
277 nonce1 = cls.anti_csrf_nonce(lifetime=5)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
278 greater_than = week_seconds - 5 * 60
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
279 elif test == 'default_time':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
280 # use the module function but with no lifetime
5488
52cb53eedf77 reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5485
diff changeset
281 nonce1 = anti_csrf_nonce(self.client)
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
282 # see above for web nonce lifetime.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
283 greater_than = week_seconds - 10 * 60
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
284
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
285 self.assertEqual(len(nonce1), 54)
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
286
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
287 uid = otks.get(nonce1, 'uid', default=None)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
288 sid = otks.get(nonce1, 'sid', default=None)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
289 timestamp = otks.get(nonce1, '__timestamp', default=None)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
290
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
291 self.assertEqual(uid, 10)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
292 self.assertEqual(sid, self.client.session_api._sid)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
293
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
294 now = time.time()
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
295
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
296 print("now, timestamp, greater, difference",
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
297 now, timestamp, greater_than, now - timestamp)
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
298
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
299
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
300 # lower bound of the difference is above. Upper bound
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
301 # of difference is run time between time.time() in
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
302 # the call to anti_csrf_nonce and the time.time() call
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
303 # that assigns ts above. I declare that difference
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
304 # to be less than 1 second for this to pass.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
305 self.assertEqual(True,
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
306 greater_than <= now - timestamp < (greater_than + 1) )
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
307
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
308 def test_number__int__(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
309 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
310 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
311 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
312 self.assertEqual(p.__int__(), 2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
313
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
314 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
315 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
316 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
317 with self.assertRaises(TypeError) as e:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
318 p.__int__()
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
319
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
320 def test_number__float__(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
321 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
322 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
323 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
324 self.assertEqual(p.__float__(), 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
325
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
326 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
327 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
328 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
329 with self.assertRaises(TypeError) as e:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
330 p.__float__()
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
331
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
332 def test_number_field(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
333 import sys
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
334
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
335 _py3 = sys.version_info[0] > 2
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
336
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
337 # python2 truncates while python3 rounds. Sigh.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
338 if _py3:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
339 expected_val = 2345678.2345678
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
340 else:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
341 expected_val = 2345678.23457
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
342
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
343 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
344 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
345 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
346 self.assertEqual(p.field(),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
347 ('<input name="testnum1@test" size="30" type="text" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
348 'value="%s">')%expected_val)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
349 self.assertEqual(p.field(size=10),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
350 ('<input name="testnum1@test" size="10" type="text" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
351 'value="%s">')%expected_val)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
352 self.assertEqual(p.field(size=10, dataprop="foo", dataprop2=5),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
353 ('<input dataprop="foo" dataprop2="5" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
354 'name="testnum1@test" size="10" type="text" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
355 'value="%s">'%expected_val))
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
356
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
357 self.assertEqual(p.field(size=10, klass="class1",
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
358 **{ "class": "class2 class3",
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
359 "data-prop": "foo",
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
360 "data-prop2": 5}),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
361 ('<input class="class2 class3" data-prop="foo" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
362 'data-prop2="5" klass="class1" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
363 'name="testnum1@test" size="10" type="text" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
364 'value="%s">')%expected_val)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
365
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
366 # get plain representation if user can't edit
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
367 p.is_edit_ok = lambda: False
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
368 self.assertEqual(p.field(), p.plain())
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
369
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
370 # test with string which is wrong type
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
371 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
372 "2345678.2345678")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
373 self.assertEqual(p.field(),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
374 ('<input name="testnum1@test" size="30" type="text" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
375 'value="2345678.2345678">'))
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
376
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
377 # test with None value, pretend property.__default_value = Null which
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
378 # is the default. It would be returned by get_default_value
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
379 # which I mock.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
380 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
381 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
382 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
383 self.assertEqual(p.field(),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
384 ('<input name="testnum1@test" size="30" type="text" '
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
385 'value="">'))
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
386
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
387 def test_number_plain(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
388 import sys
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
389
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
390 _py3 = sys.version_info[0] > 2
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
391
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
392 # python2 truncates while python3 rounds. Sigh.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
393 if _py3:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
394 expected_val = 2345678.2345678
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
395 else:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
396 expected_val = 2345678.23457
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
397
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
398 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
399 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
400
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
401 self.assertEqual(p.plain(), "%s"%expected_val)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
402
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
403 def test_number_pretty(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
404 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
405 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
406 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
407 self.assertEqual(p.pretty(), "2345678.235")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
408
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
409 # test with string which is wrong type
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
410 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
411 "2345678.2345678")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
412 self.assertEqual(p.pretty(), "2345678.2345678")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
413
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
414 # test with boolean
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
415 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
416 True)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
417 self.assertEqual(p.pretty(), "1.000")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
418
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
419 # test with None value, pretend property.__default_value = Null which
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
420 # is the default. It would be returned by get_default_value
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
421 # which I mock.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
422 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
423 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
424 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
425 self.assertEqual(p.pretty(), '')
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
426
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
427 with self.assertRaises(ValueError) as e:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
428 p.pretty('%0.3')
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
429
5156
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
430 def test_string_url_quote(self):
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
431 ''' test that urlquote quotes the string '''
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
432 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'test string< foo@bar')
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
433 self.assertEqual(p.url_quote(), 'test%20string%3C%20foo%40bar')
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
434
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
435 def test_string_email(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
436 ''' test that email obscures the email '''
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
437 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'rouilj@foo.example.com')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
438 self.assertEqual(p.email(), 'rouilj at foo example ...')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
439
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
440 def test_string_wrapped(self):
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
441 test_string = ('A long string that needs to be wrapped to'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
442 ' 80 characters and no more. Put in a link issue1.'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
443 ' Put in <html> to be escaped. Put in a'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
444 ' https://example.com/link as well. Let us see if'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
445 ' it will wrap properly.' )
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
446 test_result = ('A long string that needs to be wrapped to 80'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
447 ' characters and no more. Put in a\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
448 'link <a href="issue1">issue1</a>. Put in'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
449 ' &lt;html&gt; to be escaped. Put in a <a'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
450 ' href="https://example.com/link"'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
451 ' rel="nofollow noopener">'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
452 'https://example.com/link</a> as\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
453 'well. Let us see if it will wrap properly.')
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
454
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
455 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
456 test_string)
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
457 self.assertEqual(p.wrapped(), test_result)
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
458
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
459 def test_string_plain_or_hyperlinked(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
460 ''' test that email obscures the email '''
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
461 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded &lt; html</b>')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
462 self.assertEqual(p.plain(), 'A string <b> with rouilj@example.com embedded &lt; html</b>')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
463 self.assertEqual(p.plain(escape=1), 'A string &lt;b&gt; with rouilj@example.com embedded &amp;lt; html&lt;/b&gt;')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
464 self.assertEqual(p.plain(hyperlink=1), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
465 self.assertEqual(p.plain(escape=1, hyperlink=1), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
466
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
467 self.assertEqual(p.hyperlinked(), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
6338
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
468 # check designators
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
469 for designator in [ "issue1", "issue 1" ]:
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
470 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
471 self.assertEqual(p.hyperlinked(),
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
472 '<a href="issue1">%s</a>'%designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
473
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
474 # issue 100 > 10 which is a magic number for the mocked hasnode
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
475 # If id number is greater than 10 hasnode reports it does not have
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
476 # the node.
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
477 for designator in ['issue100', 'issue 100']:
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
478 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
479 designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
480 self.assertEqual(p.hyperlinked(), designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
481
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
482 # zoom class does not exist
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
483 for designator in ['zoom1', 'zoom100', 'zoom 1']:
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
484 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
485 designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
486 self.assertEqual(p.hyperlinked(), designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
487
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
488
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
489 @skip_rst
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
490 def test_string_rst(self):
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
491 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
6098
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
492
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
493 # test case to make sure include directive is disabled
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
494 q = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'\n\n.. include:: XyZrMt.html\n\n<badtag>\n\n'))
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
495 q_result=u'''<div class="document">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
496 <div class="system-message">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
497 <p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">&lt;string&gt;</tt>, line 3)</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
498 <p>&quot;include&quot; directive disabled.</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
499 <pre class="literal-block">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
500 .. include:: XyZrMt.html
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
501
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
502 </pre>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
503 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
504 <p>&lt;badtag&gt;</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
505 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
506 '''
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
507
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
508 # test case to make sure raw directive is disabled
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
509 r = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'\n\n.. raw:: html\n\n <badtag>\n\n'))
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
510 r_result='''<div class="document">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
511 <div class="system-message">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
512 <p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">&lt;string&gt;</tt>, line 3)</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
513 <p>&quot;raw&quot; directive disabled.</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
514 <pre class="literal-block">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
515 .. raw:: html
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
516
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
517 &lt;badtag&gt;
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
518
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
519 </pre>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
520 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
521 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
522 '''
6284
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
523 # test case to make sure javascript and data url's aren't turned
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
524 # into links
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
525 s = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<badtag>\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=='))
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
526 s_result = '<div class="document">\n<p>&lt;badtag&gt;\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==</p>\n</div>\n'
6103
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
527
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
528 # test url recognition
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
529 t = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'link is https://example.com/link for testing.'))
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
530 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'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
531
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
532 # test text that doesn't need to be processed
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
533 u = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'Just a plain old string here. Nothig to process.'))
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
534 u_result = '<div class="document">\n<p>Just a plain old string here. Nothig to process.</p>\n</div>\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
535
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
536 self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw&#64;example.com">cmeerw&#64;example.com</a> <em>embedded</em> \u00df</p>\n</div>\n'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
537 self.assertEqual(q.rst(), u2s(q_result))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
538 self.assertEqual(r.rst(), u2s(r_result))
6103
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
539 self.assertEqual(s.rst(), u2s(s_result))
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
540 self.assertEqual(t.rst(), u2s(t_result))
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
541 self.assertEqual(u.rst(), u2s(u_result))
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
542
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
543 @skip_stext
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
544 def test_string_stext(self):
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
545 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
546 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'))
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
547
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
548 def test_string_field(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
549 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded &lt; html</b>')
5485
b0359a7c5b6d create input elements with attributes in a defined (sorted) order
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
550 self.assertEqual(p.field(), '<input name="test1@test" size="30" type="text" value="A string &lt;b&gt; with rouilj@example.com embedded &amp;lt; html&lt;/b&gt;">')
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
551
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
552 def test_string_multiline(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
553 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded &lt; html</b>')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
554 self.assertEqual(p.multiline(), '<textarea name="test1@test" id="test1@test" rows="5" cols="40">A string &lt;b&gt; with rouilj@example.com embedded &amp;lt; html&lt;/b&gt;</textarea>')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
555 self.assertEqual(p.multiline(rows=300, cols=100, **{'class':'css_class'}), '<textarea class="css_class" name="test1@test" id="test1@test" rows="300" cols="100">A string &lt;b&gt; with rouilj@example.com embedded &amp;lt; html&lt;/b&gt;</textarea>')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
556
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
557 def test_url_match(self):
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
558 '''Test the URL regular expression in StringHTMLProperty.
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
559 '''
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
560 def t(s, nothing=False, **groups):
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
561 m = StringHTMLProperty.hyper_re.search(s)
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
562 if nothing:
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
563 if m:
5793
6aad7b194e63 replace assertEquals wth assertEqual.
John Rouillard <rouilj@ieee.org>
parents: 5684
diff changeset
564 self.assertEqual(m, None, '%r matched (%r)'%(s, m.groupdict()))
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
565 return
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
566 else:
5795
10747e4e4ec4 replace assertNotEquals with assertNotEqual
John Rouillard <rouilj@ieee.org>
parents: 5793
diff changeset
567 self.assertNotEqual(m, None, '%r did not match'%s)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
568 d = m.groupdict()
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
569 for g in groups:
5793
6aad7b194e63 replace assertEquals wth assertEqual.
John Rouillard <rouilj@ieee.org>
parents: 5684
diff changeset
570 self.assertEqual(d[g], groups[g], '%s %r != %r in %r'%(g, d[g],
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
571 groups[g], s))
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
572
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
573 #t('123.321.123.321', 'url')
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
574 t('https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4', url="https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4")
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
575 t('http://localhost/', url='http://localhost/')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
576 t('http://roundup.net/', url='http://roundup.net/')
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
577 t('http://richard@localhost/', url='http://richard@localhost/')
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
578 t('http://richard:sekrit@localhost/',
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
579 url='http://richard:sekrit@localhost/')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
580 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
581 t('www.a.ex', url='www.a.ex')
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
582 t('foo.a.ex', nothing=True)
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
583 t('StDevValidTimeSeries.GetObservation', nothing=True)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
584 t('http://a.ex', url='http://a.ex')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
585 t('http://a.ex/?foo&bar=baz\\.@!$%()qwerty',
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
586 url='http://a.ex/?foo&bar=baz\\.@!$%()qwerty')
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
587 t('www.foo.net', url='www.foo.net')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
588 t('richard@com.example', email='richard@com.example')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
589 t('r@a.com', email='r@a.com')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
590 t('i1', **{'class':'i', 'id':'1'})
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
591 t('item123', **{'class':'item', 'id':'123'})
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
592 t('item 123', **{'class':'item', 'id':'123'})
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
593 t('www.user:pass@host.net', email='pass@host.net')
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
594 t('user:pass@www.host.net', url='user:pass@www.host.net')
4011
e77bcbdc9b32 add tests for numbers too :)
Richard Jones <richard@users.sourceforge.net>
parents: 4010
diff changeset
595 t('123.35', nothing=True)
e77bcbdc9b32 add tests for numbers too :)
Richard Jones <richard@users.sourceforge.net>
parents: 4010
diff changeset
596 t('-.3535', nothing=True)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
597
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
598 def test_url_replace(self):
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
599 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
600 def t(s): return p.hyper_re.sub(p._hyper_repl, s)
4413
66603a9051f9 improve handling of '&gt;' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents: 4391
diff changeset
601 ae = self.assertEqual
6564
21c7c2041a4b issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents: 6551
diff changeset
602 ae(t('issue5#msg10'), '<a href="issue5#msg10">issue5#msg10</a>')
21c7c2041a4b issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents: 6551
diff changeset
603 ae(t('issue5'), '<a href="issue5">issue5</a>')
21c7c2041a4b issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents: 6551
diff changeset
604 ae(t('issue2255'), 'issue2255')
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
605 ae(t('foo https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4 bar'),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
606 'foo <a href="https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4" rel="nofollow noopener">'
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
607 'https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4</a> bar')
4288
ce684080e968 issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents: 4040
diff changeset
608 ae(t('item123123123123'), 'item123123123123')
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
609 ae(t('http://roundup.net/'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
610 '<a href="http://roundup.net/" rel="nofollow noopener">http://roundup.net/</a>')
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
611 ae(t('&lt;HTTP://roundup.net/&gt;'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
612 '&lt;<a href="HTTP://roundup.net/" rel="nofollow noopener">HTTP://roundup.net/</a>&gt;')
4414
399569ff4aed - fix small indentation glitch
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4413
diff changeset
613 ae(t('&lt;http://roundup.net/&gt;.'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
614 '&lt;<a href="http://roundup.net/" rel="nofollow noopener">http://roundup.net/</a>&gt;.')
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
615 ae(t('&lt;www.roundup.net&gt;'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
616 '&lt;<a href="http://www.roundup.net" rel="nofollow noopener">www.roundup.net</a>&gt;')
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
617 ae(t('(www.roundup.net)'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
618 '(<a href="http://www.roundup.net" rel="nofollow noopener">www.roundup.net</a>)')
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
619 ae(t('foo http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx bar'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
620 'foo <a href="http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx" rel="nofollow noopener">'
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
621 'http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx</a> bar')
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
622 ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language))'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
623 '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)" rel="nofollow noopener">'
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
624 'http://en.wikipedia.org/wiki/Python_(programming_language)</a>)')
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
625 ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language)).'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
626 '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)" rel="nofollow noopener">'
4391
d5239335fae3 make URL detection a little smarter about brackets per issue2550657
Richard Jones <richard@users.sourceforge.net>
parents: 4288
diff changeset
627 'http://en.wikipedia.org/wiki/Python_(programming_language)</a>).')
4413
66603a9051f9 improve handling of '&gt;' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents: 4391
diff changeset
628 ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language))&gt;.'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
629 '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)" rel="nofollow noopener">'
4413
66603a9051f9 improve handling of '&gt;' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents: 4391
diff changeset
630 'http://en.wikipedia.org/wiki/Python_(programming_language)</a>)&gt;.')
66603a9051f9 improve handling of '&gt;' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents: 4391
diff changeset
631 ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language&gt;)).'),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
632 '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language" rel="nofollow noopener">'
4413
66603a9051f9 improve handling of '&gt;' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents: 4391
diff changeset
633 'http://en.wikipedia.org/wiki/Python_(programming_language</a>&gt;)).')
4647
11b6601629d7 #2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 4414
diff changeset
634 for c in '.,;:!':
11b6601629d7 #2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 4414
diff changeset
635 # trailing punctuation is not included
11b6601629d7 #2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 4414
diff changeset
636 ae(t('http://roundup.net/%c ' % c),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
637 '<a href="http://roundup.net/" rel="nofollow noopener">http://roundup.net/</a>%c ' % c)
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
638 # trailing punctuation is not included without trailing space
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
639 ae(t('http://roundup.net/%c' % c),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
640 '<a href="http://roundup.net/" rel="nofollow noopener">http://roundup.net/</a>%c' % c)
4647
11b6601629d7 #2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 4414
diff changeset
641 # but it's included if it's part of the URL
11b6601629d7 #2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 4414
diff changeset
642 ae(t('http://roundup.net/%c/' % c),
5684
97e2125e064c When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
643 '<a href="http://roundup.net/%c/" rel="nofollow noopener">http://roundup.net/%c/</a>' % (c, c))
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
644 # including with a non / terminated path
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
645 ae(t('http://roundup.net/test%c ' % c),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
646 '<a href="http://roundup.net/test" rel="nofollow noopener">http://roundup.net/test</a>%c ' % c)
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
647 # but it's included if it's part of the URL path
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
648 ae(t('http://roundup.net/%ctest' % c),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
649 '<a href="http://roundup.net/%ctest" rel="nofollow noopener">http://roundup.net/%ctest</a>' % (c, c))
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
650
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
651
5989
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
652 def test_input_html4(self):
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
653 # boolean attributes are just the attribute name
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
654 # indicate with attr=None or attr="attr"
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
655 # e.g. disabled
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
656
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
657 input=input_html4(required=None, size=30)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
658 self.assertEqual(input, '<input required size="30" type="text">')
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
659
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
660 input=input_html4(required="required", size=30)
6059
f0da02e0ca81 Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents: 5989
diff changeset
661 self.assertEqual(input, '<input required="required" size="30" type="text">')
5989
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
662
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
663 attrs={"required": None, "class": "required", "size": 30}
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
664 input=input_html4(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
665 self.assertEqual(input, '<input class="required" required size="30" type="text">')
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
666
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
667 attrs={"disabled": "disabled", "class": "required", "size": 30}
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
668 input=input_html4(**attrs)
6059
f0da02e0ca81 Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents: 5989
diff changeset
669 self.assertEqual(input, '<input class="required" disabled="disabled" size="30" type="text">')
5989
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
670
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
671 def test_input_xhtml(self):
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
672 # boolean attributes are attribute name="attribute name"
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
673 # indicate with attr=None or attr="attr"
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
674 # e.g. disabled="disabled"
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
675 input=input_xhtml(required=None, size=30)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
676 self.assertEqual(input, '<input required="required" size="30" type="text"/>')
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
677
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
678 input=input_xhtml(required="required", size=30)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
679 self.assertEqual(input, '<input required="required" size="30" type="text"/>')
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
680
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
681 attrs={"required": None, "class": "required", "size": 30}
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
682 input=input_xhtml(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
683 self.assertEqual(input, '<input class="required" required="required" size="30" type="text"/>')
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
684
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
685 attrs={"disabled": "disabled", "class": "required", "size": 30}
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
686 input=input_xhtml(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
687 self.assertEqual(input, '<input class="required" disabled="disabled" size="30" type="text"/>')
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
688
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
689
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
690 class HTMLPropertyTestClass(unittest.TestCase):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
691 def setUp(self):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
692 self.form = FieldStorage()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
693 self.client = MockNull()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
694 self.client.db = db = MockDatabase()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
695 db.security.hasPermission = lambda *args, **kw: True
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
696 self.client.form = self.form
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
697
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
698 self.client._props = MockNull()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
699 # add client props for testing anti_csrf_nonce
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
700 self.client.session_api = MockNull(_sid="1234567890")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
701 self.client.db.getuid = lambda : 10
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
702
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
703 class DateHTMLPropertyTestCase(HTMLPropertyTestClass):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
704
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
705 def test_DateHTMLWithText(self):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
706 """Test methods when DateHTMLProperty._value is a string
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
707 rather than a hyperdb.Date()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
708 """
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
709 test_datestring = "2021-01-01 11:22:10"
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
710 test_date = hyperdb.Date("2")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
711
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
712 self.form.list.append(MiniFieldStorage("test1@test", test_datestring))
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
713 self.client._props=test_date
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
714
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
715 self.client.db.classes = dict \
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
716 ( test = MockNull(getprops = lambda : test_date)
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
717 )
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
718
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
719 # client, classname, nodeid, prop, name, value,
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
720 # anonymous=0, offset=None
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
721 d = DateHTMLProperty(self.client, 'test', '1', self.client._props,
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
722 'test', '')
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
723 self.assertIs(type(d._value), str)
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
724 self.assertEqual(d.pretty(), "2021-01-01 11:22:10")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
725 self.assertEqual(d.plain(), "2021-01-01 11:22:10")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
726 input = """<input name="test1@test" size="30" type="text" value="2021-01-01 11:22:10"><a class="classhelp" data-calurl="test?@template=calendar&amp;amp;property=test&amp;amp;form=itemSynopsis&amp;date=2021-01-01 11:22:10" data-height="200" data-width="300" href="javascript:help_window('test?@template=calendar&amp;property=test&amp;form=itemSynopsis&date=2021-01-01 11:22:10', 300, 200)">(cal)</a>"""
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
727 self.assertEqual(d.field(), input)
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
728
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
729 # common markdown test cases
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
730 class MarkdownTests:
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
731 def mangleMarkdown2(self, s):
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
732 ''' markdown2's rel=nofollow support on 'a' tags isn't programmable.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
733 So we are using it's builtin nofollow support. Mangle the string
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
734 so that it matches the test case.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
735
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
736 turn: <a rel="nofollow" href="foo"> into
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
737 <a href="foo" rel="nofollow noopener">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
738
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
739 Also if it is a mailto url, we don't expect rel="nofollow",
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
740 so delete it.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
741
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
742 turn: <a rel="nofollow" href="mailto:foo"> into
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
743 <a href="mailto:foo">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
744
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
745 Also when a title is present it is put in a different place
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
746 from markdown, so fix it to normalize.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
747
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
748 turn:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
749
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
750 <a rel="nofollow" href="http://example.com/" title="a title">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
751 into
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
752 <a href="http://example.com/" rel="nofollow noopener" title="a title">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
753 '''
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
754 if type(self) == Markdown2TestCase and s.find('a rel="nofollow"') != -1:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
755 if s.find('href="mailto:') == -1:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
756 # not a mailto url
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
757 if 'rel="nofollow"' in s:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
758 if 'title="' in s:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
759 s = s.replace(' rel="nofollow" ', ' ').replace(' title=', ' rel="nofollow noopener" title=')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
760 else:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
761 s = s.replace(' rel="nofollow" ', ' ').replace('">', '" rel="nofollow noopener">')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
762
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
763 return s
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
764 else:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
765 # a mailto url
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
766 return s.replace(' rel="nofollow" ', ' ')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
767 return s
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
768
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
769
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
770 def test_string_markdown(self):
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
771 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with <br> *embedded* \u00df'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
772 self.assertEqual(p.markdown().strip(), u2s(u'<p>A string with &lt;br&gt; <em>embedded</em> \u00df</p>'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
773
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
774 def test_string_markdown_link(self):
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
775 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A link <http://localhost>'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
776 self.assertEqual(p.markdown().strip(), u2s(u'<p>A link <a href="http://localhost">http://localhost</a></p>'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
777
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
778 def test_string_markdown_link_item(self):
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
779 """ The link formats for the different markdown engines changes.
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
780 Order of attributes, value for rel (noopener, nofollow etc)
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
781 is different. So most tests check for a substring that indicates
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
782 success rather than the entire returned string.
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
783 """
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
784 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An issue1 link'))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
785 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
786 # just verify that plain linking is working
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
787 self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
788
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
789 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1](issue1) link'))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
790 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
791 # just verify that plain linking is working
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
792 self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
793
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
794 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1](https://example.com/issue1) link'))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
795 self.assertIn( u2s(u'href="https://example.com/issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
796
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
797 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1] (https://example.com/issue1) link'))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
798 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
799 if type(self) == MistuneTestCase:
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
800 # mistune makes the https url into a real link
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
801 self.assertIn( u2s(u'href="https://example.com/issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
802 else:
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
803 # the other two engines leave the parenthesized url as is.
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
804 self.assertIn( u2s(u' (https://example.com/issue1) link'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
805
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
806 def test_string_markdown_link(self):
6109
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
807 # markdown2 and markdown escape the email address
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
808 try:
6109
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
809 from html import unescape as html_unescape
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
810 except ImportError:
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
811 from HTMLParser import HTMLParser
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
812 html_unescape = HTMLParser().unescape
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
813
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
814 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A link <cmeerw@example.com>'))
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
815 m = html_unescape(p.markdown().strip())
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
816 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
817
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
818 self.assertEqual(m, u2s(u'<p>A link <a href="mailto:cmeerw@example.com">cmeerw@example.com</a></p>'))
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
819
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
820 def test_string_markdown_javascript_link(self):
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
821 # make sure we don't get a "javascript:" link
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
822 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<javascript:alert(1)>'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
823 self.assertTrue(p.markdown().find('href="javascript:') == -1)
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
824
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
825 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[link](javascript:alert(1))'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
826 self.assertTrue(p.markdown().find('href="javascript:') == -1)
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
827
6284
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
828 def test_string_markdown_data_link(self):
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
829 # make sure we don't get a "data:" link
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
830 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==>'))
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
831 print(p.markdown())
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
832 self.assertTrue(p.markdown().find('href="data:') == -1)
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
833
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
834 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[data link](data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==)'))
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
835 print(p.markdown())
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
836 self.assertTrue(p.markdown().find('href="data:') == -1)
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
837
6274
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
838
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
839 def test_string_markdown_forced_line_break(self):
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
840 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'This is a set of text \n:that should have a break \n:at newlines. Each \n:colon should be the start of an html line'))
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
841 # sigh different backends render this differently:
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
842 # of text <br />
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
843 # of text<br>
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
844 # etc.
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
845 # Rather than using a different result for each
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
846 # renderer, look for '<br' and require three of them.
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
847 m = p.markdown()
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
848 print(m)
6274
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
849 self.assertEqual(3, m.count('<br'))
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
850
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
851 def test_string_markdown_code_block(self):
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
852 ''' also verify that embedded html is escaped '''
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
853 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block <pre>\n\n```\nline 1\nline 2\n```\n\nnew </pre> paragraph'))
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
854 self.assertEqual(p.markdown().strip().replace('\n\n', '\n'), u2s(u'<p>embedded code block &lt;pre&gt;</p>\n<pre><code>line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>'))
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
855
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
856 def test_string_markdown_code_block_attribute(self):
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
857 ''' also verify that embedded html is escaped '''
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
858 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block <pre>\n\n``` python\nline 1\nline 2\n```\n\nnew </pre> paragraph'))
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
859 m = p.markdown().strip()
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
860 print(m)
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
861 if type(self) == MistuneTestCase:
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
862 self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<pre><code class="lang-python">line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>')
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
863 elif type(self) == MarkdownTestCase:
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
864 self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<pre><code class="language-python">line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>')
6279
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
865 else:
6643
5b71a50e833b try to get more info on failing test
John Rouillard <rouilj@ieee.org>
parents: 6564
diff changeset
866 test_output = m.replace('\n\n', '\n')
6991
3085aac22f3a New markdown2 release changed output with code highlighting
John Rouillard <rouilj@ieee.org>
parents: 6832
diff changeset
867 expected_result = '<p>embedded code block &lt;pre&gt;</p>\n<div class="codehilite">\n<pre><span></span><code><span class="n">line</span> <span class="mi">1</span>\n<span class="n">line</span> <span class="mi">2</span>\n</code></pre>\n</div>\n<p>new &lt;/pre&gt; paragraph</p>'
6643
5b71a50e833b try to get more info on failing test
John Rouillard <rouilj@ieee.org>
parents: 6564
diff changeset
868 if test_output != expected_result:
6644
81d16e9f0f54 remove printing to stderr.
John Rouillard <rouilj@ieee.org>
parents: 6643
diff changeset
869 print("test_output:", test_output)
81d16e9f0f54 remove printing to stderr.
John Rouillard <rouilj@ieee.org>
parents: 6643
diff changeset
870 print("expected_result:", expected_result)
6643
5b71a50e833b try to get more info on failing test
John Rouillard <rouilj@ieee.org>
parents: 6564
diff changeset
871 self.assertEqual( test_output, expected_result)
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
872
6279
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
873 def test_markdown_return_text_on_exception(self):
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
874 ''' string is invalid markdown. missing end of fenced code block '''
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
875 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block <pre>\n\n``` python\nline 1\nline 2\n\n\nnew </pre> paragraph'))
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
876 m = p.markdown().strip()
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
877 print(m)
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
878 self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<p>``` python\nline 1\nline 2</p>\n<p>new &lt;/pre&gt; paragraph</p>')
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
879
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
880 def test_markdown_break_on_newline(self):
6277
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
881 self.client.db.config['MARKDOWN_BREAK_ON_NEWLINE'] = True
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
882 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with\nline break\ntwice.'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
883 m = p.markdown()
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
884 self.assertEqual(2, m.count('<br'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
885 self.client.db.config['MARKDOWN_BREAK_ON_NEWLINE'] = False
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
886
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
887 m = p.markdown()
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
888 self.assertEqual(0, m.count('<br'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
889
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
890 def test_markdown_hyperlinked_url(self):
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
891 # classic markdown does not emit a \n at end of rendered string
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
892 # so rstrip \n.
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
893 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'http://example.com/'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
894 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
895 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
896 print(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
897 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener">http://example.com/</a></p>')
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
898
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
899 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<http://example.com/>'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
900 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
901 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
902 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener">http://example.com/</a></p>')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
903
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
904 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[label](http://example.com/ "a title")'))
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
905 m = p.markdown(hyperlink=1)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
906 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
907 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener" title="a title">label</a></p>')
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
908
6299
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
909 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[label](http://example.com/).'))
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
910 m = p.markdown(hyperlink=1)
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
911 m = self.mangleMarkdown2(m)
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
912 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener">label</a>.</p>')
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
913
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
914 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'![](http://example.com/)'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
915 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
916 m = self.mangleMarkdown2(m)
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
917 self.assertIn(m, [
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
918 '<p><img src="http://example.com/" alt=""/></p>\n',
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
919 '<p><img src="http://example.com/" alt="" /></p>\n',
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
920 '<p><img src="http://example.com/" alt=""></p>\n',
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
921 '<p><img alt="" src="http://example.com/" /></p>', # markdown
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
922 ])
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
923
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
924 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An URL http://example.com/ with text'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
925 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
926 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
927 self.assertEqual(m.rstrip('\n'), '<p>An URL <a href="http://example.com/" rel="nofollow noopener">http://example.com/</a> with text</p>')
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
928
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
929 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An URL https://example.com/path with text'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
930 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
931 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
932 self.assertEqual(m.rstrip('\n'), '<p>An URL <a href="https://example.com/path" rel="nofollow noopener">https://example.com/path</a> with text</p>')
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
933
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
934 @skip_mistune
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
935 class MistuneTestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
936 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
937 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
938
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
939 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
940 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
941 templating.markdown = templating._import_mistune()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
942
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
943 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
944 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
945 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
946
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
947 @skip_markdown2
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
948 class Markdown2TestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
949 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
950 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
951
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
952 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
953 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
954 templating.markdown = templating._import_markdown2()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
955
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
956 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
957 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
958 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
959
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
960 @skip_markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
961 class MarkdownTestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
962 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
963 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
964
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
965 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
966 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
967 templating.markdown = templating._import_markdown()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
968
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
969 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
970 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
971 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
972
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
973
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
974 class NoMarkdownTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
975 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
976 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
977
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
978 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
979 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
980 templating.markdown = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
981
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
982 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
983 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
984 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
985
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
986 def test_string_markdown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
987 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string http://localhost with cmeerw@example.com <br> *embedded* \u00df'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
988 self.assertEqual(p.markdown(), u2s(u'A string <a href="http://localhost" rel="nofollow noopener">http://localhost</a> with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> &lt;br&gt; *embedded* \u00df'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
989
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
990 class NoRstTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
991 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
992 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
993
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
994 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
995 self.__ReStructuredText = templating.ReStructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
996 templating.ReStructuredText = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
997
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
998 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
999 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1000 templating.ReStructuredText = self.__ReStructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1001
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1002 def test_string_rst(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1003 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1004 self.assertEqual(p.rst(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1005
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1006 class NoStextTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1007 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1008 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1009
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1010 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1011 self.__StructuredText = templating.StructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1012 templating.StructuredText = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1013
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1014 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1015 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1016 templating.StructuredText = self.__StructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1017
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1018 def test_string_stext(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1019 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1020 self.assertEqual(p.stext(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1021
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1022
5815
fe35a232c6dc Make comment block raw to avoid travis ci warning on \d in comment block.
John Rouillard <rouilj@ieee.org>
parents: 5811
diff changeset
1023 r'''
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1024 class HTMLPermissions:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1025 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1026 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1027 def is_only_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1028 def view_check(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1029 def edit_check(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1030
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1031 def input_html4(**attrs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1032 def input_xhtml(**attrs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1033
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1034 class HTMLInputMixin:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1035 def __init__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1036
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1037 class HTMLClass(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1038 def __init__(self, client, classname, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1039 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1040 def __getitem__(self, item):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1041 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1042 def designator(self):
5811
7d276bb8b46d More invalid escape sequence fixes.
John Rouillard <rouilj@ieee.org>
parents: 5795
diff changeset
1043 def getItem(self, itemid, num_re=re.compile(r'-?\d+')):
5226
578e86e015f9 Changed function signature for properties to correspond to checkin:
John Rouillard <rouilj@ieee.org>
parents: 5211
diff changeset
1044 def properties(self, sort=1, cansearch=True):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1045 def list(self, sort_on=None):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1046 def csv(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1047 def propnames(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1048 def filter(self, request=None, filterspec={}, sort=(None,None),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1049 def classhelp(self, properties=None, label='(list)', width='500',
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1050 def submit(self, label="Submit New Entry"):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1051 def history(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1052 def renderWith(self, name, **kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1053
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1054 class HTMLItem(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1055 def __init__(self, client, classname, nodeid, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1056 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1057 def __getitem__(self, item):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1058 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1059 def designator(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1060 def is_retired(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1061 def submit(self, label="Submit Changes"):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1062 def journal(self, direction='descending'):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1063 def history(self, direction='descending', dre=re.compile('\d+')):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1064 def renderQueryForm(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1065
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1066 class HTMLUserPermission:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1067 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1068 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1069 def _user_perm_check(self, type):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1070
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1071 class HTMLUserClass(HTMLUserPermission, HTMLClass):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1072
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1073 class HTMLUser(HTMLUserPermission, HTMLItem):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1074 def __init__(self, client, classname, nodeid, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1075 def hasPermission(self, permission, classname=_marker):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1076
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1077 class HTMLProperty(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1078 def __init__(self, client, classname, nodeid, prop, name, value,
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1079 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1080 def __str__(self):
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1081 def __lt__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1082 def __le__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1083 def __eq__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1084 def __ne__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1085 def __gt__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1086 def __ge__(self, other):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1087 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1088 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1089
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1090 class StringHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1091 def _hyper_repl(self, match):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1092 def hyperlinked(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1093 def plain(self, escape=0, hyperlink=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1094 def stext(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1095 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1096 def multiline(self, escape=0, rows=5, cols=40):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1097 def email(self, escape=1):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1098
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1099 class PasswordHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1100 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1101 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1102 def confirm(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1103
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1104 class NumberHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1105 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1106 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1107 def __int__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1108 def __float__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1109
5067
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
1110 class IntegerHTMLProperty(HTMLProperty):
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
1111 def plain(self):
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
1112 def field(self, size = 30):
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
1113 def __int__(self):
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
1114
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1115 class BooleanHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1116 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1117 def field(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1118
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1119 class DateHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1120 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1121 def now(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1122 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1123 def reldate(self, pretty=1):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1124 def pretty(self, format=_marker):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1125 def local(self, offset):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1126
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1127 class IntervalHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1128 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1129 def pretty(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1130 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1131
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1132 class LinkHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1133 def __init__(self, *args, **kw):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1134 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1135 def plain(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1136 def field(self, showid=0, size=None):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1137 def menu(self, size=None, height=None, showid=0, additional=[],
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1138
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1139 class MultilinkHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1140 def __init__(self, *args, **kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1141 def __len__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1142 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1143 def __getitem__(self, num):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1144 def __contains__(self, value):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1145 def reverse(self):
5903
c3728772c594 Add reverse option to hyperdb property wrapper by David Sowder
John Rouillard <rouilj@ieee.org>
parents: 5815
diff changeset
1146 def sorted(self, property, reverse=False):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1147 def plain(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1148 def field(self, size=30, showid=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1149 def menu(self, size=None, height=None, showid=0, additional=[],
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1150
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1151 def make_key_function(db, classname, sort_on=None):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1152 def keyfunc(a):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1153
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1154 def find_sort_key(linkcl):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1155
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1156 def handleListCGIValue(value):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1157
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1158 class ShowDict:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1159 def __init__(self, columns):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1160 def __getitem__(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1161
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1162 class HTMLRequest(HTMLInputMixin):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1163 def __init__(self, client):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1164 def _post_init(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1165 def updateFromURL(self, url):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1166 def update(self, kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1167 def description(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1168 def __str__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1169 def indexargs_form(self, columns=1, sort=1, group=1, filter=1,
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1170 def indexargs_url(self, url, args):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1171 def base_javascript(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1172 def batch(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1173
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1174 class Batch(ZTUtils.Batch):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1175 def __init__(self, client, sequence, size, start, end=0, orphan=0,
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1176 def __getitem__(self, index):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1177 def propchanged(self, property):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1178 def previous(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1179 def next(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1180
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
1181 #class TemplatingUtils:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
1182 # def __init__(self, client):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
1183 # def Batch(self, sequence, size, start, end=0, orphan=0, overlap=0):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1184
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1185 class NoTemplate(Exception):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1186 class Unauthorised(Exception):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1187 def __init__(self, action, klass):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1188 def __str__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1189
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4647
diff changeset
1190 class Loader:
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1191 def __init__(self, dir):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1192 def precompileTemplates(self):
4727
5033c2ad80a7 templating: Rename LoaderBase.get() to LoaderBase.load() for clarity
anatoly techtonik <techtonik@gmail.com>
parents: 4720
diff changeset
1193 def load(self, name, extension=None):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1194 def __getitem__(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1195
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1196 class RoundupPageTemplate(PageTemplate.PageTemplate):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1197 def getContext(self, client, classname, request):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1198 def render(self, client, classname, request, **options):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1199 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1200 '''
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1201
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
1202 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/