annotate test/test_templating.py @ 6277:957a0fc20021

issue2551094 - markdown mismatch - new config for embedded newine Make earlier patch to fix mismatch between simplemde formatting of embedded newlines choosable. New option MARKDOWN_BREAK_ON_NEWLINE added to config.ini. If set to true all 4 renders: markdown, markdown2, mistune and simplemde will make a newline into a hard linebreak using <br> when displayed.
author John Rouillard <rouilj@ieee.org>
date Sun, 25 Oct 2020 16:12:15 -0400
parents bda491248fd8
children 9ec3a9bc4ea5
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
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
45 class MockDatabase(MockNull):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
46 def getclass(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
47 return self.classes[name]
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
49 # 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
50 storage = {}
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
51 def set(self, key, **props):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
52 MockDatabase.storage[key] = {}
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
53 MockDatabase.storage[key].update(props)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
54
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
55 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
56 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
57 return default
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
58 return MockDatabase.storage[key][field]
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
59
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
60 def exists(self,key):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
61 return key in MockDatabase.storage
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
62
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
63 def getOTKManager(self):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
64 return MockDatabase()
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
65
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
66 class TemplatingTestCase(unittest.TestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
67 def setUp(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
68 self.form = FieldStorage()
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
69 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
70 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
71 db.security.hasPermission = lambda *args, **kw: True
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
72 self.client.form = self.form
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
73
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
74 # 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
75 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
76 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
77 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
78
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
79 class HTMLDatabaseTestCase(TemplatingTestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
80 def test_HTMLDatabase___getitem__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
81 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
82 self.assertTrue(isinstance(db['issue'], HTMLClass))
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
83 # following assertions are invalid
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
84 # since roundup/cgi/templating.py r1.173.
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
85 # HTMLItem is function, not class,
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
86 # but HTMLUserClass and HTMLUser are passed on.
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
87 # 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
88 #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
89 #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
90 #self.assertTrue(isinstance(db['user1'], HTMLUser))
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
91
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
92 def test_HTMLDatabase___getattr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
93 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
94 self.assertTrue(isinstance(db.issue, HTMLClass))
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
95 # 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
96 #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
97 #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
98 #self.assertTrue(isinstance(db.user1, HTMLUser))
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
99
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
100 def test_HTMLDatabase_classes(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
101 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
102 db._db.classes = {'issue':MockNull(), 'user': MockNull()}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
103 db.classes()
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
104
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
105 class FunctionsTestCase(TemplatingTestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
106 def test_lookupIds(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
107 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
108 def lookup(key):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
109 if key == 'ok':
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
110 return '1'
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
111 if key == 'fail':
5378
35ea9b1efc14 Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5376
diff changeset
112 raise KeyError('fail')
3587
2372597ebbdb *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2716
diff changeset
113 return key
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
114 db._db.classes = {'issue': MockNull(lookup=lookup)}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
115 prop = MockNull(classname='issue')
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
116 self.assertEqual(lookupIds(db._db, prop, ['1','2']), ['1','2'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
117 self.assertEqual(lookupIds(db._db, prop, ['ok','2']), ['1','2'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
118 self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail'], 1),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
119 ['1', 'fail'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
120 self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail']), ['1'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
121
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
122 def test_lookupKeys(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
123 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
124 def get(entry, key):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
125 return {'1': 'green', '2': 'eggs'}.get(entry, entry)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
126 shrubbery = MockNull(get=get)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
127 db._db.classes = {'shrubbery': shrubbery}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
128 self.assertEqual(lookupKeys(shrubbery, 'spam', ['1','2']),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
129 ['green', 'eggs'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
130 self.assertEqual(lookupKeys(shrubbery, 'spam', ['ok','2']), ['ok',
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 'eggs'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
132
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
133 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
134
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
135 def test_link(self):
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
136 """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
137 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
138 def lookup(key) :
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
139 self.assertEqual(key, key.strip())
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
140 return "Status%s"%key
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
141 self.form.list.append(MiniFieldStorage("status", "1"))
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
142 self.form.list.append(MiniFieldStorage("status", "2"))
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
143 status = hyperdb.Link("status")
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
144 self.client.db.classes = dict \
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
145 ( 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
146 , 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
147 )
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
148 cls = HTMLClass(self.client, "issue")
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
149 cls["status"]
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
150
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
151 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
152 """`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
153 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
154 """
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
155 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
156 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
157 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
158 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
159 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
160 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
161 ( 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
162 , 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
163 )
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
164 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
165 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
166
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
167 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
168 '''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
169
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
170 Store the data in a mock db with the same api as the otk
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
171 db. Make sure nonce is 64 chars long. Lookup the nonce in
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
172 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
173 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
174 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
175
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
176 Consider three cases:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
177 * 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
178 * 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
179 * 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
180
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
181 '''
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
182
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
183 # 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
184 week_seconds = 604800
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
185
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
186 otks=self.client.db.getOTKManager()
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
187
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
188 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
189 print("Testing:", test)
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
190
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
191 if test == 'module':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
192 # test the module function
5488
52cb53eedf77 reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5485
diff changeset
193 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
194 # lifetime * 60 is the offset
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
195 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
196 elif test == 'template':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
197 # 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
198 cls = TemplatingUtils(self.client)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
199 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
200 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
201 elif test == 'default_time':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
202 # use the module function but with no lifetime
5488
52cb53eedf77 reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5485
diff changeset
203 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
204 # 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
205 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
206
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
207 self.assertEqual(len(nonce1), 64)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
208
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
209 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
210 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
211 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
212
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
213 self.assertEqual(uid, 10)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
214 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
215
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
216 now = time.time()
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
217
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
218 print("now, timestamp, greater, difference",
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
219 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
220
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
221
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
222 # 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
223 # 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
224 # 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
225 # 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
226 # 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
227 self.assertEqual(True,
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
228 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
229
5156
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
230 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
231 ''' 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
232 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
233 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
234
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
235 def test_string_email(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
236 ''' test that email obscures the email '''
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
237 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
238 self.assertEqual(p.email(), 'rouilj at foo example ...')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
239
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
240 def test_string_plain_or_hyperlinked(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
241 ''' test that email obscures the email '''
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
242 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
243 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
244 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
245 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
246 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
247
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
248 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;')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
249
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
250 @skip_rst
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
251 def test_string_rst(self):
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
252 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
253
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
254 # 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
255 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
256 q_result=u'''<div class="document">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
257 <div class="system-message">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
258 <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
259 <p>&quot;include&quot; directive disabled.</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
260 <pre class="literal-block">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
261 .. include:: XyZrMt.html
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
262
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
263 </pre>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
264 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
265 <p>&lt;badtag&gt;</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
266 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
267 '''
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
268
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
269 # 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
270 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
271 r_result='''<div class="document">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
272 <div class="system-message">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
273 <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
274 <p>&quot;raw&quot; directive disabled.</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
275 <pre class="literal-block">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
276 .. raw:: html
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
277
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
278 &lt;badtag&gt;
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
279
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
280 </pre>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
281 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
282 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
283 '''
6103
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
284 # test case to make sure javascript url's aren't turned into links
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
285 s = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<badtag>\njavascript:badcode'))
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
286 s_result = '<div class="document">\n<p>&lt;badtag&gt;\njavascript:badcode</p>\n</div>\n'
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
287
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
288 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
289 self.assertEqual(q.rst(), u2s(q_result))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
290 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
291 self.assertEqual(s.rst(), u2s(s_result))
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
292
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
293 @skip_stext
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
294 def test_string_stext(self):
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
295 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
296 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
297
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
298 def test_string_field(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
299 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
300 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
301
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
302 def test_string_multiline(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
303 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
304 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
305 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
306
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
307 def test_url_match(self):
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
308 '''Test the URL regular expression in StringHTMLProperty.
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
309 '''
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
310 def t(s, nothing=False, **groups):
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
311 m = StringHTMLProperty.hyper_re.search(s)
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
312 if nothing:
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
313 if m:
5793
6aad7b194e63 replace assertEquals wth assertEqual.
John Rouillard <rouilj@ieee.org>
parents: 5684
diff changeset
314 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
315 return
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
316 else:
5795
10747e4e4ec4 replace assertNotEquals with assertNotEqual
John Rouillard <rouilj@ieee.org>
parents: 5793
diff changeset
317 self.assertNotEqual(m, None, '%r did not match'%s)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
318 d = m.groupdict()
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
319 for g in groups:
5793
6aad7b194e63 replace assertEquals wth assertEqual.
John Rouillard <rouilj@ieee.org>
parents: 5684
diff changeset
320 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
321 groups[g], s))
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
322
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
323 #t('123.321.123.321', 'url')
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
324 t('http://localhost/', url='http://localhost/')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
325 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
326 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
327 t('http://richard:sekrit@localhost/',
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
328 url='http://richard:sekrit@localhost/')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
329 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
330 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
331 t('foo.a.ex', nothing=True)
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
332 t('StDevValidTimeSeries.GetObservation', nothing=True)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
333 t('http://a.ex', url='http://a.ex')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
334 t('http://a.ex/?foo&bar=baz\\.@!$%()qwerty',
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
335 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
336 t('www.foo.net', url='www.foo.net')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
337 t('richard@com.example', email='richard@com.example')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
338 t('r@a.com', email='r@a.com')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
339 t('i1', **{'class':'i', 'id':'1'})
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
340 t('item123', **{'class':'item', 'id':'123'})
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
341 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
342 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
343 t('123.35', nothing=True)
e77bcbdc9b32 add tests for numbers too :)
Richard Jones <richard@users.sourceforge.net>
parents: 4010
diff changeset
344 t('-.3535', nothing=True)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
345
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
346 def test_url_replace(self):
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
347 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
348 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
349 ae = self.assertEqual
4288
ce684080e968 issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents: 4040
diff changeset
350 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
351 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
352 '<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
353 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
354 '&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
355 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
356 '&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
357 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
358 '&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
359 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
360 '(<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
361 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
362 '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
363 '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
364 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
365 '(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
366 '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
367 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
368 '(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
369 '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
370 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
371 '(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
372 '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
373 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
374 '(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
375 '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
376 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
377 # 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
378 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
379 '<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
380 # 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
381 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
382 '<a href="http://roundup.net/%c/" rel="nofollow noopener">http://roundup.net/%c/</a>' % (c, c))
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
383
5989
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
384 def test_input_html4(self):
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
385 # 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
386 # 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
387 # e.g. disabled
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
388
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
389 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
390 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
391
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
392 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
393 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
394
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
395 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
396 input=input_html4(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
397 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
398
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
399 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
400 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
401 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
402
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
403 def test_input_xhtml(self):
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
404 # 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
405 # 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
406 # e.g. disabled="disabled"
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
407 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
408 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
409
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
410 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
411 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
412
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
413 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
414 input=input_xhtml(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
415 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
416
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
417 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
418 input=input_xhtml(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
419 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
420
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
421 # common markdown test cases
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
422 class MarkdownTests:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
423 def test_string_markdown(self):
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
424 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
425 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
426
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
427 def test_string_markdown_link(self):
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
428 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
429 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
430
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
431 def test_string_markdown_link(self):
6109
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
432 # 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
433 try:
6109
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
434 from html import unescape as html_unescape
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
435 except ImportError:
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
436 from HTMLParser import HTMLParser
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
437 html_unescape = HTMLParser().unescape
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
438
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
439 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A link <cmeerw@example.com>'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
440 self.assertEqual(html_unescape(p.markdown().strip()), u2s(u'<p>A link <a href="mailto:cmeerw@example.com">cmeerw@example.com</a></p>'))
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
441
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
442 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
443 # 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
444 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
445 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
446
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
447 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
448 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
449
6274
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
450
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
451 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
452 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
453 # sigh different backends render this differently:
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
454 # of text <br />
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
455 # of text<br>
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
456 # etc.
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
457 # 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
458 # 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
459 m = p.markdown()
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
460 self.assertEqual(3, m.count('<br'))
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
461
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
462 def test_string_markdown_code_block(self):
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
463 ''' also verify that embedded html is escaped '''
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
464 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
465 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
466
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
467 def test_string_markdown_code_block_attribute(self):
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
468 ''' also verify that embedded html is escaped '''
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
469 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
470 m = p.markdown().strip()
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
471 print(m)
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
472 if type(self) == MistuneTestCase:
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
473 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
474 elif type(self) == MarkdownTestCase:
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
475 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>')
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
476 else: # markdown2 doesn't handle attributes with code blocks
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
477 # so processing it returns original text
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
478 self.assertEqual(m.replace('\n\n', '\n'), u2s(u'embedded code block &lt;pre&gt;\n``` python\nline 1\nline 2\n```\nnew &lt;/pre&gt; paragraph'))
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
479
6277
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
480 def test_break_on_newline(self):
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
481 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
482 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
483 m = p.markdown()
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
484 self.assertEqual(2, m.count('<br'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
485 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
486
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
487 m = p.markdown()
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
488 self.assertEqual(0, m.count('<br'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
489
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
490
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
491 @skip_mistune
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
492 class MistuneTestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
493 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
494 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
495
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
496 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
497 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
498 templating.markdown = templating._import_mistune()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
499
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
500 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
501 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
502 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
503
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
504 @skip_markdown2
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
505 class Markdown2TestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
506 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
507 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
508
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
509 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
510 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
511 templating.markdown = templating._import_markdown2()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
512
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
513 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
514 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
515 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
516
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
517 @skip_markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
518 class MarkdownTestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
519 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
520 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
521
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
522 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
523 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
524 templating.markdown = templating._import_markdown()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
525
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
526 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
527 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
528 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
529
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
530
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
531 class NoMarkdownTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
532 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
533 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
534
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
535 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
536 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
537 templating.markdown = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
538
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
539 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
540 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
541 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
542
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
543 def test_string_markdown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
544 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
545 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
546
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
547 class NoRstTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
548 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
549 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
550
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
551 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
552 self.__ReStructuredText = templating.ReStructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
553 templating.ReStructuredText = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
554
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
555 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
556 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
557 templating.ReStructuredText = self.__ReStructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
558
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
559 def test_string_rst(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
560 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
561 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
562
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
563 class NoStextTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
564 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
565 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
566
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
567 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
568 self.__StructuredText = templating.StructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
569 templating.StructuredText = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
570
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
571 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
572 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
573 templating.StructuredText = self.__StructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
574
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
575 def test_string_stext(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
576 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
577 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
578
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
579
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
580 r'''
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
581 class HTMLPermissions:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
582 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
583 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
584 def is_only_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
585 def view_check(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
586 def edit_check(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
587
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
588 def input_html4(**attrs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
589 def input_xhtml(**attrs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
590
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
591 class HTMLInputMixin:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
592 def __init__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
593
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
594 class HTMLClass(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
595 def __init__(self, client, classname, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
596 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
597 def __getitem__(self, item):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
598 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
599 def designator(self):
5811
7d276bb8b46d More invalid escape sequence fixes.
John Rouillard <rouilj@ieee.org>
parents: 5795
diff changeset
600 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
601 def properties(self, sort=1, cansearch=True):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
602 def list(self, sort_on=None):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
603 def csv(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
604 def propnames(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
605 def filter(self, request=None, filterspec={}, sort=(None,None),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
606 def classhelp(self, properties=None, label='(list)', width='500',
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
607 def submit(self, label="Submit New Entry"):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
608 def history(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
609 def renderWith(self, name, **kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
610
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
611 class HTMLItem(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
612 def __init__(self, client, classname, nodeid, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
613 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
614 def __getitem__(self, item):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
615 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
616 def designator(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
617 def is_retired(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
618 def submit(self, label="Submit Changes"):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
619 def journal(self, direction='descending'):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
620 def history(self, direction='descending', dre=re.compile('\d+')):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
621 def renderQueryForm(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
622
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
623 class HTMLUserPermission:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
624 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
625 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
626 def _user_perm_check(self, type):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
627
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
628 class HTMLUserClass(HTMLUserPermission, HTMLClass):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
629
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
630 class HTMLUser(HTMLUserPermission, HTMLItem):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
631 def __init__(self, client, classname, nodeid, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
632 def hasPermission(self, permission, classname=_marker):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
633
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
634 class HTMLProperty(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
635 def __init__(self, client, classname, nodeid, prop, name, value,
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
636 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
637 def __str__(self):
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
638 def __lt__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
639 def __le__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
640 def __eq__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
641 def __ne__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
642 def __gt__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
643 def __ge__(self, other):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
644 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
645 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
646
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
647 class StringHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
648 def _hyper_repl(self, match):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
649 def hyperlinked(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
650 def plain(self, escape=0, hyperlink=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
651 def stext(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
652 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
653 def multiline(self, escape=0, rows=5, cols=40):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
654 def email(self, escape=1):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
655
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
656 class PasswordHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
657 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
658 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
659 def confirm(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
660
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
661 class NumberHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
662 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
663 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
664 def __int__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
665 def __float__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
666
5067
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
667 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
668 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
669 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
670 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
671
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
672 class BooleanHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
673 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
674 def field(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
675
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
676 class DateHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
677 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
678 def now(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
679 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
680 def reldate(self, pretty=1):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
681 def pretty(self, format=_marker):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
682 def local(self, offset):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
683
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
684 class IntervalHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
685 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
686 def pretty(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
687 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
688
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
689 class LinkHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
690 def __init__(self, *args, **kw):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
691 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
692 def plain(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
693 def field(self, showid=0, size=None):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
694 def menu(self, size=None, height=None, showid=0, additional=[],
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
695
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
696 class MultilinkHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
697 def __init__(self, *args, **kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
698 def __len__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
699 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
700 def __getitem__(self, num):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
701 def __contains__(self, value):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
702 def reverse(self):
5903
c3728772c594 Add reverse option to hyperdb property wrapper by David Sowder
John Rouillard <rouilj@ieee.org>
parents: 5815
diff changeset
703 def sorted(self, property, reverse=False):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
704 def plain(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
705 def field(self, size=30, showid=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
706 def menu(self, size=None, height=None, showid=0, additional=[],
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
707
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
708 def make_key_function(db, classname, sort_on=None):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
709 def keyfunc(a):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
710
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
711 def find_sort_key(linkcl):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
712
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
713 def handleListCGIValue(value):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
714
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
715 class ShowDict:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
716 def __init__(self, columns):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
717 def __getitem__(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
718
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
719 class HTMLRequest(HTMLInputMixin):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
720 def __init__(self, client):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
721 def _post_init(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
722 def updateFromURL(self, url):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
723 def update(self, kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
724 def description(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
725 def __str__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
726 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
727 def indexargs_url(self, url, args):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
728 def base_javascript(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
729 def batch(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
730
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
731 class Batch(ZTUtils.Batch):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
732 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
733 def __getitem__(self, index):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
734 def propchanged(self, property):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
735 def previous(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
736 def next(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
737
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
738 #class TemplatingUtils:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
739 # def __init__(self, client):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
740 # 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
741
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
742 class NoTemplate(Exception):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
743 class Unauthorised(Exception):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
744 def __init__(self, action, klass):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
745 def __str__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
746
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4647
diff changeset
747 class Loader:
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
748 def __init__(self, dir):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
749 def precompileTemplates(self):
4727
5033c2ad80a7 templating: Rename LoaderBase.get() to LoaderBase.load() for clarity
anatoly techtonik <techtonik@gmail.com>
parents: 4720
diff changeset
750 def load(self, name, extension=None):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
751 def __getitem__(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
752
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
753 class RoundupPageTemplate(PageTemplate.PageTemplate):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
754 def getContext(self, client, classname, request):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
755 def render(self, client, classname, request, **options):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
756 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
757 '''
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
758
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
759 # vim: set et sts=4 sw=4 :

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