Mercurial > p > roundup > code
comparison test/test_templating.py @ 6377:a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
Fix traceback caused by DateHTMLProperty.pretty() called
on a string value due to error in some other field.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 10 Apr 2021 22:10:07 -0400 |
| parents | ab18fe956d45 |
| children | e29d5f4e0af4 |
comparison
equal
deleted
inserted
replaced
| 6376:4e48a6a40bfe | 6377:a7e7314fb7d9 |
|---|---|
| 472 | 472 |
| 473 attrs={"disabled": "disabled", "class": "required", "size": 30} | 473 attrs={"disabled": "disabled", "class": "required", "size": 30} |
| 474 input=input_xhtml(**attrs) | 474 input=input_xhtml(**attrs) |
| 475 self.assertEqual(input, '<input class="required" disabled="disabled" size="30" type="text"/>') | 475 self.assertEqual(input, '<input class="required" disabled="disabled" size="30" type="text"/>') |
| 476 | 476 |
| 477 | |
| 478 class HTMLPropertyTestClass(unittest.TestCase): | |
| 479 def setUp(self): | |
| 480 self.form = FieldStorage() | |
| 481 self.client = MockNull() | |
| 482 self.client.db = db = MockDatabase() | |
| 483 db.security.hasPermission = lambda *args, **kw: True | |
| 484 self.client.form = self.form | |
| 485 | |
| 486 self.client._props = MockNull() | |
| 487 # add client props for testing anti_csrf_nonce | |
| 488 self.client.session_api = MockNull(_sid="1234567890") | |
| 489 self.client.db.getuid = lambda : 10 | |
| 490 | |
| 491 class DateHTMLPropertyTestCase(HTMLPropertyTestClass): | |
| 492 | |
| 493 def test_DateHTMLWithText(self): | |
| 494 """Test methods when DateHTMLProperty._value is a string | |
| 495 rather than a hyperdb.Date() | |
| 496 """ | |
| 497 test_datestring = "2021-01-01 11:22:10" | |
| 498 test_date = hyperdb.Date("2") | |
| 499 | |
| 500 self.form.list.append(MiniFieldStorage("test1@test", test_datestring)) | |
| 501 self.client._props=test_date | |
| 502 | |
| 503 self.client.db.classes = dict \ | |
| 504 ( test = MockNull(getprops = lambda : test_date) | |
| 505 ) | |
| 506 | |
| 507 # client, classname, nodeid, prop, name, value, | |
| 508 # anonymous=0, offset=None | |
| 509 d = DateHTMLProperty(self.client, 'test', '1', self.client._props, | |
| 510 'test', '') | |
| 511 self.assertIs(type(d._value), str) | |
| 512 self.assertEqual(d.pretty(), "2021-01-01 11:22:10") | |
| 513 self.assertEqual(d.plain(), "2021-01-01 11:22:10") | |
| 514 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>""" | |
| 515 self.assertEqual(d.field(), input) | |
| 516 | |
| 477 # common markdown test cases | 517 # common markdown test cases |
| 478 class MarkdownTests: | 518 class MarkdownTests: |
| 479 def mangleMarkdown2(self, s): | 519 def mangleMarkdown2(self, s): |
| 480 ''' markdown2's rel=nofollow support on 'a' tags isn't programmable. | 520 ''' markdown2's rel=nofollow support on 'a' tags isn't programmable. |
| 481 So we are using it's builtin nofollow support. Mangle the string | 521 So we are using it's builtin nofollow support. Mangle the string |
