Mercurial > p > roundup > code
comparison test/test_templating.py @ 8281:669dfccca898
issue2551391 - checkboxes and radiobutton inputs get wrong id's.
Actually it breaks automatic id assignment for all inputs.
Inputs now get an automatic id assignment that matches the name.
It can be overridden by supplting an id parameter in the call to
the field() method.
This is also a partial fix for issue1513369. I think it obsoletes the
changes to templating.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 16 Jan 2025 02:32:58 -0500 |
| parents | a9b136565838 |
| children | 2bf0c4e7795e |
comparison
equal
deleted
inserted
replaced
| 8276:8d3085b4d047 | 8281:669dfccca898 |
|---|---|
| 348 | 348 |
| 349 # test with number | 349 # test with number |
| 350 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test', | 350 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test', |
| 351 2345678.2345678) | 351 2345678.2345678) |
| 352 self.assertEqual(p.field(), | 352 self.assertEqual(p.field(), |
| 353 ('<input name="testnum1@test" size="30" type="text" ' | 353 ('<input id="testnum1@test" name="testnum1@test" size="30" type="text" ' |
| 354 'value="%s">')%expected_val) | 354 'value="%s">')%expected_val) |
| 355 self.assertEqual(p.field(size=10), | 355 self.assertEqual(p.field(size=10), |
| 356 ('<input name="testnum1@test" size="10" type="text" ' | 356 ('<input id="testnum1@test" name="testnum1@test" size="10" type="text" ' |
| 357 'value="%s">')%expected_val) | 357 'value="%s">')%expected_val) |
| 358 self.assertEqual(p.field(size=10, dataprop="foo", dataprop2=5), | 358 self.assertEqual(p.field(size=10, dataprop="foo", dataprop2=5), |
| 359 ('<input dataprop="foo" dataprop2="5" ' | 359 ('<input dataprop="foo" dataprop2="5" ' |
| 360 'name="testnum1@test" size="10" type="text" ' | 360 'id="testnum1@test" name="testnum1@test" ' |
| 361 'size="10" type="text" ' | |
| 361 'value="%s">'%expected_val)) | 362 'value="%s">'%expected_val)) |
| 362 | 363 |
| 363 self.assertEqual(p.field(size=10, klass="class1", | 364 self.assertEqual(p.field(size=10, klass="class1", |
| 364 **{ "class": "class2 class3", | 365 **{ "class": "class2 class3", |
| 365 "data-prop": "foo", | 366 "data-prop": "foo", |
| 366 "data-prop2": 5}), | 367 "data-prop2": 5}), |
| 367 ('<input class="class2 class3" data-prop="foo" ' | 368 ('<input class="class2 class3" data-prop="foo" ' |
| 368 'data-prop2="5" klass="class1" ' | 369 'data-prop2="5" id="testnum1@test" ' |
| 370 'klass="class1" ' | |
| 369 'name="testnum1@test" size="10" type="text" ' | 371 'name="testnum1@test" size="10" type="text" ' |
| 370 'value="%s">')%expected_val) | 372 'value="%s">')%expected_val) |
| 371 | 373 |
| 372 # get plain representation if user can't edit | 374 # get plain representation if user can't edit |
| 373 p.is_edit_ok = lambda: False | 375 p.is_edit_ok = lambda: False |
| 375 | 377 |
| 376 # test with string which is wrong type | 378 # test with string which is wrong type |
| 377 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test', | 379 p = NumberHTMLProperty(self.client, 'testnum', '1', None, 'test', |
| 378 "2345678.2345678") | 380 "2345678.2345678") |
| 379 self.assertEqual(p.field(), | 381 self.assertEqual(p.field(), |
| 380 ('<input name="testnum1@test" size="30" type="text" ' | 382 ('<input id="testnum1@test" name="testnum1@test" ' |
| 381 'value="2345678.2345678">')) | 383 'size="30" type="text" value="2345678.2345678">')) |
| 382 | 384 |
| 383 # test with None value, pretend property.__default_value = Null which | 385 # test with None value, pretend property.__default_value = Null which |
| 384 # is the default. It would be returned by get_default_value | 386 # is the default. It would be returned by get_default_value |
| 385 # which I mock. | 387 # which I mock. |
| 386 property = MockNull(get_default_value = lambda: None) | 388 property = MockNull(get_default_value = lambda: None) |
| 387 p = NumberHTMLProperty(self.client, 'testnum', '1', property, | 389 p = NumberHTMLProperty(self.client, 'testnum', '1', property, |
| 388 'test', None) | 390 'test', None) |
| 389 self.assertEqual(p.field(), | 391 self.assertEqual(p.field(), |
| 390 ('<input name="testnum1@test" size="30" type="text" ' | 392 ('<input id="testnum1@test" name="testnum1@test" ' |
| 391 'value="">')) | 393 'size="30" type="text" value="">')) |
| 392 | 394 |
| 393 def test_number_plain(self): | 395 def test_number_plain(self): |
| 394 import sys | 396 import sys |
| 395 | 397 |
| 396 _py3 = sys.version_info[0] > 2 | 398 _py3 = sys.version_info[0] > 2 |
| 568 self.assertEqual(t.rst(), u2s(t_result)) | 570 self.assertEqual(t.rst(), u2s(t_result)) |
| 569 self.assertEqual(u.rst(), u2s(u_result)) | 571 self.assertEqual(u.rst(), u2s(u_result)) |
| 570 | 572 |
| 571 def test_string_field(self): | 573 def test_string_field(self): |
| 572 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') | 574 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') |
| 573 self.assertEqual(p.field(), '<input name="test1@test" size="30" type="text" value="A string <b> with rouilj@example.com embedded &lt; html</b>">') | 575 self.assertEqual(p.field(), '<input id="test1@test" name="test1@test" size="30" type="text" value="A string <b> with rouilj@example.com embedded &lt; html</b>">') |
| 574 | 576 |
| 575 def test_string_multiline(self): | 577 def test_string_multiline(self): |
| 576 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') | 578 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') |
| 577 self.assertEqual(p.multiline(), '<textarea name="test1@test" id="test1@test" rows="5" cols="40">A string <b> with rouilj@example.com embedded &lt; html</b></textarea>') | 579 self.assertEqual(p.multiline(), '<textarea name="test1@test" id="test1@test" rows="5" cols="40">A string <b> with rouilj@example.com embedded &lt; html</b></textarea>') |
| 578 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 <b> with rouilj@example.com embedded &lt; html</b></textarea>') | 580 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 <b> with rouilj@example.com embedded &lt; html</b></textarea>') |
| 744 d = DateHTMLProperty(self.client, 'test', '1', self.client._props, | 746 d = DateHTMLProperty(self.client, 'test', '1', self.client._props, |
| 745 'test', '') | 747 'test', '') |
| 746 self.assertIs(type(d._value), str) | 748 self.assertIs(type(d._value), str) |
| 747 self.assertEqual(d.pretty(), "2021-01-01 11:22:10") | 749 self.assertEqual(d.pretty(), "2021-01-01 11:22:10") |
| 748 self.assertEqual(d.plain(), "2021-01-01 11:22:10") | 750 self.assertEqual(d.plain(), "2021-01-01 11:22:10") |
| 749 input = """<input name="test1@test" size="30" type="text" value="2021-01-01 11:22:10"><a class="classhelp" data-calurl="test?@template=calendar&amp;property=test&amp;form=itemSynopsis&date=2021-01-01 11:22:10" data-height="200" data-width="300" href="javascript:help_window('test?@template=calendar&property=test&form=itemSynopsis&date=2021-01-01 11:22:10', 300, 200)">(cal)</a>""" | 751 input = """<input id="test1@test" name="test1@test" size="30" type="text" value="2021-01-01 11:22:10"><a class="classhelp" data-calurl="test?@template=calendar&amp;property=test&amp;form=itemSynopsis&date=2021-01-01 11:22:10" data-height="200" data-width="300" href="javascript:help_window('test?@template=calendar&property=test&form=itemSynopsis&date=2021-01-01 11:22:10', 300, 200)">(cal)</a>""" |
| 750 self.assertEqual(d.field(), input) | 752 self.assertEqual(d.field(), input) |
| 751 | 753 |
| 752 # common markdown test cases | 754 # common markdown test cases |
| 753 class MarkdownTests: | 755 class MarkdownTests: |
| 754 def mangleMarkdown2(self, s): | 756 def mangleMarkdown2(self, s): |
