def test_has_requirments(): """Validate that certain attributes are required""" root_attrs = { "eregs-version-id": "vvv", "fr-volume": 124, "fr-start-page": 44, "fr-end-page": 55 } with XMLBuilder("ROOT", **root_attrs) as ctx: ctx.DATES(**{"eregs-published-date": "2005-05-05"}) notice_xml = NoticeXML(ctx.xml_copy()) assert import_notice.has_requirements(notice_xml) notice_xml = NoticeXML(ctx.xml_copy()) del notice_xml.xml.attrib['eregs-version-id'] assert not import_notice.has_requirements(notice_xml) notice_xml = NoticeXML(ctx.xml_copy()) del notice_xml.xml.attrib['fr-volume'] assert not import_notice.has_requirements(notice_xml) notice_xml = NoticeXML(ctx.xml_copy()) del notice_xml.xml.attrib['fr-start-page'] assert not import_notice.has_requirements(notice_xml) notice_xml = NoticeXML(ctx.xml_copy()) del notice_xml.xml.xpath('//DATES')[0].attrib['eregs-published-date'] assert not import_notice.has_requirements(notice_xml)
def add_notices(): """Adds an uneven assortment of notices""" root_attrs = { "eregs-version-id": "v0", "fr-volume": 1, "fr-start-page": 2, "fr-end-page": 3 } with XMLBuilder("ROOT", **root_attrs) as ctx: ctx.AGENCY("Agency") ctx.SUBJECT("Subj") ctx.DATES(**{'eregs-published-date': '2001-01-01'}) with ctx.EREGS_CFR_REFS(): ctx.EREGS_CFR_TITLE_REF(title=11) xml = ctx.xml entry.Notice('v0').write(NoticeXML(xml)) etree.SubElement(xml.xpath('//EREGS_CFR_TITLE_REF')[0], 'EREGS_CFR_PART_REF', part='1000') xml.attrib['eregs-version-id'] = 'v1' entry.Notice('v1').write(NoticeXML(xml)) xml.xpath('//EREGS_CFR_TITLE_REF')[0].attrib['title'] = '12' xml.attrib['eregs-version-id'] = 'v2' entry.Notice('v2').write(NoticeXML(xml)) xml.attrib['eregs-version-id'] = 'v3' entry.Notice('v3').write(NoticeXML(xml))
def parse_notice(xml_file_path): """Read the notice from the XML file; fill out any missing fields""" with open(xml_file_path, 'rb') as f: notice_xml = NoticeXML(f.read(), xml_file_path).preprocess() if has_requirements(notice_xml): notice_xml.derive_where_needed() return notice_xml
def test_process_version_if_needed_success(): """If the requirements are present we should write the version data""" notice_xml = NoticeXML(XMLBuilder().xml) notice_xml.effective = date(2001, 1, 1) notice_xml.fr_volume = 2 notice_xml.start_page = 3 entry.Notice('vvv').write(notice_xml) full_issuance.process_version_if_needed('title', 'part', 'vvv') result = entry.Version('title', 'part', 'vvv').read() assert result.identifier == 'vvv' assert result.effective == date(2001, 1, 1) assert result.fr_citation == Citation(2, 3)
def setUp(self): super(CommandsFetchSxSTests, self).setUp() self.cli = CliRunner() with XMLBuilder("ROOT") as ctx: ctx.PRTPAGE(P="1234") ctx.CFR('12 CFR 1000') self.notice_xml = NoticeXML(ctx.xml)
def example_xml(self, effdate_str="", source=None): """Returns a simple notice-like XML structure""" with XMLBuilder("ROOT") as ctx: ctx.CONTENT() ctx.P() with ctx.EFFDATE(): ctx.P(effdate_str) return NoticeXML(ctx.xml, source)
def setUp(self): super(CommandsFetchSxSTests, self).setUp() self.cli = CliRunner() with XMLBuilder("ROOT") as ctx: ctx.PRTPAGE(P="1234") with ctx.EREGS_CFR_REFS(): with ctx.EREGS_CFR_TITLE_REF(title="12"): ctx.EREGS_CFR_PART_REF(part="1000") self.notice_xml = NoticeXML(ctx.xml)
def build(doc_number, effective_on, cfr_title, cfr_part): notice_xml = NoticeXML( etree.fromstring(""" <ROOT> <AGENCY></AGENCY> <SUBJECT></SUBJECT> </ROOT> """)) notice_xml.fr_volume = 10 notice_xml.version_id = doc_number notice_xml.effective = effective_on notice_xml.published = effective_on notice_xml.start_page = 0 notice_xml.end_page = 0 notice_xml.cfr_refs = [TitlePartsRef(cfr_title, [cfr_part])] return notice_xml
def test_parse_preamble_integration(self): """End-to-end test for parsing a notice preamble""" with XMLBuilder("ROOT") as ctx: ctx.P("ignored content") with ctx.SUPLINF(): ctx.HED("Supp Inf") ctx.P("P1") ctx.P("P2") ctx.HD("I. H1", SOURCE="HD1") ctx.P("H1-P1") ctx.HD("A. H1-1", SOURCE="HD2") ctx.P("H1-1-P1") ctx.P("H1-1-P2") ctx.HD("B. H1-2", SOURCE="HD2") ctx.P("H1-2-P1") ctx.HD("II. H2", SOURCE="HD1") ctx.P("H2-P1") ctx.P("H2-P2") with ctx.GPH(): ctx.GID("111-222-333") ctx.LSTSUB() ctx.P("ignored") ctx.P("tail also ignored") xml = NoticeXML(ctx.xml) xml.version_id = 'vvv-yyy' root = NodeAccessor(preamble.parse_preamble(xml)) self.assertEqual(root.label, ['vvv_yyy']) self.assertEqual(root.title, 'Supp Inf') self.assertEqual(root['p1'].text, 'P1') self.assertEqual(root['p2'].text, 'P2') self.assertEqual(root['I'].title, 'I. H1') self.assertEqual(root['I'].text, 'H1-P1') # becomes intro self.assertEqual(root['I']['A'].title, 'A. H1-1') self.assertEqual(root['I']['A']['p1'].text, 'H1-1-P1') self.assertEqual(root['I']['A']['p2'].text, 'H1-1-P2') self.assertEqual(root['I']['B'].title, 'B. H1-2') self.assertEqual(root['I']['B'].text, 'H1-2-P1') # becomes intro self.assertEqual(root['II'].title, 'II. H2') self.assertEqual(root['II']['p1'].text, 'H2-P1') self.assertEqual(root['II']['p2'].text, 'H2-P2') self.assertEqual(root['II']['p3'].text, '![](111-222-333)')
def build(doc_number, effective_on, cfr_title, cfr_part): notice_xml = NoticeXML(etree.fromstring(""" <ROOT> <AGENCY></AGENCY> <SUBJECT></SUBJECT> </ROOT> """)) notice_xml.fr_volume = 10 notice_xml.version_id = doc_number notice_xml.effective = effective_on notice_xml.published = effective_on notice_xml.start_page = 0 notice_xml.end_page = 0 notice_xml.cfr_refs = [TitlePartsRef(cfr_title, [cfr_part])] return notice_xml
def test_process_tree_if_needed_success(monkeypatch): """If the requirements are present we should call tree-parsing function""" mock_regtext = Mock(return_value=Node('root')) monkeypatch.setattr(full_issuance, 'build_tree', mock_regtext) with XMLBuilder() as ctx: ctx.REGTEXT(TITLE=1, PART=2) entry.Notice('vvv').write(NoticeXML(ctx.xml)) full_issuance.process_tree_if_needed('1', '2', 'vvv') result = entry.Tree('1', '2', 'vvv').read() assert result.text == 'root' xml_given = mock_regtext.call_args[0][0] assert etree.tostring(xml_given) == etree.tostring(ctx.xml[0])
def deserialize(self, content): return NoticeXML(content, str(self))
def test_parse_preamble_integration(self): """End-to-end test for parsing a notice preamble""" with XMLBuilder("ROOT") as ctx: ctx.P("ignored content") with ctx.SUM(): ctx.HD("SUMMARY:") ctx.P("Out of order summary paragraph one") ctx.P("Out of order summary paragraph two") with ctx.AGY(): ctx.HD("AGENCY:") ctx.P("Agency name here.") with ctx.SUM(): ctx.HD("SUMMARY 2:") ctx.P("Out of order summary") with ctx.SUPLINF(): ctx.HED("Supp Inf") ctx.P("P1") ctx.P("P2") ctx.HD("I. H1", SOURCE="HD1") ctx.P("H1-P1") ctx.HD("A. H1-1", SOURCE="HD2") ctx.P("H1-1-P1") ctx.P("H1-1-P2") ctx.HD("B. H1-2", SOURCE="HD2") ctx.P("H1-2-P1") ctx.HD("II. H2", SOURCE="HD1") ctx.P("H2-P1") ctx.P("H2-P2") with ctx.GPH(): ctx.GID("111-222-333") ctx.LSTSUB() ctx.P("ignored") ctx.P("tail also ignored") xml = NoticeXML(ctx.xml) xml.version_id = 'vvv-yyy' root = NodeAccessor(preamble.parse_preamble(xml)) self.assertEqual(root.label, ['vvv_yyy']) self.assertEqual(root.title, 'Supp Inf') self.assertEqual(root.child_labels, ['intro', 'p1', 'p2', 'I', 'II']) # We maintain the order presented self.assertEqual(root['intro']['p1'].title, 'SUMMARY:') self.assertEqual(root['intro']['p1'].text, '') self.assertEqual(root['intro']['p1']['p1'].text, 'Out of order summary paragraph one') self.assertEqual(root['intro']['p1']['p2'].text, 'Out of order summary paragraph two') self.assertEqual(root['intro']['p2'].title, 'AGENCY:') self.assertEqual(root['intro']['p2'].text, '') self.assertEqual(root['intro']['p2']['p1'].text, 'Agency name here.') self.assertEqual(root['intro']['p3'].title, 'SUMMARY 2:') self.assertEqual(root['intro']['p3'].text, '') self.assertEqual(root['intro']['p3']['p1'].text, 'Out of order summary') self.assertEqual(root['p1'].text, 'P1') self.assertEqual(root['p2'].text, 'P2') self.assertEqual(root['I'].title, 'I. H1') self.assertEqual(root['I'].text, 'H1-P1') # becomes intro self.assertEqual(root['I']['A'].title, 'A. H1-1') self.assertEqual(root['I']['A']['p1'].text, 'H1-1-P1') self.assertEqual(root['I']['A']['p2'].text, 'H1-1-P2') self.assertEqual(root['I']['B'].title, 'B. H1-2') self.assertEqual(root['I']['B'].text, 'H1-2-P1') # becomes intro self.assertEqual(root['II'].title, 'II. H2') self.assertEqual(root['II']['p1'].text, 'H2-P1') self.assertEqual(root['II']['p2'].text, 'H2-P2') self.assertEqual(root['II']['p3'].text, '![](111-222-333)')