コード例 #1
0
    def test_docket_ids(self):
        def ditest(dis, expected, xml=None):
            if not xml:
                xml = self._dummy_notice()
            dis = dis or xml.derive_docket_ids()
            xml.docket_ids = dis
            self.assertEquals(expected, xml.docket_ids)

        # From the metadata:
        ditest(["EPA-HQ-SFUND-2010-1086"], ["EPA-HQ-SFUND-2010-1086"])

        # From the XML:
        with XMLBuilder("ROOT") as root:
            root.DEPDOC("[EPA-HQ-SFUND-2010-1086]")
        xml = notice_xml.NoticeXML(root.xml)
        ditest([], ["EPA-HQ-SFUND-2010-1086"], xml=xml)

        # From the XML, two docket ids:
        with XMLBuilder("ROOT") as root:
            root.DEPDOC("[EPA-HQ-SFUND-2010-1086; FRL-9925-69-OLEM]")
        xml = notice_xml.NoticeXML(root.xml)
        ditest([], ["EPA-HQ-SFUND-2010-1086", "FRL-9925-69-OLEM"], xml=xml)

        # Two docket ids, metadata:
        ditest(["EPA-HQ-SFUND-2010-1086", "FRL-9925-69-OLEM"],
               ["EPA-HQ-SFUND-2010-1086", "FRL-9925-69-OLEM"])
コード例 #2
0
 def test_source_is_local(self):
     for url in ('https://example.com', 'http://example.com'):
         self.assertFalse(
             notice_xml.NoticeXML(b'<ROOT/>', source=url).source_is_local)
     for path in ('./dot/relative', 'normal/relative', '/absolute/ref'):
         self.assertTrue(
             notice_xml.NoticeXML(b'<ROOT/>', source=path).source_is_local)
コード例 #3
0
    def test_rins(self):
        def rinstest(rins, expected, xml=None):
            if not xml:
                xml = self._dummy_notice()
            rins = rins or xml.derive_rins()
            xml.rins = rins
            self.assertEquals(expected, xml.rins)

        # From the metadata:
        rinstest(["2050-AG67"], ["2050-AG67"])

        # From the XML:
        with XMLBuilder("ROOT") as root:
            root.RIN("RIN 2050-AG68")
        xml = notice_xml.NoticeXML(root.xml)
        rinstest([], ["2050-AG68"], xml=xml)

        # From the XML, no prefix:
        with XMLBuilder("ROOT") as root:
            root.RIN(" 2050-AG69")
        xml = notice_xml.NoticeXML(root.xml)
        rinstest([], ["2050-AG69"], xml=xml)

        # Two numbers:
        rinstest(["2050-AG60", "2050-AG61"], ["2050-AG60", "2050-AG61"])

        # Two numbers XML:
        with XMLBuilder("ROOT") as root:
            root.RIN("RIN 2050-AG60")
            root.RIN("RIN 2050-AG61")
        xml = notice_xml.NoticeXML(root.xml)
        rinstest([], ["2050-AG60", "2050-AG61"], xml=xml)
コード例 #4
0
    def test_set_effective_date_create(self):
        """The DATES tag should get created if not present in the XML"""
        xml = notice_xml.NoticeXML(XMLBuilder('ROOT').xml)

        xml.effective = '2005-05-05'
        self.assertEqual(xml.effective, date(2005, 5, 5))
        xml = notice_xml.NoticeXML(xml.xml_str())
        self.assertEqual(xml.effective, date(2005, 5, 5))
