RFCartography/tests/test_index_parser.py
2023-01-03 14:42:54 +01:00

716 lines
36 KiB
Python

from unittest import TestCase
from rfcartography.index_parser import Author, Status, FileFormat, RFC, NotIssued,\
STD, BCP, FYI, NIC, IEN, RTR, IndexParser,\
DocType, Stream, Document
from datetime import date
class TestDocumentClasses(TestCase):
def test_rfc_id(self):
"""testing docID for RFCs"""
rfc: RFC = RFC(791,
"Internet Protocol",
Author("J. Postel"),
date(1981, 9, 1),
Status.INTERNET_STANDARD,
Status.INTERNET_STANDARD)
self.assertEqual(rfc.docID(), 'RFC0791')
return
def test_not_issued_id(self):
"""testing docID for not issued RFCs"""
not_issued: NotIssued = NotIssued(715)
self.assertEqual(not_issued.docID(), 'RFC0715')
return
def test_std_id(self):
"""testing docID for STDs"""
std: STD = STD(6, "User Datagram Protocol")
self.assertEqual(std.docID(), 'STD0006')
return
def test_bcp_id(self):
"""testing docID for BCPs"""
bcp: BCP = BCP(200, "IAB and IESG Statement on Cryptographic Technology and the Internet")
self.assertEqual(bcp.docID(), 'BCP0200')
return
def test_fyi_id(self):
"""testing docID for FYIs"""
fyi: FYI = FYI(5, "Choosing a name for your computer")
self.assertEqual(fyi.docID(), 'FYI0005')
return
def test_nic_id(self):
"""testing docID for NICs"""
nic: NIC = NIC(42)
self.assertEqual(nic.docID(), 'NIC42')
return
def test_ien_id(self):
"""testing docID for IENs"""
ien: IEN = IEN(42)
self.assertEqual(ien.docID(), 'IEN42')
return
def test_rtr_id(self):
"""testing docID for RTRs"""
rtr: RTR = RTR(42)
self.assertEqual(rtr.docID(), 'RTR42')
return
def test_rfc_refs(self):
"""testing get_references() for RFCs"""
rfc23: RFC = RFC( 23)
rfc1337: RFC = RFC(1337)
rfc12: RFC = RFC( 12)
rfc13: RFC = RFC( 13)
rfc52: RFC = RFC( 52)
rfc53: RFC = RFC( 53)
bcp1: BCP = BCP( 1)
std2: STD = STD( 2)
ien4223: IEN = IEN(4223)
nic42: NIC = NIC( 42)
rfc: RFC = RFC(42,
"Test",
Author("J. Doe"),
date(1970, 1, 1),
Status.INTERNET_STANDARD,
Status.INTERNET_STANDARD,
obsoletes=[rfc23],
obsoleted_by=[rfc1337],
updates=[rfc12, rfc13],
updated_by=[rfc52, rfc53],
is_also=[bcp1, std2],
see_also=[ien4223, nic42])
reflist: list = rfc.get_references()
self.assertEqual(len(reflist), 10)
self.assertIn(("obsoletes", rfc23), reflist)
self.assertIn(("obsoleted by", rfc1337), reflist)
self.assertIn(("updates", rfc12), reflist)
self.assertIn(("updates", rfc13), reflist)
self.assertIn(("updated by", rfc52), reflist)
self.assertIn(("updated by", rfc53), reflist)
self.assertIn(("is also", bcp1), reflist)
self.assertIn(("is also", std2), reflist)
self.assertIn(("see also", ien4223), reflist)
self.assertIn(("see also", nic42), reflist)
return
def test_not_issued_refs(self):
"""testing get_references() for not issued RFCs"""
self.assertEqual(NotIssued(715).get_references(), [])
return
def test_std_ref(self):
"""testing get_references() for STDs"""
rfc42: RFC = RFC(42)
nic42: NIC = NIC(42)
std: STD = STD(42,
"test",
[rfc42, nic42])
reflist: list = std.get_references()
self.assertEqual(len(reflist), 2)
self.assertIn(("is also", rfc42), reflist)
self.assertIn(("is also", nic42), reflist)
return
def test_bcp_ref(self):
"""testing get_references() for BCPs"""
rfc42: RFC = RFC(42)
nic42: NIC = NIC(42)
bcp: BCP = BCP(42,
"test",
[rfc42, nic42])
reflist: list = bcp.get_references()
self.assertEqual(len(reflist), 2)
self.assertIn(("is also", rfc42), reflist)
self.assertIn(("is also", nic42), reflist)
return
def test_fyi_ref(self):
"""testing get_references() for FYIs"""
rfc42: RFC = RFC(42)
nic42: NIC = NIC(42)
fyi: FYI = FYI(42,
"test",
[rfc42, nic42])
reflist: list = fyi.get_references()
self.assertEqual(len(reflist), 2)
self.assertIn(("is also", rfc42), reflist)
self.assertIn(("is also", nic42), reflist)
return
def test_nic_refs(self):
"""testing get_references() for NICs"""
self.assertEqual(NIC(42).get_references(), [])
return
def test_ien_refs(self):
"""testing get_references() for IENs"""
self.assertEqual(IEN(42).get_references(), [])
return
def test_rtr_refs(self):
"""testing get_references() for RTRs"""
self.assertEqual(RTR(42).get_references(), [])
return
def test_rfc_update(self):
"""testing RFC updates"""
ref: NIC = NIC(42)
rfc: RFC = RFC(42)
rfc.update(title="test",
authors=[Author("test")],
pub_date=date(1984, 1, 1),
current_status=Status.EXPERIMENTAL,
pub_status=Status.PROPOSED_STANDARD,
format=FileFormat.PDF,
page_count=42,
keywords=["foo"],
abstract=["bar"],
draft="draft",
notes="notes",
obsoletes=[ref],
obsoleted_by=[ref],
updates=[ref],
updated_by=[ref],
is_also=[ref],
see_also=[ref],
stream=Stream.IETF,
area="area",
wg_acronym="wg_acronym",
errata_url="errata_url",
doi="doi")
self.assertEqual(rfc.title, "test")
self.assertEqual(len(rfc.authors), 1)
self.assertEqual(rfc.authors[0].name, "test")
self.assertEqual(rfc.pub_date.year, 1984)
self.assertEqual(rfc.pub_date.month, 1)
self.assertEqual(rfc.pub_date.day, 1)
self.assertEqual(rfc.current_status, Status.EXPERIMENTAL)
self.assertEqual(rfc.pub_status, Status.PROPOSED_STANDARD)
self.assertEqual(rfc.format, FileFormat.PDF)
self.assertEqual(rfc.page_count, 42)
self.assertEqual(len(rfc.keywords), 1)
self.assertEqual(rfc.keywords[0], "foo")
self.assertEqual(len(rfc.abstract), 1)
self.assertEqual(rfc.abstract[0], "bar")
self.assertEqual(rfc.draft, "draft")
self.assertEqual(rfc.notes, "notes")
self.assertEqual(len(rfc.obsoletes), 1)
self.assertEqual(rfc.obsoletes[0], ref)
self.assertEqual(len(rfc.obsoleted_by), 1)
self.assertEqual(rfc.obsoleted_by[0], ref)
self.assertEqual(len(rfc.updates), 1)
self.assertEqual(rfc.updates[0], ref)
self.assertEqual(len(rfc.updated_by), 1)
self.assertEqual(rfc.updated_by[0], ref)
self.assertEqual(len(rfc.is_also), 1)
self.assertEqual(rfc.is_also[0], ref)
self.assertEqual(len(rfc.see_also), 1)
self.assertEqual(rfc.see_also[0], ref)
self.assertEqual(rfc.stream, Stream.IETF)
self.assertEqual(rfc.area, "area")
self.assertEqual(rfc.wg_acronym, "wg_acronym")
self.assertEqual(rfc.errata_url, "errata_url")
self.assertEqual(rfc.doi, "doi")
return
def test_std_update(self):
"""testing STD updates"""
ref: NIC = NIC(42)
std: STD = STD(42)
std.update(title="title",
is_also=[ref])
self.assertEqual(std.title, "title")
self.assertEqual(len(std.is_also), 1)
self.assertEqual(std.is_also[0], ref)
return
def test_bcp_update(self):
"""testing BCP updates"""
ref: NIC = NIC(42)
bcp: BCP = BCP(42)
bcp.update(title="title",
is_also=[ref])
self.assertEqual(bcp.title, "title")
self.assertEqual(len(bcp.is_also), 1)
self.assertEqual(bcp.is_also[0], ref)
return
def test_fyi_update(self):
"""testing FYI updates"""
ref: NIC = NIC(42)
fyi: FYI = FYI(42)
fyi.update(title="title",
is_also=[ref])
self.assertEqual(fyi.title, "title")
self.assertEqual(len(fyi.is_also), 1)
self.assertEqual(fyi.is_also[0], ref)
return
def test_not_issued_update(self):
"""testing RFC not issued updates"""
before: NotIssued = NotIssued(42)
after: NotIssued = before.update(title="test")
self.assertEqual(before, after)
return
def test_nic_update(self):
"""testing NIC updates"""
before: NIC = NIC(42)
after: NIC = before.update(title="test")
self.assertEqual(before, after)
return
def test_ien_update(self):
"""testing IEN updates"""
before: IEN = IEN(42)
after: IEN = before.update(title="test")
self.assertEqual(before, after)
return
def test_rtr_update(self):
"""testing RTR updates"""
before: RTR = RTR(42)
after: RTR = before.update(title="test")
self.assertEqual(before, after)
return
class TestIndexParser(TestCase):
def test_bcp(self):
"""testing index parser for BCP entries"""
xml: str = """<?xml version="1.0" encoding="UTF-8"?>
<rfc-index xmlns="http://www.rfc-editor.org/rfc-index"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rfc-editor.org/rfc-index
http://www.rfc-editor.org/rfc-index.xsd">
<bcp-entry>
<doc-id>BCP0001</doc-id>
</bcp-entry>
<bcp-entry>
<doc-id>BCP0188</doc-id>
<is-also>
<doc-id>RFC7258</doc-id>
</is-also>
</bcp-entry>
<bcp-entry>
<doc-id>BCP0185</doc-id>
<is-also>
<doc-id>RFC7115</doc-id>
<doc-id>RFC9319</doc-id>
</is-also>
</bcp-entry>
</rfc-index>"""
parser: IndexParser = IndexParser(xml)
self.assertEqual(len(parser.index[DocType.BCP]), 3)
# w/o is-also
self.assertEqual(parser.index[DocType.BCP][1].docID(), 'BCP0001')
self.assertEqual(len(parser.index[DocType.BCP][1].is_also), 0)
# with single is-also
self.assertEqual(parser.index[DocType.BCP][188].docID(), 'BCP0188')
self.assertEqual(len(parser.index[DocType.BCP][188].is_also), 1)
self.assertEqual(parser.index[DocType.BCP][188].is_also[0].docID(), 'RFC7258')
# with multiple is-also
self.assertEqual(parser.index[DocType.BCP][185].docID(), 'BCP0185')
self.assertEqual(len(parser.index[DocType.BCP][185].is_also), 2)
self.assertEqual(parser.index[DocType.BCP][185].is_also[0].docID(), 'RFC7115')
self.assertEqual(parser.index[DocType.BCP][185].is_also[1].docID(), 'RFC9319')
return
def test_fyi(self):
"""testing index parser for FYI entries"""
xml: str = """<?xml version="1.0" encoding="UTF-8"?>
<rfc-index xmlns="http://www.rfc-editor.org/rfc-index"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rfc-editor.org/rfc-index
http://www.rfc-editor.org/rfc-index.xsd">
<fyi-entry>
<doc-id>FYI0042</doc-id>
</fyi-entry>
<fyi-entry>
<doc-id>FYI0023</doc-id>
<is-also>
<doc-id>RFC1580</doc-id>
</is-also>
</fyi-entry>
<fyi-entry>
<doc-id>FYI0666</doc-id>
<is-also>
<doc-id>RFC1149</doc-id>
<doc-id>RFC2549</doc-id>
<doc-id>RFC6214</doc-id>
</is-also>
</fyi-entry>
</rfc-index>"""
parser: IndexParser = IndexParser(xml)
self.assertEqual(len(parser.index[DocType.FYI]), 3)
# w/o is-also
self.assertEqual(parser.index[DocType.FYI][42].docID(), 'FYI0042')
self.assertEqual(len(parser.index[DocType.FYI][42].is_also), 0)
# with single is-also
self.assertEqual(parser.index[DocType.FYI][23].docID(), 'FYI0023')
self.assertEqual(len(parser.index[DocType.FYI][23].is_also), 1)
self.assertEqual(parser.index[DocType.FYI][23].is_also[0].docID(), 'RFC1580')
# with multiple is-also
self.assertEqual(parser.index[DocType.FYI][666].docID(), 'FYI0666')
self.assertEqual(len(parser.index[DocType.FYI][666].is_also), 3)
self.assertEqual(parser.index[DocType.FYI][666].is_also[0].docID(), 'RFC1149')
self.assertEqual(parser.index[DocType.FYI][666].is_also[1].docID(), 'RFC2549')
self.assertEqual(parser.index[DocType.FYI][666].is_also[2].docID(), 'RFC6214')
return
def test_rfc(self):
"""testing index parser for RFC entries"""
xml: str = """<?xml version="1.0" encoding="UTF-8"?>
<rfc-index xmlns="http://www.rfc-editor.org/rfc-index"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rfc-editor.org/rfc-index
http://www.rfc-editor.org/rfc-index.xsd">
<rfc-entry>
<doc-id>RFC0023</doc-id>
<title>Foo</title>
<author>
<name>J. Doe</name>
</author>
<date>
<month>April</month>
<year>2042</year>
</date>
<current-status>PROPOSED STANDARD</current-status>
<publication-status>INFORMATIONAL</publication-status>
</rfc-entry>
<rfc-entry>
<doc-id>RFC0042</doc-id>
<title>Bar</title>
<author>
<name>J. Doe</name>
<title>Editor</title>
<organization>A Company that Makes Everything</organization>
<org-abbrev>ACME</org-abbrev>
</author>
<date>
<day>28</day>
<month>February</month>
<year>2042</year>
</date>
<format>
<file-format>ASCII</file-format>
</format>
<page-count>42</page-count>
<keywords>
<kw>foo</kw>
</keywords>
<abstract>
<p>This is a test</p>
</abstract>
<draft>draft-test-test-test</draft>
<notes>this is a note</notes>
<obsoletes>
<doc-id>RFC0023</doc-id>
</obsoletes>
<obsoleted-by>
<doc-id>RFC0666</doc-id>
</obsoleted-by>
<updates>
<doc-id>RFC0023</doc-id>
</updates>
<updated-by>
<doc-id>RFC0666</doc-id>
</updated-by>
<is-also>
<doc-id>BCP0666</doc-id>
</is-also>
<see-also>
<doc-id>RFC0023</doc-id>
</see-also>
<current-status>HISTORIC</current-status>
<publication-status>UNKNOWN</publication-status>
<stream>IETF</stream>
<area>foo</area>
<wg_acronym>bar</wg_acronym>
<errata-url>http://example.org</errata-url>
<doi>10.17487/RFC0042</doi>
</rfc-entry>
<rfc-entry>
<doc-id>RFC0666</doc-id>
<title>FooBar</title>
<author>
<name>J. Doe</name>
<title>Editor</title>
<organization>A Company that Makes Everything</organization>
<org-abbrev>ACME</org-abbrev>
</author>
<author>
<name>M. Mustermann</name>
</author>
<date>
<day>28</day>
<month>February</month>
<year>2042</year>
</date>
<format>
<file-format>TEXT</file-format>
<file-format>HTML</file-format>
</format>
<page-count>666</page-count>
<keywords>
<kw>foo</kw>
<kw>bar</kw>
</keywords>
<abstract>
<p>This is a test</p>
<p>more testing</p>
</abstract>
<draft>draft-test-test-test</draft>
<notes>this is a note</notes>
<obsoletes>
<doc-id>RFC0023</doc-id>
<doc-id>RFC0042</doc-id>
</obsoletes>
<obsoleted-by>
<doc-id>RFC1337</doc-id>
<doc-id>RFC6666</doc-id>
</obsoleted-by>
<updates>
<doc-id>RFC0023</doc-id>
<doc-id>RFC0042</doc-id>
</updates>
<updated-by>
<doc-id>RFC1337</doc-id>
<doc-id>RFC6666</doc-id>
</updated-by>
<is-also>
<doc-id>BCP6666</doc-id>
<doc-id>STD0666</doc-id>
</is-also>
<see-also>
<doc-id>RFC0023</doc-id>
<doc-id>RFC0042</doc-id>
</see-also>
<current-status>INTERNET STANDARD</current-status>
<publication-status>DRAFT STANDARD</publication-status>
<stream>INDEPENDENT</stream>
<area>foo</area>
<wg_acronym>bar</wg_acronym>
<errata-url>http://example.org</errata-url>
<doi>10.17487/RFC0666</doi>
</rfc-entry>
</rfc-index>"""
parser: IndexParser = IndexParser(xml)
self.assertEqual(len(parser.index[DocType.RFC]), 5)
# minimal data
self.assertEqual(parser.index[DocType.RFC][23].docID(), 'RFC0023')
self.assertEqual(len(parser.index[DocType.RFC][23].is_also), 0)
self.assertEqual(parser.index[DocType.RFC][23].title, "Foo")
self.assertEqual(len(parser.index[DocType.RFC][23].authors), 1)
self.assertEqual(parser.index[DocType.RFC][23].authors[0].name, "J. Doe")
self.assertEqual(parser.index[DocType.RFC][23].authors[0].title, "")
self.assertEqual(parser.index[DocType.RFC][23].authors[0].organization, "")
self.assertEqual(parser.index[DocType.RFC][23].authors[0].org_abbrev, "")
self.assertEqual(parser.index[DocType.RFC][23].pub_date.year, 2042)
self.assertEqual(parser.index[DocType.RFC][23].pub_date.month, 4)
self.assertEqual(parser.index[DocType.RFC][23].pub_date.day, 1)
self.assertEqual(len(parser.index[DocType.RFC][23].format), 0)
self.assertEqual(parser.index[DocType.RFC][23].current_status, Status.PROPOSED_STANDARD)
self.assertEqual(parser.index[DocType.RFC][23].pub_status, Status.INFORMATIONAL)
self.assertIsNone(parser.index[DocType.RFC][23].page_count)
self.assertEqual(len(parser.index[DocType.RFC][23].keywords), 0)
self.assertEqual(len(parser.index[DocType.RFC][23].abstract), 0)
self.assertEqual(parser.index[DocType.RFC][23].draft, "")
self.assertEqual(parser.index[DocType.RFC][23].notes, "")
self.assertEqual(len(parser.index[DocType.RFC][23].obsoletes), 0)
self.assertEqual(len(parser.index[DocType.RFC][23].obsoleted_by), 0)
self.assertEqual(len(parser.index[DocType.RFC][23].updates), 0)
self.assertEqual(len(parser.index[DocType.RFC][23].updated_by), 0)
self.assertEqual(len(parser.index[DocType.RFC][23].is_also), 0)
self.assertEqual(len(parser.index[DocType.RFC][23].see_also), 0)
self.assertIsNone(parser.index[DocType.RFC][23].stream)
self.assertEqual(parser.index[DocType.RFC][23].area, "")
self.assertEqual(parser.index[DocType.RFC][23].wg_acronym, "")
self.assertEqual(parser.index[DocType.RFC][23].errata_url, "")
self.assertEqual(parser.index[DocType.RFC][23].doi, "")
# single entry for each data entry
self.assertEqual(parser.index[DocType.RFC][42].docID(), 'RFC0042')
self.assertEqual(parser.index[DocType.RFC][42].title, "Bar")
self.assertEqual(len(parser.index[DocType.RFC][42].authors), 1)
self.assertEqual(parser.index[DocType.RFC][42].authors[0].name, "J. Doe")
self.assertEqual(parser.index[DocType.RFC][42].authors[0].title, "Editor")
self.assertEqual(parser.index[DocType.RFC][42].authors[0].organization, "A Company that Makes Everything")
self.assertEqual(parser.index[DocType.RFC][42].authors[0].org_abbrev, "ACME")
self.assertEqual(parser.index[DocType.RFC][42].pub_date.year, 2042)
self.assertEqual(parser.index[DocType.RFC][42].pub_date.month, 2)
self.assertEqual(parser.index[DocType.RFC][42].pub_date.day, 28)
self.assertEqual(len(parser.index[DocType.RFC][42].format), 1)
self.assertEqual(parser.index[DocType.RFC][42].format[0], FileFormat.ASCII)
self.assertEqual(parser.index[DocType.RFC][42].current_status, Status.HISTORIC)
self.assertEqual(parser.index[DocType.RFC][42].pub_status, Status.UNKNOWN)
self.assertEqual(parser.index[DocType.RFC][42].page_count, 42)
self.assertEqual(len(parser.index[DocType.RFC][42].keywords), 1)
self.assertEqual(parser.index[DocType.RFC][42].keywords[0], "foo")
self.assertEqual(len(parser.index[DocType.RFC][42].abstract), 1)
self.assertEqual(parser.index[DocType.RFC][42].abstract[0], "This is a test")
self.assertEqual(parser.index[DocType.RFC][42].draft, "draft-test-test-test")
self.assertEqual(parser.index[DocType.RFC][42].notes, "this is a note")
self.assertEqual(len(parser.index[DocType.RFC][42].obsoletes), 1)
self.assertEqual(parser.index[DocType.RFC][42].obsoletes[0].docID(), 'RFC0023')
self.assertEqual(len(parser.index[DocType.RFC][42].obsoleted_by), 1)
self.assertEqual(parser.index[DocType.RFC][42].obsoleted_by[0].docID(), 'RFC0666')
self.assertEqual(len(parser.index[DocType.RFC][42].updates), 1)
self.assertEqual(parser.index[DocType.RFC][42].updates[0].docID(), 'RFC0023')
self.assertEqual(len(parser.index[DocType.RFC][42].updated_by), 1)
self.assertEqual(parser.index[DocType.RFC][42].updated_by[0].docID(), 'RFC0666')
self.assertEqual(len(parser.index[DocType.RFC][42].is_also), 1)
self.assertEqual(parser.index[DocType.RFC][42].is_also[0].docID(), 'BCP0666')
self.assertEqual(len(parser.index[DocType.RFC][42].see_also), 1)
self.assertEqual(parser.index[DocType.RFC][42].see_also[0].docID(), 'RFC0023')
self.assertEqual(parser.index[DocType.RFC][42].stream, Stream.IETF)
self.assertEqual(parser.index[DocType.RFC][42].area, "foo")
self.assertEqual(parser.index[DocType.RFC][42].wg_acronym, "bar")
self.assertEqual(parser.index[DocType.RFC][42].errata_url, "http://example.org")
self.assertEqual(parser.index[DocType.RFC][42].doi, "10.17487/RFC0042")
# multiple entries where allowed
self.assertEqual(parser.index[DocType.RFC][666].docID(), 'RFC0666')
self.assertEqual(parser.index[DocType.RFC][666].title, "FooBar")
self.assertEqual(len(parser.index[DocType.RFC][666].authors), 2)
self.assertEqual(parser.index[DocType.RFC][666].authors[0].name, "J. Doe")
self.assertEqual(parser.index[DocType.RFC][666].authors[0].title, "Editor")
self.assertEqual(parser.index[DocType.RFC][666].authors[0].organization, "A Company that Makes Everything")
self.assertEqual(parser.index[DocType.RFC][666].authors[0].org_abbrev, "ACME")
self.assertEqual(parser.index[DocType.RFC][666].authors[1].name, "M. Mustermann")
self.assertEqual(parser.index[DocType.RFC][666].authors[1].title, "")
self.assertEqual(parser.index[DocType.RFC][666].authors[1].organization, "")
self.assertEqual(parser.index[DocType.RFC][666].authors[1].org_abbrev, "")
self.assertEqual(parser.index[DocType.RFC][666].pub_date.year, 2042)
self.assertEqual(parser.index[DocType.RFC][666].pub_date.month, 2)
self.assertEqual(parser.index[DocType.RFC][666].pub_date.day, 28)
self.assertEqual(len(parser.index[DocType.RFC][666].format), 2)
self.assertEqual(parser.index[DocType.RFC][666].format[0], FileFormat.TEXT)
self.assertEqual(parser.index[DocType.RFC][666].format[1], FileFormat.HTML)
self.assertEqual(parser.index[DocType.RFC][666].current_status, Status.INTERNET_STANDARD)
self.assertEqual(parser.index[DocType.RFC][666].pub_status, Status.DRAFT_STANDARD)
self.assertEqual(parser.index[DocType.RFC][666].page_count, 666)
self.assertEqual(len(parser.index[DocType.RFC][666].keywords), 2)
self.assertEqual(parser.index[DocType.RFC][666].keywords[0], "foo")
self.assertEqual(parser.index[DocType.RFC][666].keywords[1], "bar")
self.assertEqual(len(parser.index[DocType.RFC][666].abstract), 2)
self.assertEqual(parser.index[DocType.RFC][666].abstract[0], "This is a test")
self.assertEqual(parser.index[DocType.RFC][666].abstract[1], "more testing")
self.assertEqual(parser.index[DocType.RFC][666].draft, "draft-test-test-test")
self.assertEqual(parser.index[DocType.RFC][666].notes, "this is a note")
self.assertEqual(len(parser.index[DocType.RFC][666].obsoletes), 2)
self.assertEqual(parser.index[DocType.RFC][666].obsoletes[0].docID(), 'RFC0023')
self.assertEqual(parser.index[DocType.RFC][666].obsoletes[1].docID(), 'RFC0042')
self.assertEqual(len(parser.index[DocType.RFC][666].obsoleted_by), 2)
self.assertEqual(parser.index[DocType.RFC][666].obsoleted_by[0].docID(), 'RFC1337')
self.assertEqual(parser.index[DocType.RFC][666].obsoleted_by[1].docID(), 'RFC6666')
self.assertEqual(len(parser.index[DocType.RFC][666].updates), 2)
self.assertEqual(parser.index[DocType.RFC][666].updates[0].docID(), 'RFC0023')
self.assertEqual(parser.index[DocType.RFC][666].updates[1].docID(), 'RFC0042')
self.assertEqual(len(parser.index[DocType.RFC][666].updated_by), 2)
self.assertEqual(parser.index[DocType.RFC][666].updated_by[0].docID(), 'RFC1337')
self.assertEqual(parser.index[DocType.RFC][666].updated_by[1].docID(), 'RFC6666')
self.assertEqual(len(parser.index[DocType.RFC][666].is_also), 2)
self.assertEqual(parser.index[DocType.RFC][666].is_also[0].docID(), 'BCP6666')
self.assertEqual(parser.index[DocType.RFC][666].is_also[1].docID(), 'STD0666')
self.assertEqual(len(parser.index[DocType.RFC][666].see_also), 2)
self.assertEqual(parser.index[DocType.RFC][666].see_also[0].docID(), 'RFC0023')
self.assertEqual(parser.index[DocType.RFC][666].see_also[1].docID(), 'RFC0042')
self.assertEqual(parser.index[DocType.RFC][666].stream, Stream.INDEPENDENT)
self.assertEqual(parser.index[DocType.RFC][666].area, "foo")
self.assertEqual(parser.index[DocType.RFC][666].wg_acronym, "bar")
self.assertEqual(parser.index[DocType.RFC][666].errata_url, "http://example.org")
self.assertEqual(parser.index[DocType.RFC][666].doi, "10.17487/RFC0666")
return
def test_std(self):
"""testing index parser for STD entries"""
xml: str = """<?xml version="1.0" encoding="UTF-8"?>
<rfc-index xmlns="http://www.rfc-editor.org/rfc-index"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rfc-editor.org/rfc-index
http://www.rfc-editor.org/rfc-index.xsd">
<std-entry>
<doc-id>STD0666</doc-id>
<title>test</title>
</std-entry>
<std-entry>
<doc-id>STD0099</doc-id>
<title>HTTP/1.1</title>
<is-also>
<doc-id>RFC9112</doc-id>
</is-also>
</std-entry>
<std-entry>
<doc-id>STD0078</doc-id>
<title>Simple Network Management Protocol (SNMP) Security</title>
<is-also>
<doc-id>RFC5343</doc-id>
<doc-id>RFC5590</doc-id>
<doc-id>RFC5591</doc-id>
<doc-id>RFC6353</doc-id>
</is-also>
</std-entry>
</rfc-index>"""
parser: IndexParser = IndexParser(xml)
self.assertEqual(len(parser.index[DocType.STD]), 3)
# w/o is-also
self.assertEqual(parser.index[DocType.STD][666].docID(), 'STD0666')
self.assertEqual(parser.index[DocType.STD][666].title, 'test')
self.assertEqual(len(parser.index[DocType.STD][666].is_also), 0)
# with single is-also
self.assertEqual(parser.index[DocType.STD][99].docID(), 'STD0099')
self.assertEqual(parser.index[DocType.STD][99].title, 'HTTP/1.1')
self.assertEqual(len(parser.index[DocType.STD][99].is_also), 1)
self.assertEqual(parser.index[DocType.STD][99].is_also[0].docID(), 'RFC9112')
# with multiple is-also
self.assertEqual(parser.index[DocType.STD][78].docID(), 'STD0078')
self.assertEqual(parser.index[DocType.STD][78].title, 'Simple Network Management Protocol (SNMP) Security')
self.assertEqual(len(parser.index[DocType.STD][78].is_also), 4)
self.assertEqual(parser.index[DocType.STD][78].is_also[0].docID(), 'RFC5343')
self.assertEqual(parser.index[DocType.STD][78].is_also[1].docID(), 'RFC5590')
self.assertEqual(parser.index[DocType.STD][78].is_also[2].docID(), 'RFC5591')
self.assertEqual(parser.index[DocType.STD][78].is_also[3].docID(), 'RFC6353')
return
def test_not_issued(self):
"""testing index parser for RFC not issued entries"""
xml: str = """<?xml version="1.0" encoding="UTF-8"?>
<rfc-index xmlns="http://www.rfc-editor.org/rfc-index"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rfc-editor.org/rfc-index
http://www.rfc-editor.org/rfc-index.xsd">
<rfc-not-issued-entry>
<doc-id>RFC0042</doc-id>
</rfc-not-issued-entry>
</rfc-index>"""
parser: IndexParser = IndexParser(xml)
self.assertEqual(len(parser.index[DocType.RFC]), 1)
self.assertEqual(parser.index[DocType.RFC][42].docID(), 'RFC0042')
return
def test_get_index(self):
"""testing the parser's get_index() function"""
xml: str = """<?xml version="1.0" encoding="UTF-8"?>
<rfc-index xmlns="http://www.rfc-editor.org/rfc-index"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rfc-editor.org/rfc-index
http://www.rfc-editor.org/rfc-index.xsd">
<rfc-not-issued-entry>
<doc-id>RFC0042</doc-id>
</rfc-not-issued-entry>
</rfc-index>"""
parser: IndexParser = IndexParser(xml)
index: dict[DocType: dict[int, Document]] = parser.get_index()
self.assertIn(DocType.RFC, index)
self.assertIn(DocType.STD, index)
self.assertIn(DocType.BCP, index)
self.assertIn(DocType.FYI, index)
self.assertIn(DocType.NIC, index)
self.assertIn(DocType.IEN, index)
self.assertIn(DocType.RTR, index)
self.assertEqual(index[DocType.RFC][42].docID(), 'RFC0042')
return