annotate test/test_templating.py @ 8300:b99e76e76496

Make native date and number elements configurable Now for Number() and Integer() properties the browser-native number format can be configured with the use_browser_number_input config item in seciont [web]. The default is 'yes'. For Date() properties the config item is use_browser_date_input (also in section [web]) but the default is 'no'. In addition when defining Date() properties, these now have a parameter 'display_time' which defaults to 'yes' and a 'format' parameter which defaults to None. These set defaults for the field() method of the DateHTMLProperty which have the same parameters (but the display_time parameter of field() takes a boolean, not 'yes'/'no').
author Ralf Schlatterbeck <rsc@runtux.com>
date Wed, 19 Feb 2025 12:38:06 +0100
parents 46886073c665
children a81a3cd067fa
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
7032
f529cca242dc flake8: fix imports,
John Rouillard <rouilj@ieee.org>
parents: 6995
diff changeset
3 import time
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4
7582
978285986b2c fix: issue2551193 - Fix roundup for removal of cgi and cgitb ...
John Rouillard <rouilj@ieee.org>
parents: 7576
diff changeset
5 from roundup.anypy.cgi_ import FieldStorage, MiniFieldStorage
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
6 from roundup.cgi.templating import *
7866
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
7 from roundup.cgi.ZTUtils.Iterator import Iterator
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
8 from roundup.test import memorydb
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5378
diff changeset
9 from .test_actions import MockNull, true
6995
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
10 from .html_norm import NormalizingHtmlParser
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
12
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
13 import pytest
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
14 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
15
7576
7bdf9c0f74b9 Handle error id markdown2 not defined.
John Rouillard <rouilj@ieee.org>
parents: 7561
diff changeset
16 try:
7bdf9c0f74b9 Handle error id markdown2 not defined.
John Rouillard <rouilj@ieee.org>
parents: 7561
diff changeset
17 from markdown2 import __version_info__ as md2__version_info__
7bdf9c0f74b9 Handle error id markdown2 not defined.
John Rouillard <rouilj@ieee.org>
parents: 7561
diff changeset
18 except ImportError:
7bdf9c0f74b9 Handle error id markdown2 not defined.
John Rouillard <rouilj@ieee.org>
parents: 7561
diff changeset
19 md2__version_info__ = (0,0,0)
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
20
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
21 if ReStructuredText:
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
22 skip_rst = lambda func, *args, **kwargs: func
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
23 else:
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
24 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
25 reason='ReStructuredText not available'))
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
26
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
27 import roundup.cgi.templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
28 if roundup.cgi.templating._import_mistune():
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
29 skip_mistune = lambda func, *args, **kwargs: func
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
30 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
31 skip_mistune = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
32 reason='mistune not available'))
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
33
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
34 if roundup.cgi.templating._import_markdown2():
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
35 skip_markdown2 = lambda func, *args, **kwargs: func
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
36 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
37 skip_markdown2 = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
38 reason='markdown2 not available'))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
39
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
40 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
41 skip_markdown = lambda func, *args, **kwargs: func
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
42 else:
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
43 skip_markdown = mark_class(pytest.mark.skip(
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
44 reason='markdown not available'))
6097
90a1470edbea added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6096
diff changeset
45
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
46 from roundup.anypy.strings import u2s, s2u
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
47
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
48 from roundup.backends.sessions_common import SessionCommon
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
49
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
50 class MockConfig(dict):
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
51 def __getattr__(self, name):
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
52 try:
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
53 return self[name]
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
54 except KeyError as err:
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
55 raise AttributeError(err)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
56
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
57 class MockDatabase(MockNull, SessionCommon):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
58 def getclass(self, name):
6337
316c2c32dace Make testing mock smarter. Make getclass fail for invalid classes.
John Rouillard <rouilj@ieee.org>
parents: 6336
diff changeset
59 # limit class names
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
60 if name not in [ 'issue', 'user', 'status' ]:
6337
316c2c32dace Make testing mock smarter. Make getclass fail for invalid classes.
John Rouillard <rouilj@ieee.org>
parents: 6336
diff changeset
61 raise KeyError('There is no class called "%s"' % name)
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
62 # Class returned must have hasnode(id) method that returns true
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
63 # otherwise designators like 'issue1' can't be hyperlinked.
6338
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
64 self.classes[name].hasnode = lambda id: True if int(id) < 10 else False
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
65 return self.classes[name]
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
66
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
67 # 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
68 storage = {}
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
69 def set(self, key, **props):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
70 MockDatabase.storage[key] = {}
6817
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
71 if '__timestamp' not in props:
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
72 props['__timestamp'] = time.time() - 7*24*3600
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
73 MockDatabase.storage[key].update(props)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
74
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
75 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
76 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
77 return default
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
78 return MockDatabase.storage[key][field]
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
79
6817
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
80 def getall(self, key):
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
81 if key not in MockDatabase.storage:
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
82 return default
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
83 return MockDatabase.storage[key]
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
84
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
85 def exists(self,key):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
86 return key in MockDatabase.storage
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
87
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
88 def getOTKManager(self):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
89 return MockDatabase()
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
90
6817
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
91 def lifetime(self, seconds):
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
92 return time.time() - 7*24*3600 + seconds
38b73f7495f8 fix mock datbase
John Rouillard <rouilj@ieee.org>
parents: 6689
diff changeset
93
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
94 class TemplatingTestCase(unittest.TestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
95 def setUp(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
96 self.form = FieldStorage()
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97 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
98 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
99 db.security.hasPermission = lambda *args, **kw: True
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
100 self.client.form = self.form
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
101
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
102 # 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
103 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
104 self.client.db.getuid = lambda : 10
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
105 self.client.db.config = MockConfig (
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
106 {'WEB_CSRF_TOKEN_LIFETIME': 10,
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
107 '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
108
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
109 class HTMLDatabaseTestCase(TemplatingTestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
110 def test_HTMLDatabase___getitem__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
111 db = HTMLDatabase(self.client)
5649
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5488
diff changeset
112 self.assertTrue(isinstance(db['issue'], HTMLClass))
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
113 # following assertions are invalid
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
114 # since roundup/cgi/templating.py r1.173.
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
115 # HTMLItem is function, not class,
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
116 # but HTMLUserClass and HTMLUser are passed on.
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
117 # 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
118 #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
119 #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
120 #self.assertTrue(isinstance(db['user1'], HTMLUser))
2158
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_HTMLDatabase___getattr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
123 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
124 self.assertTrue(isinstance(db.issue, HTMLClass))
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
125 # 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
126 #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
127 #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
128 #self.assertTrue(isinstance(db.user1, HTMLUser))
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
129
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
130 def test_HTMLDatabase_classes(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
132 db._db.classes = {'issue':MockNull(), 'user': MockNull()}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
133 db.classes()
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
134
6689
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
135 def test_HTMLDatabase_list(self):
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
136 # The list method used to produce a traceback when a None value
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
137 # for an order attribute of a class was encountered. This
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
138 # happens when the 'get' of the order attribute for a numeric
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
139 # id produced a None value. So we put '23' as a key into the
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
140 # list and set things up that a None value is returned on 'get'.
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
141
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
142 # This keeps db.issue static, otherwise it changes for each call
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
143 db = MockNull(issue = HTMLDatabase(self.client).issue)
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
144 db.issue._klass.list = lambda : ['23', 'a', 'b']
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
145 # Make db.getclass return something that has a sensible 'get' method
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
146 mock = MockNull(get = lambda x, y : None)
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
147 db.issue._db.getclass = lambda x : mock
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
148 l = db.issue.list()
994893cf3e1a Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6645
diff changeset
149
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
150 class FunctionsTestCase(TemplatingTestCase):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
151 def test_lookupIds(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
152 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
153 def lookup(key):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
154 if key == 'ok':
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
155 return '1'
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
156 if key == 'fail':
5378
35ea9b1efc14 Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5376
diff changeset
157 raise KeyError('fail')
7936
a9b136565838 feat: issue1525113 - notation to filter by logged-in user
John Rouillard <rouilj@ieee.org>
parents: 7923
diff changeset
158 if key == '@current_user':
a9b136565838 feat: issue1525113 - notation to filter by logged-in user
John Rouillard <rouilj@ieee.org>
parents: 7923
diff changeset
159 raise KeyError('@current_user')
3587
2372597ebbdb *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2716
diff changeset
160 return key
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
161 db._db.classes = {'issue': MockNull(lookup=lookup)}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
162 prop = MockNull(classname='issue')
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
163 self.assertEqual(lookupIds(db._db, prop, ['1','2']), ['1','2'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
164 self.assertEqual(lookupIds(db._db, prop, ['ok','2']), ['1','2'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
165 self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail'], 1),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
166 ['1', 'fail'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
167 self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail']), ['1'])
7936
a9b136565838 feat: issue1525113 - notation to filter by logged-in user
John Rouillard <rouilj@ieee.org>
parents: 7923
diff changeset
168 self.assertEqual(lookupIds(db._db, prop, ['ok', '@current_user']),
a9b136565838 feat: issue1525113 - notation to filter by logged-in user
John Rouillard <rouilj@ieee.org>
parents: 7923
diff changeset
169 ['1'])
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
170
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
171 def test_lookupKeys(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
172 db = HTMLDatabase(self.client)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
173 def get(entry, key):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
174 return {'1': 'green', '2': 'eggs'}.get(entry, entry)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
175 shrubbery = MockNull(get=get)
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
176 db._db.classes = {'shrubbery': shrubbery}
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
177 self.assertEqual(lookupKeys(shrubbery, 'spam', ['1','2']),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
178 ['green', 'eggs'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
179 self.assertEqual(lookupKeys(shrubbery, 'spam', ['ok','2']), ['ok',
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
180 'eggs'])
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
181
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
182 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
183
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
184 def test_link(self):
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
185 """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
186 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
187 def lookup(key) :
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
188 self.assertEqual(key, key.strip())
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
189 return "Status%s"%key
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
190 self.form.list.append(MiniFieldStorage("issue@status", "1"))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
191 self.form.list.append(MiniFieldStorage("issue@status", "2"))
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
192 status = hyperdb.Link("status")
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
193 self.client.db.classes = dict \
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
194 ( 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
195 , 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
196 )
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
197 self.client.form = self.form
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
198 cls = HTMLClass(self.client, "issue")
6404
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
199
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
200 s = cls["status"]
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
201 self.assertEqual(s._value, '1')
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
202
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
203 def test_link_default(self):
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
204 """Make sure default value for link is returned
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
205 if new item and no value in form."""
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
206 def lookup(key) :
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
207 self.assertEqual(key, key.strip())
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
208 return "Status%s"%key
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
209 status = hyperdb.Link("status")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
210 # set default_value
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
211 status.__dict__['_Type__default_value'] = "4"
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
212
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
213 self.client.db.classes = dict \
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
214 ( issue = MockNull(getprops = lambda : dict(status = status))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
215 , status = MockNull(get = lambda id, name : id, lookup = lookup, get_default_value = lambda: 4)
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
216 )
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
217 self.client.form = self.form
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
218
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
219 cls = HTMLClass(self.client, "issue")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
220 s = cls["status"]
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
221 self.assertEqual(s._value, '4')
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
222
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
223 def test_link_with_value_and_default(self):
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
224 """Make sure default value is not used if there
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
225 is a value in the form."""
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
226 def lookup(key) :
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
227 self.assertEqual(key, key.strip())
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
228 return "Status%s"%key
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
229 self.form.list.append(MiniFieldStorage("issue@status", "2"))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
230 self.form.list.append(MiniFieldStorage("issue@status", "1"))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
231 status = hyperdb.Link("status")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
232 # set default_value
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
233 status.__dict__['_Type__default_value'] = "4"
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
234
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
235 self.client.db.classes = dict \
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
236 ( issue = MockNull(getprops = lambda : dict(status = status))
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
237 , status = MockNull(get = lambda id, name : id, lookup = lookup, get_default_value = lambda: 4)
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
238 )
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
239 self.client.form = self.form
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
240
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
241 cls = HTMLClass(self.client, "issue")
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
242 s = cls["status"]
e29d5f4e0af4 issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents: 6377
diff changeset
243 self.assertEqual(s._value, '2')
4040
b6a2251394dd Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents: 4011
diff changeset
244
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
245 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
246 """`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
247 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
248 """
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
249 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
250 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
251 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
252 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
253 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
254 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
255 ( 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
256 , 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
257 )
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
258 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
259 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
260
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
261 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
262 '''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
263
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
264 Store the data in a mock db with the same api as the otk
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
265 db. Make sure nonce is 54 chars long. Lookup the nonce in
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
266 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
267 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
268 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
269
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
270 Consider three cases:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
271 * 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
272 * 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
273 * 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
274
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
275 '''
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
276
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
277 # 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
278 week_seconds = 604800
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
279
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
280 otks=self.client.db.getOTKManager()
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
281
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
282 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
283 print("Testing:", test)
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
284
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
285 if test == 'module':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
286 # test the module function
5488
52cb53eedf77 reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5485
diff changeset
287 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
288 # lifetime * 60 is the offset
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
289 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
290 elif test == 'template':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
291 # 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
292 cls = TemplatingUtils(self.client)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
293 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
294 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
295 elif test == 'default_time':
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
296 # use the module function but with no lifetime
5488
52cb53eedf77 reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5485
diff changeset
297 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
298 # 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
299 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
300
6826
28b906a237d8 Fix anti_csrf_nonce test
John Rouillard <rouilj@ieee.org>
parents: 6817
diff changeset
301 self.assertEqual(len(nonce1), 54)
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
302
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
303 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
304 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
305 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
306
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
307 self.assertEqual(uid, 10)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
308 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
309
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
310 now = time.time()
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
311
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
312 print("now, timestamp, greater, difference",
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5226
diff changeset
313 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
314
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
315
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
316 # 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
317 # 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
318 # 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
319 # 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
320 # 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
321 self.assertEqual(True,
5211
f4b6a2a3e605 Fix expiration dates and expire csrf tokens properly
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
322 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
323
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
324 def test_number__int__(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
325 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
326 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
327 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
328 self.assertEqual(p.__int__(), 2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
329
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
330 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
331 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
332 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
333 with self.assertRaises(TypeError) as e:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
334 p.__int__()
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
335
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
336 def test_number__float__(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
337 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
338 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
339 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
340 self.assertEqual(p.__float__(), 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
341
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
342 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
343 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
344 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
345 with self.assertRaises(TypeError) as e:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
346 p.__float__()
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
347
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
348 def test_number_field(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
349 import sys
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
350
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
351 _py3 = sys.version_info[0] > 2
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
352
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
353 # python2 truncates while python3 rounds. Sigh.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
354 if _py3:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
355 expected_val = 2345678.2345678
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
356 else:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
357 expected_val = 2345678.23457
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
358
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
359 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
360 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
361 2345678.2345678)
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
362 self.client.db.config['WEB_USE_BROWSER_NUMBER_INPUT'] = False
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
363 self.assertEqual(p.field(),
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
364 ('<input id="testnum1@test" name="testnum1@test" '
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
365 'size="30" type="text" value="%s">')%expected_val)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
366 self.client.db.config['WEB_USE_BROWSER_NUMBER_INPUT'] = True
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
367 self.assertEqual(p.field(),
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
368 ('<input id="testnum1@test" name="testnum1@test" '
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
369 'size="30" type="number" value="%s">')%expected_val)
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
370 self.assertEqual(p.field(size=10),
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
371 ('<input id="testnum1@test" name="testnum1@test" '
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
372 'size="10" type="number" value="%s">')%expected_val)
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
373 self.assertEqual(p.field(size=10, dataprop="foo", dataprop2=5),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
374 ('<input dataprop="foo" dataprop2="5" '
8281
669dfccca898 issue2551391 - checkboxes and radiobutton inputs get wrong id's.
John Rouillard <rouilj@ieee.org>
parents: 7936
diff changeset
375 'id="testnum1@test" name="testnum1@test" '
8287
60e682add9ea test - fix broken test
John Rouillard <rouilj@ieee.org>
parents: 8286
diff changeset
376 'size="10" type="number" '
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
377 'value="%s">'%expected_val))
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
378
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
379 self.assertEqual(p.field(size=10, klass="class1",
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
380 **{ "class": "class2 class3",
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
381 "data-prop": "foo",
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
382 "data-prop2": 5}),
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
383 ('<input class="class2 class3" data-prop="foo" '
8281
669dfccca898 issue2551391 - checkboxes and radiobutton inputs get wrong id's.
John Rouillard <rouilj@ieee.org>
parents: 7936
diff changeset
384 'data-prop2="5" id="testnum1@test" '
669dfccca898 issue2551391 - checkboxes and radiobutton inputs get wrong id's.
John Rouillard <rouilj@ieee.org>
parents: 7936
diff changeset
385 'klass="class1" '
8287
60e682add9ea test - fix broken test
John Rouillard <rouilj@ieee.org>
parents: 8286
diff changeset
386 'name="testnum1@test" size="10" type="number" '
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
387 'value="%s">')%expected_val)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
388
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
389 # get plain representation if user can't edit
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
390 p.is_edit_ok = lambda: False
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
391 self.assertEqual(p.field(), p.plain())
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
392
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
393 # test with string which is wrong type
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
394 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
8287
60e682add9ea test - fix broken test
John Rouillard <rouilj@ieee.org>
parents: 8286
diff changeset
395 "234567e.2345678")
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
396 self.assertEqual(p.field(),
8281
669dfccca898 issue2551391 - checkboxes and radiobutton inputs get wrong id's.
John Rouillard <rouilj@ieee.org>
parents: 7936
diff changeset
397 ('<input id="testnum1@test" name="testnum1@test" '
8287
60e682add9ea test - fix broken test
John Rouillard <rouilj@ieee.org>
parents: 8286
diff changeset
398 'size="30" type="number" value="234567e.2345678">'))
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
399
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
400 # test with None value, pretend property.__default_value = Null which
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
401 # is the default. It would be returned by get_default_value
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
402 # which I mock.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
403 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
404 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
405 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
406 self.assertEqual(p.field(),
8281
669dfccca898 issue2551391 - checkboxes and radiobutton inputs get wrong id's.
John Rouillard <rouilj@ieee.org>
parents: 7936
diff changeset
407 ('<input id="testnum1@test" name="testnum1@test" '
8287
60e682add9ea test - fix broken test
John Rouillard <rouilj@ieee.org>
parents: 8286
diff changeset
408 'size="30" type="number" value="">'))
6832
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
409
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
410 def test_number_plain(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
411 import sys
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
412
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
413 _py3 = sys.version_info[0] > 2
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
414
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
415 # python2 truncates while python3 rounds. Sigh.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
416 if _py3:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
417 expected_val = 2345678.2345678
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
418 else:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
419 expected_val = 2345678.23457
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
420
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
421 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
422 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
423
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
424 self.assertEqual(p.plain(), "%s"%expected_val)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
425
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
426 def test_number_pretty(self):
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
427 # test with number
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
428 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
429 2345678.2345678)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
430 self.assertEqual(p.pretty(), "2345678.235")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
431
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
432 # test with string which is wrong type
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
433 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
434 "2345678.2345678")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
435 self.assertEqual(p.pretty(), "2345678.2345678")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
436
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
437 # test with boolean
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
438 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test',
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
439 True)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
440 self.assertEqual(p.pretty(), "1.000")
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
441
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
442 # test with None value, pretend property.__default_value = Null which
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
443 # is the default. It would be returned by get_default_value
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
444 # which I mock.
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
445 property = MockNull(get_default_value = lambda: None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
446 p = NumberHTMLProperty(self.client, 'testnum', '1', property,
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
447 'test', None)
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
448 self.assertEqual(p.pretty(), '')
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
449
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
450 with self.assertRaises(ValueError) as e:
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
451 p.pretty('%0.3')
234fefd7568a issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents: 6826
diff changeset
452
5156
882fa4d9bead issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents: 5067
diff changeset
453 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
454 ''' 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
455 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
456 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
457
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
458 def test_string_email(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
459 ''' test that email obscures the email '''
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
460 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
461 self.assertEqual(p.email(), 'rouilj at foo example ...')
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
462
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
463 def test_string_wrapped(self):
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
464 test_string = ('A long string that needs to be wrapped to'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
465 ' 80 characters and no more. Put in a link issue1.'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
466 ' Put in <html> to be escaped. Put in a'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
467 ' https://example.com/link as well. Let us see if'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
468 ' it will wrap properly.' )
7864
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
469
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
470 test_result_wrap = {}
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
471 test_result_wrap[80] = ('A long string that needs to be wrapped to 80'
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
472 ' characters and no more. Put in a\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
473 'link <a href="issue1">issue1</a>. Put in'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
474 ' &lt;html&gt; to be escaped. Put in a <a'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
475 ' href="https://example.com/link"'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
476 ' rel="nofollow noopener">'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
477 'https://example.com/link</a> as\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
478 'well. Let us see if it will wrap properly.')
7864
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
479 test_result_wrap[20] = (
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
480 'A long string that\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
481 'needs to be wrapped\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
482 'to 80 characters and\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
483 'no more. Put in a\nlink <a href="issue1">issue1</a>. Put in\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
484 '&lt;html&gt; to be\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
485 'escaped. Put in a\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
486 '<a href="https://example.com/link" rel="nofollow '
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
487 'noopener">https://example.com/link</a>\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
488 'as well. Let us see\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
489 'if it will wrap\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
490 'properly.')
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
491 test_result_wrap[100] = (
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
492 'A long string that needs to be wrapped to 80 characters and no more. Put in a link <a href="issue1">issue1</a>. Put in\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
493 '&lt;html&gt; to be escaped. Put in a <a href="https://example.com/link" rel="nofollow noopener">https://example.com/link</a> as well. Let us see if it will wrap\n'
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
494 'properly.')
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
495
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
496 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
497 test_string)
7864
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
498
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
499 for i in [80, 20, 100]:
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
500 wrapped = p.wrapped(columns=i)
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
501 print(wrapped)
b080cdb8b199 fix: document/fix wrapped HtmlProperty method.
John Rouillard <rouilj@ieee.org>
parents: 7582
diff changeset
502 self.assertEqual(wrapped, test_result_wrap[i])
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
503
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
504 def test_string_plain_or_hyperlinked(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
505 ''' test that email obscures the email '''
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
506 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
507 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
508 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
509 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
510 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
511
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
512 self.assertEqual(p.hyperlinked(), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
6338
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
513 # check designators
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
514 for designator in [ "issue1", "issue 1" ]:
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
515 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
516 self.assertEqual(p.hyperlinked(),
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
517 '<a href="issue1">%s</a>'%designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
518
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
519 # issue 100 > 10 which is a magic number for the mocked hasnode
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
520 # If id number is greater than 10 hasnode reports it does not have
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
521 # the node.
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
522 for designator in ['issue100', 'issue 100']:
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
523 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
524 designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
525 self.assertEqual(p.hyperlinked(), designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
526
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
527 # zoom class does not exist
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
528 for designator in ['zoom1', 'zoom100', 'zoom 1']:
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
529 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
530 designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
531 self.assertEqual(p.hyperlinked(), designator)
a70a0c138dd9 Test hyperlinked method on designators
John Rouillard <rouilj@ieee.org>
parents: 6337
diff changeset
532
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
533
6096
c914b3d8362f If rst missing skip; initial attempt to test structuredtext.
John Rouillard <rouilj@ieee.org>
parents: 6095
diff changeset
534 @skip_rst
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
535 def test_string_rst(self):
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
536 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
537
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
538 # 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
539 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
540 q_result=u'''<div class="document">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
541 <div class="system-message">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
542 <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
543 <p>&quot;include&quot; directive disabled.</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
544 <pre class="literal-block">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
545 .. include:: XyZrMt.html
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
546
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
547 </pre>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
548 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
549 <p>&lt;badtag&gt;</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
550 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
551 '''
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
552
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
553 # 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
554 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
555 r_result='''<div class="document">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
556 <div class="system-message">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
557 <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
558 <p>&quot;raw&quot; directive disabled.</p>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
559 <pre class="literal-block">
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
560 .. raw:: html
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
561
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
562 &lt;badtag&gt;
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
563
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
564 </pre>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
565 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
566 </div>
72a281a55a17 Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents: 6097
diff changeset
567 '''
6284
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
568 # test case to make sure javascript and data url's aren't turned
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
569 # into links
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
570 s = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<badtag>\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=='))
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
571 s_result = '<div class="document">\n<p>&lt;badtag&gt;\njavascript:badcode data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==</p>\n</div>\n'
6103
af16c135fb98 url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents: 6099
diff changeset
572
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
573 # test url recognition
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
574 t = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'link is https://example.com/link for testing.'))
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
575 t_result = '<div class="document">\n<p>link is <a class="reference external" href="https://example.com/link">https://example.com/link</a> for testing.</p>\n</div>\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
576
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
577 # test text that doesn't need to be processed
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
578 u = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'Just a plain old string here. Nothig to process.'))
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
579 u_result = '<div class="document">\n<p>Just a plain old string here. Nothig to process.</p>\n</div>\n'
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
580
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
581 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
582 self.assertEqual(q.rst(), u2s(q_result))
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
583 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
584 self.assertEqual(s.rst(), u2s(s_result))
6339
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
585 self.assertEqual(t.rst(), u2s(t_result))
ab18fe956d45 Test StringHTMLProperty.wrapped(); test url, plain text for rst
John Rouillard <rouilj@ieee.org>
parents: 6338
diff changeset
586 self.assertEqual(u.rst(), u2s(u_result))
6095
3ada6a3f48e1 fixed ReStructuredText encoding with Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6059
diff changeset
587
5157
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
588 def test_string_field(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
589 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded &lt; html</b>')
8281
669dfccca898 issue2551391 - checkboxes and radiobutton inputs get wrong id's.
John Rouillard <rouilj@ieee.org>
parents: 7936
diff changeset
590 self.assertEqual(p.field(), '<input id="test1@test" 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
591
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
592 def test_string_multiline(self):
ae2a5d1afdd5 adding tests for some StringHTMLProperty methods.
John Rouillard <rouilj@ieee.org>
parents: 5156
diff changeset
593 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
594 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
595 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
596
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
597 def test_url_match(self):
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
598 '''Test the URL regular expression in StringHTMLProperty.
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
599 '''
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
600 def t(s, nothing=False, **groups):
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
601 m = StringHTMLProperty.hyper_re.search(s)
4009
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
602 if nothing:
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
603 if m:
5793
6aad7b194e63 replace assertEquals wth assertEqual.
John Rouillard <rouilj@ieee.org>
parents: 5684
diff changeset
604 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
605 return
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
606 else:
5795
10747e4e4ec4 replace assertNotEquals with assertNotEqual
John Rouillard <rouilj@ieee.org>
parents: 5793
diff changeset
607 self.assertNotEqual(m, None, '%r did not match'%s)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
608 d = m.groupdict()
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
609 for g in groups:
5793
6aad7b194e63 replace assertEquals wth assertEqual.
John Rouillard <rouilj@ieee.org>
parents: 5684
diff changeset
610 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
611 groups[g], s))
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
612
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
613 #t('123.321.123.321', 'url')
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
614 t('https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4', url="https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4")
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
615 t('http://localhost/', url='http://localhost/')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
616 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
617 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
618 t('http://richard:sekrit@localhost/',
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
619 url='http://richard:sekrit@localhost/')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
620 t('<HTTP://roundup.net/>', url='HTTP://roundup.net/')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
621 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
622 t('foo.a.ex', nothing=True)
e335ce40d6c8 Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents: 3991
diff changeset
623 t('StDevValidTimeSeries.GetObservation', nothing=True)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
624 t('http://a.ex', url='http://a.ex')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
625 t('http://a.ex/?foo&bar=baz\\.@!$%()qwerty',
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
626 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
627 t('www.foo.net', url='www.foo.net')
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
628 t('richard@com.example', email='richard@com.example')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
629 t('r@a.com', email='r@a.com')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
630 t('i1', **{'class':'i', 'id':'1'})
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
631 t('item123', **{'class':'item', 'id':'123'})
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
632 t('item 123', **{'class':'item', 'id':'123'})
4010
797eacd945af add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents: 4009
diff changeset
633 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
634 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
635 t('123.35', nothing=True)
e77bcbdc9b32 add tests for numbers too :)
Richard Jones <richard@users.sourceforge.net>
parents: 4010
diff changeset
636 t('-.3535', nothing=True)
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
637
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
638 def test_url_replace(self):
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
639 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
640 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
641 ae = self.assertEqual
6564
21c7c2041a4b issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents: 6551
diff changeset
642 ae(t('issue5#msg10'), '<a href="issue5#msg10">issue5#msg10</a>')
21c7c2041a4b issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents: 6551
diff changeset
643 ae(t('issue5'), '<a href="issue5">issue5</a>')
21c7c2041a4b issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents: 6551
diff changeset
644 ae(t('issue2255'), 'issue2255')
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
645 ae(t('foo https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4 bar'),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
646 'foo <a href="https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4" rel="nofollow noopener">'
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
647 'https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4</a> bar')
4288
ce684080e968 issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents: 4040
diff changeset
648 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
649 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
650 '<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
651 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
652 '&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
653 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
654 '&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
655 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
656 '&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
657 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
658 '(<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
659 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
660 '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
661 '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
662 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
663 '(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
664 '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
665 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
666 '(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
667 '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
668 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
669 '(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
670 '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
671 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
672 '(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
673 '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
674 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
675 # 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
676 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
677 '<a href="http://roundup.net/" rel="nofollow noopener">http://roundup.net/</a>%c ' % c)
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
678 # trailing punctuation is not included without trailing space
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
679 ae(t('http://roundup.net/%c' % c),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
680 '<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
681 # 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
682 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
683 '<a href="http://roundup.net/%c/" rel="nofollow noopener">http://roundup.net/%c/</a>' % (c, c))
6551
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
684 # including with a non / terminated path
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
685 ae(t('http://roundup.net/test%c ' % c),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
686 '<a href="http://roundup.net/test" rel="nofollow noopener">http://roundup.net/test</a>%c ' % c)
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
687 # but it's included if it's part of the URL path
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
688 ae(t('http://roundup.net/%ctest' % c),
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
689 '<a href="http://roundup.net/%ctest" rel="nofollow noopener">http://roundup.net/%ctest</a>' % (c, c))
f1f8d75edd97 Add variations on test for _hyper_url functons
John Rouillard <rouilj@ieee.org>
parents: 6404
diff changeset
690
3991
13161539e5bd improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents: 3972
diff changeset
691
5989
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
692 def test_input_html4(self):
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
693 # 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
694 # 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
695 # e.g. disabled
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
696
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
697 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
698 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
699
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
700 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
701 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
702
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
703 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
704 input=input_html4(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
705 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
706
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
707 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
708 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
709 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
710
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
711 def test_input_xhtml(self):
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
712 # 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
713 # 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
714 # e.g. disabled="disabled"
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
715 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
716 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
717
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
718 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
719 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
720
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
721 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
722 input=input_xhtml(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
723 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
724
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
725 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
726 input=input_xhtml(**attrs)
c475159af6b8 Add test and changelog for html boolean fix.
John Rouillard <rouilj@ieee.org>
parents: 5903
diff changeset
727 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
728
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
729
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
730 class HTMLPropertyTestClass(unittest.TestCase):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
731 def setUp(self):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
732 self.form = FieldStorage()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
733 self.client = MockNull()
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
734 self.client.db = db = memorydb.create('admin')
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
735 db.tx_Source = "web"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
736
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
737 db.issue.addprop(tx_Source=hyperdb.String())
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
738
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
739 db.security.hasPermission = lambda *args, **kw: True
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
740 self.client.form = self.form
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
741
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
742 self.client._props = MockNull()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
743 # add client props for testing anti_csrf_nonce
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
744 self.client.session_api = MockNull(_sid="1234567890")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
745 self.client.db.getuid = lambda : 10
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
746
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
747 @pytest.fixture(autouse=True)
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
748 def inject_fixtures(self, caplog):
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
749 self._caplog = caplog
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
750
8288
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
751 class BooleanHTMLPropertyTestCase(HTMLPropertyTestClass):
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
752
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
753 def setUp(self):
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
754 super(BooleanHTMLPropertyTestCase, self).setUp()
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
755
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
756 db = self.client.db
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
757 db.issue.addprop(boolvalt=hyperdb.Boolean())
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
758 db.issue.addprop(boolvalf=hyperdb.Boolean())
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
759 db.issue.addprop(boolvalunset=hyperdb.Boolean())
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
760
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
761 self.client.db.issue.create(title="title",
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
762 boolvalt = True,
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
763 boolvalf = False)
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
764
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
765 def tearDown(self):
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
766 self.client.db.close()
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
767 memorydb.db_nuke('')
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
768
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
769 testdata = [
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
770 ("boolvalt", "Yes", True, False),
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
771 ("boolvalf", "No", False, True),
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
772 ("boolvalunset", "", False, True),
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
773 ]
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
774
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
775 def test_BoolHTMLRadioButtons(self):
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
776 #propname = "boolvalt"
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
777
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
778 #plainval = "Yes"
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
779
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
780 self.maxDiff = None
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
781 for test_inputs in self.testdata:
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
782 params = {
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
783 "check1": 'checked="checked" ' if test_inputs[2] else "",
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
784 "check2": 'checked="checked" ' if test_inputs[3] else "",
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
785 "propname": test_inputs[0],
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
786 "plainval": test_inputs[1],
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
787
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
788 }
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
789
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
790
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
791 test_hyperdbBoolean = self.client.db.issue.getprops("1")[
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
792 params['propname']]
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
793 test_boolean = self.client.db.issue.get("1", params['propname'])
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
794
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
795 # client, classname, nodeid, prop, name, value,
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
796 # anonymous=0, offset=None
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
797 d = BooleanHTMLProperty(self.client, 'issue', '1',
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
798 test_hyperdbBoolean,
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
799 params['propname'], test_boolean)
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
800
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
801 self.assertIsInstance(d._value, (type(None), bool))
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
802
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
803 self.assertEqual(d.plain(), params['plainval'])
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
804
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
805 input_expected = (
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
806 '<input %(check1)sid="issue1@%(propname)s_yes" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
807 'name="issue1@%(propname)s" type="radio" value="yes">'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
808 '<label class="rblabel" for="issue1@%(propname)s_yes">'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
809 'Yes</label>'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
810 '<input %(check2)sid="issue1@%(propname)s_no" name="issue1@%(propname)s" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
811 'type="radio" value="no"><label class="rblabel" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
812 'for="issue1@%(propname)s_no">No</label>') % params
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
813
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
814 self.assertEqual(d.field(), input_expected)
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
815
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
816 y_label = ( '<label class="rblabel" for="issue1@%(propname)s_yes">'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
817 'True</label>') % params
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
818 n_label = ('<label class="rblabel" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
819 'for="issue1@%(propname)s_no">False</label>') % params
8289
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
820 u_label = ('<label class="rblabel" '
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
821 'for="issue1@%(propname)s_unk">Ignore</label>') % params
8288
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
822
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
823 input_expected = (
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
824 '<input %(check1)sid="issue1@%(propname)s_yes" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
825 'name="issue1@%(propname)s" type="radio" value="yes">'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
826 + y_label +
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
827 '<input %(check2)sid="issue1@%(propname)s_no" name="issue1@%(propname)s" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
828 'type="radio" value="no">' + n_label ) % params
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
829
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
830 self.assertEqual(d.field(y_label=y_label, n_label=n_label), input_expected)
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
831
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
832
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
833 input_expected = (
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
834 '<label class="rblabel" for="issue1@%(propname)s_yes">'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
835 'Yes</label>'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
836 '<input %(check1)sid="issue1@%(propname)s_yes" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
837 'name="issue1@%(propname)s" type="radio" value="yes">'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
838 '<label class="rblabel" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
839 'for="issue1@%(propname)s_no">No</label>'
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
840 '<input %(check2)sid="issue1@%(propname)s_no" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
841 'name="issue1@%(propname)s" '
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
842 'type="radio" value="no">') % params
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
843
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
844 print(d.field(labelfirst=True))
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
845 self.assertEqual(d.field(labelfirst=True), input_expected)
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
846
8289
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
847 input_expected = (
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
848 '<label class="rblabel" for="issue1@%(propname)s_unk">'
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
849 'Ignore</label>'
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
850 '<input id="issue1@%(propname)s_unk" '
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
851 'name="issue1@%(propname)s" type="radio" value="">'
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
852 '<input %(check1)sid="issue1@%(propname)s_yes" '
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
853 'name="issue1@%(propname)s" type="radio" value="yes">'
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
854 '<label class="rblabel" for="issue1@%(propname)s_yes">'
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
855 'Yes</label>'
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
856 '<input %(check2)sid="issue1@%(propname)s_no" name="issue1@%(propname)s" '
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
857 'type="radio" value="no"><label class="rblabel" '
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
858 'for="issue1@%(propname)s_no">No</label>') % params
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
859
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
860 self.assertEqual(d.field(u_label=u_label), input_expected)
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
861
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
862
46886073c665 refactor: change method used to assign radiobuttons for boolean
John Rouillard <rouilj@ieee.org>
parents: 8288
diff changeset
863 # one test with the last d is enough.
8288
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
864 # check permissions return
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
865 is_view_ok_orig = d.is_view_ok
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
866 is_edit_ok_orig = d.is_edit_ok
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
867 no_access = lambda : False
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
868
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
869 d.is_view_ok = no_access
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
870 self.assertEqual(d.plain(), "[hidden]")
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
871
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
872 d.is_edit_ok = no_access
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
873 self.assertEqual(d.field(), "[hidden]")
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
874
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
875 d.is_view_ok = is_view_ok_orig
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
876 self.assertEqual(d.field(), params['plainval'])
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
877 d.is_edit_ok = is_edit_ok_orig
e70dc7c43c9c test: basic testing for BooleanHTMLProperty
John Rouillard <rouilj@ieee.org>
parents: 8287
diff changeset
878
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
879 class DateHTMLPropertyTestCase(HTMLPropertyTestClass):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
880
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
881 def setUp(self):
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
882 super(DateHTMLPropertyTestCase, self).setUp()
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
883
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
884 db = self.client.db
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
885 db.issue.addprop(deadline=hyperdb.Date())
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
886
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
887 self.test_datestring = "2021-01-01.11:22:10"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
888
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
889 self.client.db.issue.create(title="title",
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
890 deadline=date.Date(self.test_datestring))
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
891 self.client.db.getUserTimezone = lambda: "2"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
892
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
893 def tearDown(self):
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
894 self.client.db.close()
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
895 memorydb.db_nuke('')
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
896
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
897 def exp_classhelp(self, cls='issue', prop='deadline', dlm='.'):
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
898 value = dlm.join (('2021-01-01', '11:22:10'))
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
899 return ('<a class="classhelp" data-calurl="%(cls)s?'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
900 '@template=calendar&amp;amp;property=%(prop)s&amp;amp;'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
901 'form=itemSynopsis&amp;date=%(value)s" '
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
902 'data-height="200" data-width="300" href="javascript:help_window'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
903 '(\'%(cls)s?@template=calendar&amp;property=%(prop)s&amp;'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
904 'form=itemSynopsis&date=%(value)s\', 300, 200)">(cal)</a>'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
905 ) % {'cls': cls, 'prop': prop, 'value': value}
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
906
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
907 def test_DateHTMLWithDate(self):
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
908 """Test methods when DateHTMLProperty._value is a hyperdb.Date()
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
909 """
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
910 self.client.db.config['WEB_USE_BROWSER_DATE_INPUT'] = True
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
911 test_datestring = self.test_datestring
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
912 test_Date = self.client.db.issue.get("1", 'deadline')
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
913 test_hyperdbDate = self.client.db.issue.getprops("1")['deadline']
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
914
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
915 self.client.classname = "issue"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
916 self.client.template = "item"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
917
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
918 # client, classname, nodeid, prop, name, value,
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
919 # anonymous=0, offset=None
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
920 d = DateHTMLProperty(self.client, 'issue', '1', test_hyperdbDate,
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
921 'deadline', test_Date)
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
922 self.assertIsInstance(d._value, date.Date)
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
923 self.assertEqual(d.pretty(), " 1 January 2021")
8287
60e682add9ea test - fix broken test
John Rouillard <rouilj@ieee.org>
parents: 8286
diff changeset
924 self.assertEqual(d.pretty("%2d %B %Y"), "01 January 2021")
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
925 self.assertEqual(d.pretty(format="%Y-%m"), "2021-01")
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
926 self.assertEqual(d.plain(), "2021-01-01.13:22:10")
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
927 self.assertEqual(d.local("-4").plain(), "2021-01-01.07:22:10")
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
928 input_expected = """<input id="issue1@deadline" name="issue1@deadline" size="30" type="date" value="2021-01-01">"""
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
929 self.assertEqual(d.field(display_time=False), input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
930
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
931 input_expected = '<input id="issue1@deadline" name="issue1@deadline" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
932 'size="30" type="datetime-local" value="2021-01-01T13:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
933 self.assertEqual(d.field(), input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
934
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
935 input_expected = '<input id="issue1@deadline" name="issue1@deadline" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
936 'size="30" type="text" value="2021-01-01.13:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
937 field = d.field(format='%Y-%m-%d.%H:%M:%S', popcal=False)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
938 self.assertEqual(field, input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
939
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
940 # test with format
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
941 input_expected = '<input id="issue1@deadline" name="issue1@deadline" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
942 'size="30" type="text" value="2021-01">' + self.exp_classhelp()
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
943
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
944 self.assertEqual(d.field(format="%Y-%m"), input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
945
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
946 input_expected = '<input id="issue1@deadline" name="issue1@deadline" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
947 'size="30" type="text" value="2021-01">'
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
948
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
949 input = d.field(format="%Y-%m", popcal=False)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
950 self.assertEqual(input, input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
951
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
952 def test_DateHTMLWithText(self):
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
953 """Test methods when DateHTMLProperty._value is a string
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
954 rather than a hyperdb.Date()
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
955 """
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
956 test_datestring = "2021-01-01 11:22:10"
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
957 test_date = hyperdb.Date("2")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
958
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
959 self.form.list.append(MiniFieldStorage("test1@test", test_datestring))
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
960 self.client._props=test_date
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
961 self.client.db.config['WEB_USE_BROWSER_DATE_INPUT'] = False
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
962
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
963 self.client.db.classes = dict \
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
964 ( test = MockNull(getprops = lambda : test_date)
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
965 )
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
966
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
967 self.client.classname = "test"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
968 self.client.template = "item"
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
969
6377
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
970 # client, classname, nodeid, prop, name, value,
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
971 # anonymous=0, offset=None
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
972 d = DateHTMLProperty(self.client, 'test', '1', self.client._props,
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
973 'test', '')
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
974 self.assertIs(type(d._value), str)
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
975 self.assertEqual(d.pretty(), "2021-01-01 11:22:10")
a7e7314fb7d9 issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents: 6339
diff changeset
976 self.assertEqual(d.plain(), "2021-01-01 11:22:10")
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
977 input_expected = '<input id="test1@test" name="test1@test" size="30" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
978 'type="text" value="2021-01-01 11:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
979 self.assertEqual(d.field(popcal=False), input_expected)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
980 self.client.db.config['WEB_USE_BROWSER_DATE_INPUT'] = True
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
981 input_expected = '<input id="test1@test" name="test1@test" size="30" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
982 'type="datetime-local" value="2021-01-01 11:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
983 self.assertEqual(d.field(), input_expected)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
984 self.client.db.config['WEB_USE_BROWSER_DATE_INPUT'] = False
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
985
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
986 input_expected = '<input id="test1@test" name="test1@test" size="40" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
987 'type="text" value="2021-01-01 11:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
988 self.assertEqual(d.field(size=40, popcal=False), input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
989
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
990 input_expected = ('<input id="test1@test" name="test1@test" size="30" '
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
991 'type="text" value="2021-01-01 11:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
992 + self.exp_classhelp(cls='test', prop='test', dlm=' '))
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
993 self.maxDiff=None
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
994 self.assertEqual(d.field(format="%Y-%m"), input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
995
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
996 # format always uses type="text" even when date input is set
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
997 self.client.db.config['WEB_USE_BROWSER_DATE_INPUT'] = True
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
998 result = d.field(format="%Y-%m-%d", popcal=False)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
999 input_expected = '<input id="test1@test" name="test1@test" size="30" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1000 'type="text" value="2021-01-01 11:22:10">'
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
1001 self.assertEqual(result, input_expected)
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
1002
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1003 input_expected = ('<input id="test1@test" name="test1@test" size="30" '
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1004 'type="text" value="2021-01-01 11:22:10">'
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1005 + self.exp_classhelp(cls='test', prop='test', dlm=' '))
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1006 self.assertEqual(d.field(format="%Y-%m"), input_expected)
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
1007
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1008 result = d.field(format="%Y-%m-%dT%H:%M:%S", popcal=False)
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1009 input_expected = '<input id="test1@test" name="test1@test" size="30" '\
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8289
diff changeset
1010 'type="text" value="2021-01-01 11:22:10">'
8285
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
1011 self.assertEqual(result, input_expected)
2bf0c4e7795e fix: issue2551390 - Replace text input/calendar popup with native date input
John Rouillard <rouilj@ieee.org>
parents: 8281
diff changeset
1012
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1013 # common markdown test cases
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1014 class MarkdownTests:
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1015 def mangleMarkdown2(self, s):
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1016 ''' markdown2's rel=nofollow support on 'a' tags isn't programmable.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1017 So we are using it's builtin nofollow support. Mangle the string
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1018 so that it matches the test case.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1019
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1020 turn: <a rel="nofollow" href="foo"> into
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1021 <a href="foo" rel="nofollow noopener">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1022
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1023 Also if it is a mailto url, we don't expect rel="nofollow",
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1024 so delete it.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1025
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1026 turn: <a rel="nofollow" href="mailto:foo"> into
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1027 <a href="mailto:foo">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1028
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1029 Also when a title is present it is put in a different place
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1030 from markdown, so fix it to normalize.
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1031
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1032 turn:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1033
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1034 <a rel="nofollow" href="http://example.com/" title="a title">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1035 into
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1036 <a href="http://example.com/" rel="nofollow noopener" title="a title">
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1037 '''
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1038 if type(self) == Markdown2TestCase and s.find('a rel="nofollow"') != -1:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1039 if s.find('href="mailto:') == -1:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1040 # not a mailto url
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1041 if 'rel="nofollow"' in s:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1042 if 'title="' in s:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1043 s = s.replace(' rel="nofollow" ', ' ').replace(' title=', ' rel="nofollow noopener" title=')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1044 else:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1045 s = s.replace(' rel="nofollow" ', ' ').replace('">', '" rel="nofollow noopener">')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1046
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1047 return s
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1048 else:
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1049 # a mailto url
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1050 return s.replace(' rel="nofollow" ', ' ')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1051 return s
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1052
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1053
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1054 def test_string_markdown(self):
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1055 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
1056 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
1057
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1058 def test_string_markdown_link(self):
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1059 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1060 u2s(u'A link <http://localhost>'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1061 m = p.markdown().strip()
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1062 m = self.mangleMarkdown2(m)
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1063
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1064 self.assertEqual( u2s(u'<p>A link <a href="http://localhost" rel="nofollow noopener">http://localhost</a></p>'), m)
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1065
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1066 def test_string_markdown_link_item(self):
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1067 """ The link formats for the different markdown engines changes.
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1068 Order of attributes, value for rel (noopener, nofollow etc)
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1069 is different. So most tests check for a substring that indicates
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1070 success rather than the entire returned string.
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1071 """
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1072 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1073 u2s(u'An issue1 link'))
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1074 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1075 # just verify that plain linking is working
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1076 self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1077
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1078 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1079 u2s(u'An [issue1](issue1) link'))
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1080 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1081 # just verify that plain linking is working
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1082 self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1))
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1083
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1084 p = StringHTMLProperty(
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1085 self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1086 u2s(u'An [issue1](https://example.com/issue1) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1087 self.assertIn( u2s(u'href="https://example.com/issue1"'),
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1088 p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1089
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1090 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1091 u2s(u'An [issu1](#example) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1092 self.assertIn( u2s(u'href="#example"'), p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1093
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1094 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1095 u2s(u'An [issu1](/example) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1096 self.assertIn( u2s(u'href="/example"'), p.markdown().strip())
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1097
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1098 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1099 u2s(u'An [issu1](./example) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1100 self.assertIn( u2s(u'href="./example"'), p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1101
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1102 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1103 u2s(u'An [issu1](../example) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1104 self.assertIn( u2s(u'href="../example"'), p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1105
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1106 p = StringHTMLProperty(
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1107 self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1108 u2s(u'A [wuarchive_ftp](ftp://www.wustl.gov/file) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1109 self.assertIn( u2s(u'href="ftp://www.wustl.gov/file"'),
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1110 p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1111
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1112 p = StringHTMLProperty(
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1113 self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1114 u2s(u'An [issue1] (https://example.com/issue1) link'))
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1115 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1116 if type(self) == MistuneTestCase:
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1117 # mistune makes the https url into a real link
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1118 self.assertIn( u2s(u'href="https://example.com/issue1"'),
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1119 p.markdown().strip())
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1120 else:
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1121 # the other two engines leave the parenthesized url as is.
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1122 self.assertIn( u2s(u' (https://example.com/issue1) link'),
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1123 p.markdown().strip())
6336
6f89cdc7c938 issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents: 6299
diff changeset
1124
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1125 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1126 u2s(u'An [issu1](.../example) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1127 if (isinstance(self, Markdown2TestCase) and
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1128 md2__version_info__ > (2, 4, 9)):
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1129 # markdown2 > 2.4.9 handles this differently
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1130 self.assertIn( u2s(u'href="#"'), p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1131 else:
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1132 self.assertIn( u2s(u'href=".../example"'), p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1133
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1134 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1135 u2s(u'A [phone](tel:0016175555555) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1136 if (isinstance(self, Markdown2TestCase) and
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1137 md2__version_info__ > (2, 4, 9)):
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1138 self.assertIn(u2s(u'href="#"'), p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1139 else:
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1140 self.assertIn( u2s(u'href="tel:0016175555555"'),
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1141 p.markdown().strip())
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1142
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1143 def test_string_email_markdown_link(self):
6109
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
1144 # 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
1145 try:
6109
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
1146 from html import unescape as html_unescape
b108c9fc7aea fix test for Python 2
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6104
diff changeset
1147 except ImportError:
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1148 from HTMLParser import HTMLParser
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1149 html_unescape = HTMLParser().unescape
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1150
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1151 p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1152 u2s(u'A link <cmeerw@example.com>'))
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1153 m = html_unescape(p.markdown().strip())
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1154 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1155
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1156 self.assertEqual(m, u2s(u'<p>A link <a href="mailto:cmeerw@example.com">cmeerw@example.com</a></p>'))
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1157
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1158 p = StringHTMLProperty(
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1159 self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1160 u2s(u'An bare email baduser@daemons.com link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1161 m = self.mangleMarkdown2(html_unescape(p.markdown().strip()))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1162 self.assertIn( u2s(u'href="mailto:baduser@daemons.com"'),
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1163 m)
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1164
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1165 p = StringHTMLProperty(
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1166 self.client, 'test', '1', None, 'test',
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1167 u2s(u'An [email_url](mailto:baduser@daemons.com) link'))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1168 m = self.mangleMarkdown2(html_unescape(p.markdown().strip()))
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1169
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1170 if isinstance(self, MistuneTestCase):
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1171 self.assertIn('<a href="mailto:baduser@daemons.com" rel="nofollow noopener">email_url</a>', m)
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1172 else:
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1173 self.assertIn('<a href="mailto:baduser@daemons.com">email_url</a>', m)
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1174
6104
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1175 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
1176 # 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
1177 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
1178 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
1179
a1fd9551d416 don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6103
diff changeset
1180 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
1181 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
1182
6284
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1183 def test_string_markdown_data_link(self):
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1184 # make sure we don't get a "data:" link
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1185 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==>'))
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1186 print(p.markdown())
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1187 self.assertTrue(p.markdown().find('href="data:') == -1)
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1188
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1189 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[data link](data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==)'))
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1190 print(p.markdown())
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1191 self.assertTrue(p.markdown().find('href="data:') == -1)
3f7538316724 issue2551099 - disable processing of data url's in markdown.
John Rouillard <rouilj@ieee.org>
parents: 6282
diff changeset
1192
6274
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1193
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1194 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
1195 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
1196 # sigh different backends render this differently:
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1197 # of text <br />
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1198 # of text<br>
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1199 # etc.
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1200 # 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
1201 # 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
1202 m = p.markdown()
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1203 print(m)
6274
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1204 self.assertEqual(3, m.count('<br'))
474de62f4ce0 Add test for hard linebreak fomatting in markdown
John Rouillard <rouilj@ieee.org>
parents: 6109
diff changeset
1205
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1206 def test_string_markdown_code_block(self):
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1207 ''' also verify that embedded html is escaped '''
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1208 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
1209 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
1210
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1211 def test_string_markdown_code_block_attribute(self):
6995
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
1212 parser = NormalizingHtmlParser()
6992
a5f30372ef7f New markdown2 release changed output with code highlighting (take 2)
John Rouillard <rouilj@ieee.org>
parents: 6991
diff changeset
1213
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1214 ''' also verify that embedded html is escaped '''
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1215 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'))
6995
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
1216 m = parser.normalize(p.markdown())
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
1217 parser.reset()
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1218 print(m)
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1219 if type(self) == MistuneTestCase:
6995
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
1220 self.assertEqual(m, parser.normalize('<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>'))
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1221 elif type(self) == MarkdownTestCase:
7561
91725f12b239 Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
John Rouillard <rouilj@ieee.org>
parents: 7032
diff changeset
1222 self.assertEqual(m.replace('class="python"','class="language-python"'), parser.normalize('<p>embedded code block &lt;pre&gt;</p>\n<pre><code class="language-python">line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>'))
6279
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1223 else:
6995
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
1224 expected_result = parser.normalize('<p>embedded code block &lt;pre&gt;</p>\n<div class="codehilite"><pre><span></span><code><span class="n">line</span> <span class="mi">1</span>\n<span class="n">line</span> <span class="mi">2</span>\n</code></pre></div>\n<p>new &lt;/pre&gt; paragraph</p>')
dc83ebff4c90 change test to use html normalizer when comparing html output.
John Rouillard <rouilj@ieee.org>
parents: 6992
diff changeset
1225 self.assertEqual(m, expected_result)
6275
bda491248fd8 Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents: 6274
diff changeset
1226
6279
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1227 def test_markdown_return_text_on_exception(self):
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1228 ''' string is invalid markdown. missing end of fenced code block '''
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1229 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block <pre>\n\n``` python\nline 1\nline 2\n\n\nnew </pre> paragraph'))
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1230 m = p.markdown().strip()
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1231 print(m)
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1232 self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<p>``` python\nline 1\nline 2</p>\n<p>new &lt;/pre&gt; paragraph</p>')
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1233
9ec3a9bc4ea5 issue2551097 - fix call to markdown2 - fix fenced code blocks.
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
1234 def test_markdown_break_on_newline(self):
6277
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
1235 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
1236 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
1237 m = p.markdown()
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
1238 self.assertEqual(2, m.count('<br'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
1239 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
1240
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
1241 m = p.markdown()
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
1242 self.assertEqual(0, m.count('<br'))
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6275
diff changeset
1243
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1244 def test_markdown_hyperlinked_url(self):
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1245 # classic markdown does not emit a \n at end of rendered string
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1246 # so rstrip \n.
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1247 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'http://example.com/'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1248 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1249 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1250 print(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1251 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener">http://example.com/</a></p>')
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1252
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1253 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'<http://example.com/>'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1254 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1255 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1256 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener">http://example.com/</a></p>')
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1257
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1258 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[label](http://example.com/ "a title")'))
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1259 m = p.markdown(hyperlink=1)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1260 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1261 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener" title="a title">label</a></p>')
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1262
6299
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
1263 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'[label](http://example.com/).'))
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
1264 m = p.markdown(hyperlink=1)
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
1265 m = self.mangleMarkdown2(m)
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
1266 self.assertEqual(m.rstrip('\n'), '<p><a href="http://example.com/" rel="nofollow noopener">label</a>.</p>')
fd0bdcbc68e4 issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents: 6284
diff changeset
1267
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1268 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'![](http://example.com/)'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1269 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1270 m = self.mangleMarkdown2(m)
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1271 self.assertIn(m, [
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1272 '<p><img src="http://example.com/" alt=""/></p>\n',
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1273 '<p><img src="http://example.com/" alt="" /></p>\n',
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1274 '<p><img src="http://example.com/" alt=""></p>\n',
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1275 '<p><img alt="" src="http://example.com/" /></p>', # markdown
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1276 ])
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1277
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1278 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An URL http://example.com/ with text'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1279 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1280 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1281 self.assertEqual(m.rstrip('\n'), '<p>An URL <a href="http://example.com/" rel="nofollow noopener">http://example.com/</a> with text</p>')
6280
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1282
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1283 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An URL https://example.com/path with text'))
6ed5152a92d0 issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents: 6279
diff changeset
1284 m = p.markdown(hyperlink=1)
6282
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1285 m = self.mangleMarkdown2(m)
d30501bafdfb issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents: 6280
diff changeset
1286 self.assertEqual(m.rstrip('\n'), '<p>An URL <a href="https://example.com/path" rel="nofollow noopener">https://example.com/path</a> with text</p>')
6099
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1287
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1288 @skip_mistune
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1289 class MistuneTestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1290 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1291 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1292
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1293 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1294 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1295 templating.markdown = templating._import_mistune()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1296
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1297 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1298 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1299 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1300
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1301 @skip_markdown2
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1302 class Markdown2TestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1303 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1304 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1305
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1306 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1307 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1308 templating.markdown = templating._import_markdown2()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1309
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1310 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1311 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1312 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1313
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1314 @skip_markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1315 class MarkdownTestCase(TemplatingTestCase, MarkdownTests) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1316 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1317 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1318
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1319 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1320 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1321 templating.markdown = templating._import_markdown()
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1322
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1323 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1324 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1325 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1326
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1327
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1328 class NoMarkdownTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1329 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1330 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1331
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1332 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1333 self.__markdown = templating.markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1334 templating.markdown = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1335
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1336 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1337 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1338 templating.markdown = self.__markdown
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1339
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1340 def test_string_markdown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1341 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
1342 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
1343
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1344 class NoRstTestCase(TemplatingTestCase) :
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1345 def setUp(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1346 TemplatingTestCase.setUp(self)
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1347
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1348 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1349 self.__ReStructuredText = templating.ReStructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1350 templating.ReStructuredText = None
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1351
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1352 def tearDown(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1353 from roundup.cgi import templating
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1354 templating.ReStructuredText = self.__ReStructuredText
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1355
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1356 def test_string_rst(self):
55c56ceacb8e escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents: 6098
diff changeset
1357 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
1358 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
1359
8286
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1360 class NumberIntegerHTMLPropertyTestCase(HTMLPropertyTestClass):
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1361
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1362 def setUp(self):
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1363 super(NumberIntegerHTMLPropertyTestCase, self).setUp()
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1364
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1365 db = self.client.db
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1366 db.issue.addprop(numberval=hyperdb.Number())
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1367 db.issue.addprop(intval=hyperdb.Integer())
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1368
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1369 self.client.db.issue.create(title="title",
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1370 numberval = "3.14",
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1371 intval="314")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1372
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1373 def tearDown(self):
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1374 self.client.db.close()
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1375 memorydb.db_nuke('')
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1376
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1377 def test_IntegerHTML(self):
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1378 test_hyperdbInteger = self.client.db.issue.getprops("1")['intval']
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1379 test_Integer = test_hyperdbInteger.from_raw(
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1380 self.client.db.issue.get("1", 'intval')
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1381 )
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1382
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1383 # client, classname, nodeid, prop, name, value,
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1384 # anonymous=0, offset=None
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1385 d = IntegerHTMLProperty(self.client, 'issue', '1',
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1386 test_hyperdbInteger,
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1387 'intval', test_Integer)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1388
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1389 self.assertIsInstance(d._value, int)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1390
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1391 self.assertEqual(d.plain(), "314")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1392
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1393 input_expected = """<input id="issue1@intval" name="issue1@intval" size="30" step="1" type="number" value="314">"""
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1394 self.assertEqual(d.field(), input_expected)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1395
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1396 input_expected = """<input id="issue1@intval" name="issue1@intval" size="30" step="50" type="number" value="314">"""
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1397 self.assertEqual(d.field(step="50"), input_expected)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1398
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1399 input_expected = """<input id="issue1@intval" name="issue1@intval" size="30" type="text" value="314">"""
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1400 self.assertEqual(d.field(type="text"), input_expected)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1401
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1402
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1403 # check permissions return
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1404 is_view_ok_orig = d.is_view_ok
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1405 is_edit_ok_orig = d.is_edit_ok
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1406 no_access = lambda : False
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1407
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1408 d.is_view_ok = no_access
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1409 self.assertEqual(d.plain(), "[hidden]")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1410
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1411 d.is_edit_ok = no_access
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1412 self.assertEqual(d.field(), "[hidden]")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1413
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1414 d.is_view_ok = is_view_ok_orig
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1415 self.assertEqual(d.field(), "314")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1416 d.is_edit_ok = is_edit_ok_orig
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1417
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1418 def test_NumberHTML(self):
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1419 test_hyperdbNumber = self.client.db.issue.getprops("1")['numberval']
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1420 test_Number = test_hyperdbNumber.from_raw(
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1421 self.client.db.issue.get("1", 'numberval')
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1422 )
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1423
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1424 # client, classname, nodeid, prop, name, value,
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1425 # anonymous=0, offset=None
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1426 d = NumberHTMLProperty(self.client, 'issue', '1',
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1427 test_hyperdbNumber,
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1428 'numberval', test_Number)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1429
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1430 # string needed for memorydb/anydbm backend. Float?? when
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1431 # running against sql backends.
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1432 self.assertIsInstance(d._value, float)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1433
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1434 self.assertEqual(d._value, 3.14)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1435
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1436 input_expected = """<input id="issue1@numberval" name="issue1@numberval" size="30" type="number" value="3.14">"""
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1437 self.assertEqual(d.field(), input_expected)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1438
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1439 input_expected = """<input id="issue1@numberval" name="issue1@numberval" size="30" step="50" type="number" value="3.14">"""
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1440 self.assertEqual(d.field(step="50"), input_expected)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1441
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1442 input_expected = """<input id="issue1@numberval" name="issue1@numberval" size="30" type="text" value="3.14">"""
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1443 self.assertEqual(d.field(type="text"), input_expected)
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1444
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1445 self.assertEqual(d.pretty("%0.3f"), "3.140")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1446 self.assertEqual(d.pretty("%0.3d"), "003")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1447 self.assertEqual(d.pretty("%2d"), " 3")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1448
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1449 # see what happens if for other values
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1450 value = d._value
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1451 d._value = "1" # integer
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1452 self.assertEqual(d.pretty("%2d"), "1")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1453 d._value = "I'mNotAFloat" # not a number
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1454 self.assertEqual(d.pretty("%2d"), "I'mNotAFloat")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1455 d._value = value
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1456
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1457 # check permissions return
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1458 is_view_ok_orig = d.is_view_ok
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1459 is_edit_ok_orig = d.is_edit_ok
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1460 no_access = lambda : False
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1461
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1462 d.is_view_ok = no_access
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1463 self.assertEqual(d.plain(), "[hidden]")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1464
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1465 d.is_edit_ok = no_access
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1466 self.assertEqual(d.field(), "[hidden]")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1467
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1468 d.is_view_ok = is_view_ok_orig
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1469 self.assertEqual(d.field(), "3.14")
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1470 d.is_edit_ok = is_edit_ok_orig
6445e63bb423 feat(web) - Use native number type input for Number() and Integer().
John Rouillard <rouilj@ieee.org>
parents: 8285
diff changeset
1471
7866
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1472 class ZUtilsTestcase(TemplatingTestCase):
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1473
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1474 def test_Iterator(self):
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1475 """Test all the iterator functions and properties.
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1476 """
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1477 sequence = ['one', 'two', '3', 4]
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1478 i = Iterator(sequence)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1479 for j in [ # element, item, 1st, last, even, odd, number,
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1480 # letter, Letter, roman, Roman
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1481 (1, "one", 1, 0, True, 0, 1, 'a', 'A', 'i', 'I'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1482 (1, "two", 0, 0, False, 1, 2, 'b', 'B', 'ii', 'II'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1483 (1, "3", 0, 0, True, 0, 3, 'c', 'C', 'iii', 'III'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1484 (1, 4, 0, 1, False, 1, 4, 'd', 'D', 'iv', 'IV'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1485 # next() fails with 0 when past end of sequence
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1486 # everything else is left at end of sequence
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1487 (0, 4, 0, 1, False, 1, 4, 'd', 'D', 'iv', 'IV'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1488
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1489
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1490 ]:
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1491 element = i.next() # returns 1 if next item else 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1492 print(i.item)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1493 self.assertEqual(element, j[0])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1494 self.assertEqual(i.item, j[1])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1495 self.assertEqual(i.first(), j[2])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1496 self.assertEqual(i.start, j[2])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1497 self.assertEqual(i.last(), j[3])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1498 self.assertEqual(i.end, j[3])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1499 self.assertIs(i.even(), j[4])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1500 self.assertEqual(i.odd(), j[5])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1501 self.assertEqual(i.number(), j[6])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1502 self.assertEqual(i.index, j[6] - 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1503 self.assertEqual(i.nextIndex, j[6])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1504 self.assertEqual(i.letter(), j[7])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1505 self.assertEqual(i.Letter(), j[8])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1506 self.assertEqual(i.roman(), j[9])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1507 self.assertEqual(i.Roman(), j[10])
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1508
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1509 class I:
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1510 def __init__(self, name, data):
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1511 self.name = name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1512 self.data = data
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1513
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1514 sequence = [I('Al', 'd'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1515 I('Bob', 'e'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1516 I('Bob', 'd'),
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1517 I('Chip', 'd')
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1518 ]
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1519
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1520 iterator = iter(sequence)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1521
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1522 # Iterator is supposed take both sequence and Python iterator.
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1523 for source in [sequence, iterator]:
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1524 i = Iterator(source)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1525
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1526 element = i.next() # returns 1 if next item else 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1527 item1 = i.item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1528
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1529 # note these can trigger calls by first/last to same_part().
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1530 # It can return true for first/last even when there are more
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1531 # items in the sequence. I am just testing the current
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1532 # implementation. Woe to the person who tries to change
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1533 # Iterator.py.
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1534
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1535 self.assertEqual(element, 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1536 # i.start == 1, so it bypasses name check
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1537 self.assertEqual(i.first(name='namea'), 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1538 self.assertEqual(i.first(name='name'), 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1539 # i.end == 0 so it uses name check in object
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1540 self.assertEqual(i.last(name='namea'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1541 self.assertEqual(i.last(name='name'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1542
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1543 element = i.next() # returns 1 if next item else 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1544 item2 = i.item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1545 self.assertEqual(element, 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1546 # i.start == 0 so it uses name check
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1547 # between item1 and item2
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1548 self.assertEqual(i.first(name='namea'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1549 self.assertEqual(i.first(name='name'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1550 # i.end == 0 so it uses name check in object
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1551 # between item2 and the next item item3
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1552 self.assertEqual(i.last(name='namea'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1553 self.assertEqual(i.last(name='name'), True)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1554
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1555 element = i.next() # returns 1 if next item else 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1556 item3 = i.item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1557 self.assertEqual(element, 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1558 # i.start == 0 so it uses name check
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1559 self.assertEqual(i.first(name='namea'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1560 self.assertEqual(i.first(name='name'), 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1561 # i.end == 0 so it uses name check in object
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1562 # between item3 and the next item item4
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1563 self.assertEqual(i.last(name='namea'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1564 self.assertEqual(i.last(name='name'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1565
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1566 element = i.next() # returns 1 if next item else 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1567 item4 = i.item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1568 self.assertEqual(element, 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1569 # i.start == 0 so it uses name check
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1570 self.assertEqual(i.first(name='namea'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1571 self.assertEqual(i.first(name='name'), 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1572 # i.end == 0 so it uses name check in object
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1573 # last two object have same name (1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1574 self.assertEqual(i.last(name='namea'), 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1575 self.assertEqual(i.last(name='name'), 1)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1576
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1577 element = i.next() # returns 1 if next item else 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1578 self.assertEqual(element, 0)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1579
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1580 # this is the underlying call for first/last
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1581 # when i.start/i.end are 0
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1582 # use non-existing attribute name, same item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1583 self.assertIs(i.same_part('namea', item2, item2), False)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1584 # use correct attribute name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1585 self.assertIs(i.same_part('name', item2, item2), True)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1586 # use no attribute name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1587 self.assertIs(i.same_part(None, item2, item2), True)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1588
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1589 # use non-existing attribute name, different item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1590 # non-matching names
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1591 self.assertIs(i.same_part('namea', item1, item2), False)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1592 # use correct attribute name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1593 self.assertIs(i.same_part('name', item1, item2), False)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1594 # use no attribute name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1595 self.assertIs(i.same_part(None, item1, item2), False)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1596
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1597 # use non-existing attribute name, different item
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1598 # matching names
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1599 self.assertIs(i.same_part('namea', item2, item3), False)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1600 # use correct attribute name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1601 self.assertIs(i.same_part('name', item2, item3), True)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1602 # use no attribute name
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1603 self.assertIs(i.same_part(None, item2, item3), False)
9bbc1d951677 issue2551331 - Fix repeat first/last methods.
John Rouillard <rouilj@ieee.org>
parents: 7864
diff changeset
1604
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
1605 r'''
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1606 class HTMLPermissions:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1607 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1608 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1609 def is_only_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1610 def view_check(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1611 def edit_check(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1612
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1613 def input_html4(**attrs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1614 def input_xhtml(**attrs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1615
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1616 class HTMLInputMixin:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1617 def __init__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1618
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1619 class HTMLClass(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1620 def __init__(self, client, classname, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1621 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1622 def __getitem__(self, item):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1623 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1624 def designator(self):
5811
7d276bb8b46d More invalid escape sequence fixes.
John Rouillard <rouilj@ieee.org>
parents: 5795
diff changeset
1625 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
1626 def properties(self, sort=1, cansearch=True):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1627 def list(self, sort_on=None):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1628 def csv(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1629 def propnames(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1630 def filter(self, request=None, filterspec={}, sort=(None,None),
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1631 def classhelp(self, properties=None, label='(list)', width='500',
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1632 def submit(self, label="Submit New Entry"):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1633 def history(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1634 def renderWith(self, name, **kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1635
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1636 class HTMLItem(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1637 def __init__(self, client, classname, nodeid, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1638 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1639 def __getitem__(self, item):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1640 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1641 def designator(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1642 def is_retired(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1643 def submit(self, label="Submit Changes"):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1644 def journal(self, direction='descending'):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1645 def history(self, direction='descending', dre=re.compile('\d+')):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1646 def renderQueryForm(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1647
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1648 class HTMLUserPermission:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1649 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1650 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1651 def _user_perm_check(self, type):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1652
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1653 class HTMLUserClass(HTMLUserPermission, HTMLClass):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1654
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1655 class HTMLUser(HTMLUserPermission, HTMLItem):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1656 def __init__(self, client, classname, nodeid, anonymous=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1657 def hasPermission(self, permission, classname=_marker):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1658
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1659 class HTMLProperty(HTMLInputMixin, HTMLPermissions):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1660 def __init__(self, client, classname, nodeid, prop, name, value,
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1661 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1662 def __str__(self):
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1663 def __lt__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1664 def __le__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1665 def __eq__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1666 def __ne__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1667 def __gt__(self, other):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1668 def __ge__(self, other):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1669 def is_edit_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1670 def is_view_ok(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1671
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1672 class StringHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1673 def _hyper_repl(self, match):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1674 def hyperlinked(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1675 def plain(self, escape=0, hyperlink=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1676 def stext(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1677 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1678 def multiline(self, escape=0, rows=5, cols=40):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1679 def email(self, escape=1):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1680
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1681 class PasswordHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1682 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1683 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1684 def confirm(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1685
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1686 class NumberHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1687 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1688 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1689 def __int__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1690 def __float__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1691
5067
e424987d294a Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
1692 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
1693 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
1694 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
1695 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
1696
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1697 class BooleanHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1698 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1699 def field(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1700
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1701 class DateHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1702 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1703 def now(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1704 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1705 def reldate(self, pretty=1):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1706 def pretty(self, format=_marker):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1707 def local(self, offset):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1708
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1709 class IntervalHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1710 def plain(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1711 def pretty(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1712 def field(self, size = 30):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1713
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1714 class LinkHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1715 def __init__(self, *args, **kw):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1716 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1717 def plain(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1718 def field(self, showid=0, size=None):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1719 def menu(self, size=None, height=None, showid=0, additional=[],
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1720
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1721 class MultilinkHTMLProperty(HTMLProperty):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1722 def __init__(self, *args, **kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1723 def __len__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1724 def __getattr__(self, attr):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1725 def __getitem__(self, num):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1726 def __contains__(self, value):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1727 def reverse(self):
5903
c3728772c594 Add reverse option to hyperdb property wrapper by David Sowder
John Rouillard <rouilj@ieee.org>
parents: 5815
diff changeset
1728 def sorted(self, property, reverse=False):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1729 def plain(self, escape=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1730 def field(self, size=30, showid=0):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1731 def menu(self, size=None, height=None, showid=0, additional=[],
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1732
5414
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1733 def make_key_function(db, classname, sort_on=None):
3fa026621f69 Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5388
diff changeset
1734 def keyfunc(a):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1735
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1736 def find_sort_key(linkcl):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1737
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1738 def handleListCGIValue(value):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1739
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1740 class ShowDict:
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1741 def __init__(self, columns):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1742 def __getitem__(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1743
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1744 class HTMLRequest(HTMLInputMixin):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1745 def __init__(self, client):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1746 def _post_init(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1747 def updateFromURL(self, url):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1748 def update(self, kwargs):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1749 def description(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1750 def __str__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1751 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
1752 def indexargs_url(self, url, args):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1753 def base_javascript(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1754 def batch(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1755
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1756 class Batch(ZTUtils.Batch):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1757 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
1758 def __getitem__(self, index):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1759 def propchanged(self, property):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1760 def previous(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1761 def next(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1762
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
1763 #class TemplatingUtils:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
1764 # def __init__(self, client):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5190
diff changeset
1765 # 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
1766
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1767 class NoTemplate(Exception):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1768 class Unauthorised(Exception):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1769 def __init__(self, action, klass):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1770 def __str__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1771
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4647
diff changeset
1772 class Loader:
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1773 def __init__(self, dir):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1774 def precompileTemplates(self):
4727
5033c2ad80a7 templating: Rename LoaderBase.get() to LoaderBase.load() for clarity
anatoly techtonik <techtonik@gmail.com>
parents: 4720
diff changeset
1775 def load(self, name, extension=None):
2158
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1776 def __getitem__(self, name):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1777
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1778 class RoundupPageTemplate(PageTemplate.PageTemplate):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1779 def getContext(self, client, classname, request):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1780 def render(self, client, classname, request, **options):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1781 def __repr__(self):
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1782 '''
a0cfea4e5956 start at templating tests
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1783
2716
305d346f8f3b disable invalid assertions
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2158
diff changeset
1784 # vim: set et sts=4 sw=4 :

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