コード例 #5
0
 def test_set_agencies_simple(self):
     """
     Test that we can properly derive agency info from the metadata or the
     XML itself, and that it's added to the XML.
     """
     agencies_info = [{
         u'name':
         u'Environmental Protection Agency',
         u'parent_id':
         None,
         u'raw_name':
         u'ENVIRONMENTAL PROTECTION AGENCY',
         u'url':
         u'%s%s' % (u'https://www.federalregister.gov/',
                    u'agencies/environmental-protection-agency'),
         u'json_url':
         u'%s%s' %
         ('https://www.federalregister.gov/', 'api/v1/agencies/145.json'),
         u'id':
         145
     }]
     with XMLBuilder("ROOT") as ctx:
         with ctx.DATES():
             ctx.P("Effective on May 4, 2004")
     xml = notice_xml.NoticeXML(ctx.xml)
     xml.set_agencies(agencies=agencies_info)
     self.assertEquals(len(xml.xpath("//EREGS_AGENCIES")), 1)
     eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
     self.assertEquals(len(eregs_agencies.xpath("//EREGS_AGENCY")), 1)
     epa = eregs_agencies.xpath("//EREGS_AGENCY")[0]
     self.assertEquals(epa.attrib["name"],
                       "Environmental Protection Agency")
     self.assertEquals(epa.attrib["raw-name"],
                       "ENVIRONMENTAL PROTECTION AGENCY")
     self.assertEquals(epa.attrib["agency-id"], "145")
コード例 #6
0
    def test_as_dict(self):
        with XMLBuilder("ROOT") as ctx:
            ctx.PRTPAGE(P=44)
            ctx.AGENCY('Awesome Admin')
            ctx.SUBJECT('This is the title')

        notice = notice_xml.NoticeXML(ctx.xml)
        notice.cfr_refs = [
            notice_xml.TitlePartsRef(title=11, parts=[234, 456])
        ]
        notice.version_id = 'v1v1v1'
        notice.fr_volume = 33
        notice.fr_html_url = 'http://example.com'
        notice.published = date(2002, 2, 2)
        notice.comments_close_on = date(2003, 3, 3)
        notice.effective = date(2004, 4, 4)
        notice.rins = ['r1111', 'r2222']
        notice.docket_ids = ['d1111', 'd2222']
        notice.comment_doc_id = 'comment-docket'
        notice.primary_docket = 'd2222'
        notice.supporting_documents = [RegsGovDoc('some-id', 'A support doc')]

        self.assertEqual(
            notice.as_dict(), {
                'amendments': [],
                'comments_close':
                '2003-03-03',
                'comment_doc_id':
                'comment-docket',
                'cfr_parts': ['234', '456'],
                'cfr_title':
                11,
                'dockets': ['d1111', 'd2222'],
                'document_number':
                'v1v1v1',
                'effective_on':
                '2004-04-04',
                'fr_citation':
                '33 FR 43',
                'fr_url':
                'http://example.com',
                'fr_volume':
                33,
                'meta': {
                    'start_page': 43
                },
                'primary_agency':
                'Awesome Admin',
                'primary_docket':
                'd2222',
                'publication_date':
                '2002-02-02',
                'regulation_id_numbers': ['r1111', 'r2222'],
                'supporting_documents': [{
                    'regs_id': 'some-id',
                    'title': 'A support doc'
                }],
                'title':
                'This is the title'
            })
コード例 #7
0
def test_set_agencies_simple():
    """ Test that we can properly derive agency info from the metadata or the
    XML itself, and that it's added to the XML.  """
    agencies_info = [{
        'name':
        'Environmental Protection Agency',
        'parent_id':
        None,
        'raw_name':
        'ENVIRONMENTAL PROTECTION AGENCY',
        'url': ('https://www.federalregister.gov/agencies/'
                'environmental-protection-agency'),
        'json_url':
        'https://www.federalregister.gov/api/v1/agencies/145.json',
        'id':
        145
    }]
    with XMLBuilder("ROOT") as ctx:
        with ctx.DATES():
            ctx.P("Effective on May 4, 2004")
    xml = notice_xml.NoticeXML(ctx.xml)
    xml.set_agencies(agencies=agencies_info)
    assert len(xml.xpath("//EREGS_AGENCIES")) == 1
    eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
    assert len(eregs_agencies.xpath("//EREGS_AGENCY")) == 1
    epa = eregs_agencies.xpath("//EREGS_AGENCY")[0]
    assert epa.attrib["name"] == "Environmental Protection Agency"
    assert epa.attrib["raw-name"] == "ENVIRONMENTAL PROTECTION AGENCY"
    assert epa.attrib["agency-id"] == "145"
