|
5 | 5 | import datetime
|
6 | 6 | import io
|
7 | 7 | import json
|
| 8 | +import lxml.etree |
8 | 9 | import os.path
|
9 | 10 | import pytz
|
10 | 11 | import shutil
|
@@ -450,6 +451,41 @@ def test_parse_creation_date(self):
|
450 | 451 | datetime.date(today.year, 1 if today.month != 1 else 2, 15),
|
451 | 452 | )
|
452 | 453 |
|
| 454 | + def test_parse_docname(self): |
| 455 | + with self.assertRaises(ValueError) as cm: |
| 456 | + XMLDraft.parse_docname(lxml.etree.Element("xml")) # no docName |
| 457 | + self.assertIn("Missing docName attribute", str(cm.exception)) |
| 458 | + |
| 459 | + # There to be more invalid docNames, but we use XMLDraft in places where we don't |
| 460 | + # actually care about the validation, so for now just test what has long been the |
| 461 | + # implementation. |
| 462 | + with self.assertRaises(ValueError) as cm: |
| 463 | + XMLDraft.parse_docname(lxml.etree.Element("xml", docName="")) # not a valid docName |
| 464 | + self.assertIn("Unable to parse docName", str(cm.exception)) |
| 465 | + |
| 466 | + self.assertEqual( |
| 467 | + XMLDraft.parse_docname(lxml.etree.Element("xml", docName="draft-foo-bar-baz-01")), |
| 468 | + ("draft-foo-bar-baz", "01"), |
| 469 | + ) |
| 470 | + |
| 471 | + self.assertEqual( |
| 472 | + XMLDraft.parse_docname(lxml.etree.Element("xml", docName="draft-foo-bar-baz")), |
| 473 | + ("draft-foo-bar-baz", None), |
| 474 | + ) |
| 475 | + |
| 476 | + self.assertEqual( |
| 477 | + XMLDraft.parse_docname(lxml.etree.Element("xml", docName="draft-foo-bar-baz-")), |
| 478 | + ("draft-foo-bar-baz-", None), |
| 479 | + ) |
| 480 | + |
| 481 | + # This is awful, but is how we've been running for some time. The missing rev will trigger |
| 482 | + # validation errors for submissions, so we're at least somewhat guarded against this |
| 483 | + # property. |
| 484 | + self.assertEqual( |
| 485 | + XMLDraft.parse_docname(lxml.etree.Element("xml", docName="-01")), |
| 486 | + ("-01", None), |
| 487 | + ) |
| 488 | + |
453 | 489 |
|
454 | 490 | class NameTests(TestCase):
|
455 | 491 |
|
|
0 commit comments