コード例 #8
0
 def test_set_agencies_unrelated(self):
     """
     Test that we can properly derive agency info from the metadata and add
     it to the XML if there is an agency and a non-child subagency.
     """
     agencies_info = [{
         u'name':
         u'Treasury Department',
         u'parent_id':
         None,
         u'url':
         u'%s%s' % (u'https://www.federalregister.gov/',
                    u'agencies/treasury-department'),
         u'raw_name':
         u'DEPARTMENT OF THE TREASURY',
         u'json_url':
         u'%s%s' %
         (u'https://www.federalregister.gov/', u'api/v1/agencies/497.json'),
         u'id':
         497
     }, {
         u'name':
         u'Alcohol, Tobacco, Firearms, and Explosives Bureau',
         u'parent_id':
         268,
         u'url':
         '%s%s%s' %
         (u'https://www.federalregister.gov/',
          u'agencies/alcohol-tobacco-firearms', u'-and-explosives-bureau'),
         u'raw_name':
         '%s%s' %
         (u'Bureau of Alcohol, Tobacco, Firearms', u' and Explosives'),
         u'json_url':
         '%s%s' %
         (u'https://www.federalregister.gov/', u'api/v1/agencies/19.json'),
         u'id':
         19
     }]
     with XMLBuilder("ROOT") as ctx:
         with ctx.DATES():
             ctx.P("Effective on May 4, 2004")
     xml = notice_xml.NoticeXML(ctx.xml)
     xml.set_agencies(agencies=agencies_info)
     self.assertEquals(len(xml.xpath("//EREGS_AGENCIES")), 1)
     eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
     self.assertEquals(len(eregs_agencies.xpath("//EREGS_AGENCY")), 1)
     treas = eregs_agencies.xpath("//EREGS_AGENCY")[0]
     self.assertEquals(treas.attrib["name"], "Treasury Department")
     self.assertEquals(treas.attrib["raw-name"],
                       "DEPARTMENT OF THE TREASURY")
     self.assertEquals(treas.attrib["agency-id"], "497")
     self.assertEquals(len(eregs_agencies.xpath("//EREGS_SUBAGENCY")), 1)
     atf = eregs_agencies.xpath("//EREGS_SUBAGENCY")[0]
     self.assertEquals(
         atf.attrib["name"],
         u'Alcohol, Tobacco, Firearms, and Explosives Bureau')
     self.assertEquals(
         atf.attrib["raw-name"],
         u"Bureau of Alcohol, Tobacco, Firearms and Explosives")
     self.assertEquals(atf.attrib["agency-id"], "19")
コード例 #9
0
def test_set_effective_date_create():
    """The DATES tag should get created if not present in the XML"""
    xml = _dummy_notice()

    xml.effective = '2005-05-05'
    assert xml.effective == date(2005, 5, 5)
    xml = notice_xml.NoticeXML(xml.xml)
    assert xml.effective == date(2005, 5, 5)
コード例 #10
0
    def test_set_effective_date_create(self):
        """The DATES tag should get created if not present in the XML"""
        xml = self._dummy_notice()

        xml.effective = '2005-05-05'
        self.assertEqual(xml.effective, date(2005, 5, 5))
        xml = notice_xml.NoticeXML(xml.xml)
        self.assertEqual(xml.effective, date(2005, 5, 5))
コード例 #11
0
 def test_set_agencies_singlesub(self):
     """
     Test that we can properly derive agency info from the metadata and add
     it to the XML if there is a subagency.
     """
     agencies_info = [{
         u'name':
         u'Justice Department',
         u'parent_id':
         None,
         u'url':
         u'%s%s' % (u'https://www.federalregister.gov/',
                    u'agencies/justice-department'),
         u'raw_name':
         u'DEPARTMENT OF JUSTICE',
         u'json_url':
         u'%s%s' %
         (u'https://www.federalregister.gov/', u'api/v1/agencies/268.json'),
         u'id':
         268
     }, {
         u'name':
         u'Alcohol, Tobacco, Firearms, and Explosives Bureau',
         u'parent_id':
         268,
         u'url':
         '%s%s%s' %
         (u'https://www.federalregister.gov/',
          u'agencies/alcohol-tobacco-firearms', u'-and-explosives-bureau'),
         u'raw_name':
         '%s%s' %
         (u'Bureau of Alcohol, Tobacco, Firearms', u' and Explosives'),
         u'json_url':
         '%s%s' %
         (u'https://www.federalregister.gov/', u'api/v1/agencies/19.json'),
         u'id':
         19
     }]
     with XMLBuilder("ROOT") as ctx:
         with ctx.DATES():
             ctx.P("Effective on May 4, 2004")
     xml = notice_xml.NoticeXML(ctx.xml)
     xml.set_agencies(agencies=agencies_info)
     self.assertEquals(len(xml.xpath("//EREGS_AGENCIES")), 1)
     eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
     self.assertEquals(len(eregs_agencies.xpath("//EREGS_AGENCY")), 1)
     doj = eregs_agencies.xpath("//EREGS_AGENCY")[0]
     self.assertEquals(doj.attrib["name"], "Justice Department")
     self.assertEquals(doj.attrib["raw-name"], "DEPARTMENT OF JUSTICE")
     self.assertEquals(doj.attrib["agency-id"], "268")
     self.assertEquals(len(doj.xpath("//EREGS_SUBAGENCY")), 1)
     atf = doj.xpath("//EREGS_SUBAGENCY")[0]
     self.assertEquals(atf.attrib["name"],
                       "Alcohol, Tobacco, Firearms, and Explosives Bureau")
     self.assertEquals(
         atf.attrib["raw-name"],
         "Bureau of Alcohol, Tobacco, Firearms and Explosives")
     self.assertEquals(atf.attrib["agency-id"], "19")
コード例 #12
0
def test_delays_empty_p():
    """Delaying text may have an empty P tag"""
    with XMLBuilder("ROOT") as ctx:
        with ctx.EFFDATE():
            ctx.P()
            ctx.P("The effective date of 11 FR 100 has been delayed until "
                  "April 1, 2010.")
    xml = notice_xml.NoticeXML(ctx.xml)

    assert xml.delays() == [FRDelay(11, 100, date(2010, 4, 1))]
コード例 #13
0
def test_docket_ids(dis, expected, depdoc):
    if not depdoc:
        xml = _dummy_notice()
    else:
        with XMLBuilder("ROOT") as root:
            root.DEPDOC(depdoc)
        xml = notice_xml.NoticeXML(root.xml)

    dis = dis or xml.derive_docket_ids()
    xml.docket_ids = dis
    assert xml.docket_ids == expected
コード例 #14
0
    def test_derive_effective_date(self):
        """Effective date can be derived from the dates strings. When it is
        derived, it should also be set on the notice xml"""
        with XMLBuilder("ROOT") as ctx:
            with ctx.DATES():
                ctx.P("Effective on May 4, 2004")
        xml = notice_xml.NoticeXML(ctx.xml)

        xml.effective = '2002-02-02'
        self.assertEqual(xml.derive_effective_date(), date(2004, 5, 4))
        self.assertEqual(xml.effective, date(2004, 5, 4))
コード例 #15
0
def test_rins(rins, expected, xml_rins):
    if not xml_rins:
        xml = _dummy_notice()
    else:
        with XMLBuilder("ROOT") as ctx:
            for xml_rin in xml_rins:
                ctx.RIN(xml_rin)
        xml = notice_xml.NoticeXML(ctx.xml)

    rins = rins or xml.derive_rins()
    xml.rins = rins
    assert xml.rins == expected
コード例 #16
0
def test_delays():
    """The XML should be search for any delaying text"""
    with XMLBuilder("ROOT") as ctx:
        with ctx.EFFDATE():
            ctx.P("The effective date of 11 FR 100 has been delayed until "
                  "April 1, 2010. The effective date of 11 FR 200 has also "
                  "been delayed until October 10, 2010")
    xml = notice_xml.NoticeXML(ctx.xml)

    assert xml.delays() == [
        FRDelay(11, 100, date(2010, 4, 1)),
        FRDelay(11, 200, date(2010, 10, 10))
    ]
コード例 #17
0
    def test_set_meta_data(self):
        """Several pieces of meta data should be set within the XML. We test
        that the NoticeXML wrapper can retrieve them and that, if we re-read
        the XML, they can still be pulled out"""
        with XMLBuilder("ROOT") as ctx:
            with ctx.DATES():
                ctx.P("Some content")
            ctx.PRTPAGE(P="455")
        xml = notice_xml.NoticeXML(ctx.xml)

        xml.effective = '2005-05-05'
        xml.published = '2004-04-04'
        xml.fr_volume = 22

        self.assertEqual(xml.effective, date(2005, 5, 5))
        self.assertEqual(xml.published, date(2004, 4, 4))
        self.assertEqual(xml.fr_volume, 22)

        xml = notice_xml.NoticeXML(xml.xml_str())
        self.assertEqual(xml.effective, date(2005, 5, 5))
        self.assertEqual(xml.published, date(2004, 4, 4))
        self.assertEqual(xml.fr_volume, 22)
コード例 #18
0
def test_derive_effective_date():
    """Effective date can be derived from the dates strings. When it is
    derived, it should also be set on the notice xml"""
    with XMLBuilder("ROOT") as ctx:
        with ctx.DATES():
            ctx.P("Effective on May 4, 2004")
    xml = notice_xml.NoticeXML(ctx.xml)

    xml.effective = '2002-02-02'
    assert xml.derive_effective_date() == date(2004, 5, 4)
    # does _not_ set that date
    assert xml.effective == date(2002, 2, 2)
    xml.effective = xml.derive_effective_date()
    assert xml.effective == date(2004, 5, 4)
コード例 #19
0
def test_set_agencies_singlesub():
    """ Test that we can properly derive agency info from the metadata and add
    it to the XML if there is a subagency.  """
    agencies_info = [{
        'name':
        'Justice Department',
        'parent_id':
        None,
        'url': ('https://www.federalregister.gov/agencies/'
                'justice-department'),
        'raw_name':
        'DEPARTMENT OF JUSTICE',
        'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                     '268.json'),
        'id':
        268
    }, {
        'name':
        'Alcohol, Tobacco, Firearms, and Explosives Bureau',
        'parent_id':
        268,
        'url': ('https://www.federalregister.gov/agencies/'
                'alcohol-tobacco-firearms-and-explosives-bureau'),
        'raw_name': ('Bureau of Alcohol, Tobacco, Firearms and '
                     'Explosives'),
        'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                     '19.json'),
        'id':
        19
    }]
    with XMLBuilder("ROOT") as ctx:
        with ctx.DATES():
            ctx.P("Effective on May 4, 2004")
    xml = notice_xml.NoticeXML(ctx.xml)
    xml.set_agencies(agencies=agencies_info)
    assert len(xml.xpath("//EREGS_AGENCIES")) == 1
    eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
    assert len(eregs_agencies.xpath("//EREGS_AGENCY")) == 1
    doj = eregs_agencies.xpath("//EREGS_AGENCY")[0]
    assert doj.attrib["name"] == "Justice Department"
    assert doj.attrib["raw-name"] == "DEPARTMENT OF JUSTICE"
    assert doj.attrib["agency-id"] == "268"
    assert len(doj.xpath("//EREGS_SUBAGENCY")) == 1
    atf = doj.xpath("//EREGS_SUBAGENCY")[0]
    assert atf.attrib["name"] == ("Alcohol, Tobacco, Firearms, and "
                                  "Explosives Bureau")
    assert atf.attrib["raw-name"] == ("Bureau of Alcohol, Tobacco, Firearms "
                                      "and Explosives")
    assert atf.attrib["agency-id"] == "19"
コード例 #20
0
def test_set_agencies_unrelated():
    """ Test that we can properly derive agency info from the metadata and add
    it to the XML if there is an agency and a non-child subagency.  """
    agencies_info = [{
        'name':
        'Treasury Department',
        'parent_id':
        None,
        'url': ('https://www.federalregister.gov/agencies/'
                'treasury-department'),
        'raw_name':
        'DEPARTMENT OF THE TREASURY',
        'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                     '497.json'),
        'id':
        497
    }, {
        'name':
        'Alcohol, Tobacco, Firearms, and Explosives Bureau',
        'parent_id':
        268,
        'url': ('https://www.federalregister.gov/agencies/'
                'alcohol-tobacco-firearms-and-explosives-bureau'),
        'raw_name': ('Bureau of Alcohol, Tobacco, Firearms and '
                     'Explosives'),
        'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                     '19.json'),
        'id':
        19
    }]
    with XMLBuilder("ROOT") as ctx:
        with ctx.DATES():
            ctx.P("Effective on May 4, 2004")
    xml = notice_xml.NoticeXML(ctx.xml)
    xml.set_agencies(agencies=agencies_info)
    assert len(xml.xpath("//EREGS_AGENCIES")) == 1
    eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
    assert len(eregs_agencies.xpath("//EREGS_AGENCY")) == 1
    treas = eregs_agencies.xpath("//EREGS_AGENCY")[0]
    assert treas.attrib["name"] == "Treasury Department"
    assert treas.attrib["raw-name"] == "DEPARTMENT OF THE TREASURY"
    assert treas.attrib["agency-id"] == "497"
    assert len(eregs_agencies.xpath("//EREGS_SUBAGENCY")) == 1
    atf = eregs_agencies.xpath("//EREGS_SUBAGENCY")[0]
    assert atf.attrib["name"] == ('Alcohol, Tobacco, Firearms, and '
                                  'Explosives Bureau')
    assert atf.attrib["raw-name"] == ("Bureau of Alcohol, Tobacco, Firearms "
                                      "and Explosives")
    assert atf.attrib["agency-id"] == "19"
コード例 #21
0
def test_set_meta_data():
    """Several pieces of meta data should be set within the XML. We test that
    the NoticeXML wrapper can retrieve them and that, if we re-read the XML,
    they can still be pulled out"""
    xml = _dummy_notice()

    xml.effective = '2005-05-05'
    xml.published = '2004-04-04'
    xml.fr_volume = 22

    assert xml.effective == date(2005, 5, 5)
    assert xml.published == date(2004, 4, 4)
    assert xml.fr_volume == 22

    xml = notice_xml.NoticeXML(xml.xml)
    assert xml.effective == date(2005, 5, 5)
    assert xml.published == date(2004, 4, 4)
    assert xml.fr_volume == 22
コード例 #22
0
 def test_derive_agencies_generations(self):
     """
     Test that we can properly derive agency info from the metadata and add
     it to the XML if we have nested parent-child relationships.
     """
     agencies_info = [
         {
             u'name':
             u'ATF subagency',
             u'parent_id':
             19,
             u'url':
             u'%s%s' % (u'https://www.federalregister.gov/',
                        u'agencies/atf-subagency'),
             u'raw_name':
             u'SUBAGENCY OF ATF',
             u'json_url':
             u'%s%s' % (u'https://www.federalregister.gov/',
                        u'api/v1/agencies/100023.json'),
             u'id':
             100023
         },
         {
             u'name':
             u'Alcohol, Tobacco, Firearms, and Explosives Bureau',
             u'parent_id':
             268,
             u'url':
             '%s%s%s' % (u'https://www.federalregister.gov/',
                         u'agencies/alcohol-tobacco-firearms',
                         u'-and-explosives-bureau'),
             u'raw_name':
             '%s%s' %
             (u'Bureau of Alcohol, Tobacco, Firearms', u' and Explosives'),
             u'json_url':
             '%s%s' % (u'https://www.federalregister.gov/',
                       u'api/v1/agencies/19.json'),
             u'id':
             19
         },
         {
             u'name':
             u'Justice Department',
             u'parent_id':
             None,
             u'url':
             u'%s%s' % (u'https://www.federalregister.gov/',
                        u'agencies/justice-department'),
             u'raw_name':
             u'DEPARTMENT OF JUSTICE',
             u'json_url':
             u'%s%s' % (u'https://www.federalregister.gov/',
                        u'api/v1/agencies/268.json'),
             u'id':
             268
         },
         {
             u'name':
             u'ATF subsubagency',
             u'parent_id':
             100023,
             u'url':
             u'%s%s' % (u'https://www.federalregister.gov/',
                        u'agencies/atf-subsubagency'),
             u'raw_name':
             u'SUBSUBAGENCY OF ATF',
             u'json_url':
             u'%s%s' % (u'https://www.federalregister.gov/',
                        u'api/v1/agencies/100072.json'),
             u'id':
             100072
         },
     ]
     with XMLBuilder("ROOT") as ctx:
         with ctx.DATES():
             ctx.P("Effective on May 4, 2004")
     xml = notice_xml.NoticeXML(ctx.xml)
     xml.derive_agencies(agencies=agencies_info)
     self.assertEquals(len(xml.xpath("//EREGS_AGENCIES")), 1)
     eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
     self.assertEquals(len(eregs_agencies.xpath("//EREGS_AGENCY")), 1)
     doj = eregs_agencies.xpath("//EREGS_AGENCY")[0]
     self.assertEquals(doj.attrib["name"], "Justice Department")
     self.assertEquals(doj.attrib["raw-name"], "DEPARTMENT OF JUSTICE")
     self.assertEquals(doj.attrib["agency-id"], "268")
     self.assertEquals(len(doj.xpath("//EREGS_SUBAGENCY")), 3)
     self.assertEquals(len(doj.xpath("EREGS_SUBAGENCY")), 1)
     atf = doj.xpath("//EREGS_SUBAGENCY")[0]
     self.assertEquals(
         atf.attrib["name"],
         u'Alcohol, Tobacco, Firearms, and Explosives Bureau')
     self.assertEquals(
         atf.attrib["raw-name"],
         "Bureau of Alcohol, Tobacco, Firearms and Explosives")
     self.assertEquals(atf.attrib["agency-id"], "19")
     self.assertEquals(len(atf.xpath("EREGS_SUBAGENCY")), 1)
     subatf = atf.xpath("EREGS_SUBAGENCY")[0]
     self.assertEquals(subatf.attrib["name"], u'ATF subagency')
     self.assertEquals(subatf.attrib["raw-name"], u"SUBAGENCY OF ATF")
     self.assertEquals(subatf.attrib["agency-id"], u"100023")
     subsubatf = subatf.xpath("EREGS_SUBAGENCY")[0]
     self.assertEquals(subsubatf.attrib["name"], u'ATF subsubagency')
     self.assertEquals(subsubatf.attrib["raw-name"], u"SUBSUBAGENCY OF ATF")
     self.assertEquals(subsubatf.attrib["agency-id"], u"100072")
コード例 #23
0
def _dummy_notice():
    with XMLBuilder("ROOT") as ctx:
        with ctx.DATES():
            ctx.P("Some content")
        ctx.PRTPAGE(P="455")
    return notice_xml.NoticeXML(ctx.xml)
コード例 #24
0
def test_set_agencies_generations():
    """ Test that we can properly derive agency info from the metadata and add
    it to the XML if we have nested parent-child relationships.  """
    agencies_info = [
        {
            'name':
            'ATF subagency',
            'parent_id':
            19,
            'url':
            'https://www.federalregister.gov/agencies/atf-subagency',
            'raw_name':
            'SUBAGENCY OF ATF',
            'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                         '100023.json'),
            'id':
            100023
        },
        {
            'name':
            'Alcohol, Tobacco, Firearms, and Explosives Bureau',
            'parent_id':
            268,
            'url': ('https://www.federalregister.gov/agencies/'
                    'alcohol-tobacco-firearms-and-explosives-bureau'),
            'raw_name':
            'Bureau of Alcohol, Tobacco, Firearms and Explosives',
            'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                         '19.json'),
            'id':
            19
        },
        {
            'name':
            'Justice Department',
            'parent_id':
            None,
            'url': ('https://www.federalregister.gov/agencies/'
                    'justice-department'),
            'raw_name':
            'DEPARTMENT OF JUSTICE',
            'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                         '268.json'),
            'id':
            268
        },
        {
            'name':
            'ATF subsubagency',
            'parent_id':
            100023,
            'url':
            'https://www.federalregister.gov/agencies/atf-subsubagency',
            'raw_name':
            'SUBSUBAGENCY OF ATF',
            'json_url': ('https://www.federalregister.gov/api/v1/agencies/'
                         '100072.json'),
            'id':
            100072
        },
    ]
    with XMLBuilder("ROOT") as ctx:
        with ctx.DATES():
            ctx.P("Effective on May 4, 2004")
    xml = notice_xml.NoticeXML(ctx.xml)
    xml.set_agencies(agencies=agencies_info)
    assert len(xml.xpath("//EREGS_AGENCIES")) == 1
    eregs_agencies = xml.xpath("//EREGS_AGENCIES")[0]
    assert len(eregs_agencies.xpath("//EREGS_AGENCY")) == 1
    doj = eregs_agencies.xpath("//EREGS_AGENCY")[0]
    assert doj.attrib["name"] == "Justice Department"
    assert doj.attrib["raw-name"] == "DEPARTMENT OF JUSTICE"
    assert doj.attrib["agency-id"] == "268"
    assert len(doj.xpath("//EREGS_SUBAGENCY")) == 3
    assert len(doj.xpath("EREGS_SUBAGENCY")) == 1
    atf = doj.xpath("//EREGS_SUBAGENCY")[0]
    assert atf.attrib["name"] == ('Alcohol, Tobacco, Firearms, and '
                                  'Explosives Bureau')
    assert atf.attrib["raw-name"] == ("Bureau of Alcohol, Tobacco, "
                                      "Firearms and Explosives")
    assert atf.attrib["agency-id"] == "19"
    assert len(atf.xpath("EREGS_SUBAGENCY")) == 1
    subatf = atf.xpath("EREGS_SUBAGENCY")[0]
    assert subatf.attrib["name"] == 'ATF subagency'
    assert subatf.attrib["raw-name"] == "SUBAGENCY OF ATF"
    assert subatf.attrib["agency-id"] == "100023"
    subsubatf = subatf.xpath("EREGS_SUBAGENCY")[0]
    assert subsubatf.attrib["name"] == 'ATF subsubagency'
    assert subsubatf.attrib["raw-name"] == "SUBSUBAGENCY OF ATF"
    assert subsubatf.attrib["agency-id"] == "100072"