def test_create_subpart_amendment():
    """We expect the sections to include a parent_label, but not the
    paragraphs"""
    subpart = Node(
        label=['111', 'Subpart', 'C'], node_type=Node.SUBPART, children=[
            Node(label=['111', '22'],
                 children=[Node(label=['111', '22', 'a']),
                           Node(label=['111', '22', 'b'])]),
            Node(label=['111', '23'])
        ])
    results = changes.create_subpart_amendment(subpart)
    results = list(sorted(results, key=lambda r: r.label_id))

    def empty_node(label, node_type='regtext'):
        return dict(text='', tagged_text='', title=None, node_type=node_type,
                    child_labels=[], label=label)

    assert results == [
        changes.Change('111-22', dict(parent_label=['111', 'Subpart', 'C'],
                                      action='POST',
                                      node=empty_node(['111', '22']))),
        changes.Change('111-22-a', dict(action='POST',
                                        node=empty_node(['111', '22', 'a']))),
        changes.Change('111-22-b', dict(action='POST',
                                        node=empty_node(['111', '22', 'b']))),
        changes.Change('111-23', dict(parent_label=['111', 'Subpart', 'C'],
                                      action='POST',
                                      node=empty_node(['111', '23']))),
        changes.Change(
            '111-Subpart-C',
            dict(action='POST',
                 node=empty_node(['111', 'Subpart', 'C'], 'subpart'))),
    ]
Пример #2
0
def process_new_subpart(notice, subpart_added, par):
    """ A new subpart has been added, create the notice changes. """
    subpart_changes = {}
    subpart_xml = find_subpart(par)
    subpart = reg_text.build_subpart(notice['cfr_part'], subpart_xml)

    for change in changes.create_subpart_amendment(subpart):
        subpart_changes.update(change)
    return subpart_changes
Пример #3
0
def process_new_subpart(notice, amd_label, par):
    """ A new subpart has been added, create the notice changes. """
    subpart_changes = {}
    subpart_xml = find_subpart(par)
    subpart = reg_text.build_subpart(amd_label.label[0], subpart_xml)

    for change in changes.create_subpart_amendment(subpart):
        subpart_changes.update(change)
    return subpart_changes
def fetch_amendments(notice_xml):
    """Process changes to the regulation that are expressed in the notice."""
    notice_changes = changes.NoticeChanges()

    if notice_xml.xpath('.//AMDPAR[not(EREGS_INSTRUCTIONS)]'):
        logger.warning(
            'No <EREGS_INSTRUCTIONS>. Was this notice preprocessed?')

    cache = ContentCache()
    authority_by_xml = {}
    for instruction_xml in notice_xml.xpath('.//EREGS_INSTRUCTIONS/*'):
        amendment = amendment_from_xml(instruction_xml)
        content = cache.content_of_change(instruction_xml)
        if instruction_xml.tag == 'MOVE_INTO_SUBPART':
            subpart_changes = process_designate_subpart(amendment)
            if subpart_changes:
                notice_changes.add_changes(amendment.amdpar_xml,
                                           subpart_changes)
        elif instruction_xml.tag == 'AUTHORITY':
            authority_by_xml[amendment.amdpar_xml] = instruction_xml.text
        elif changes.new_subpart_added(amendment):
            subpart_changes = {}
            for change in changes.create_subpart_amendment(content.struct):
                subpart_changes.update(change)
            notice_changes.add_changes(amendment.amdpar_xml, subpart_changes)
        elif content:
            content.amends.append(amendment)
        else:
            create_xmlless_change(amendment, notice_changes)

    for content in cache.by_xml.values():
        create_xml_changes(content.amends, content.struct, notice_changes)

    amendments = []
    for amdpar_xml in notice_xml.xpath('.//AMDPAR'):
        amendment = {"instruction": amdpar_xml.text}
        # There'll be at most one
        for inst_xml in amdpar_xml.xpath('./EREGS_INSTRUCTIONS'):
            context = inst_xml.get('final_context', '')
            amendment['cfr_part'] = context.split('-')[0]
        relevant_changes = notice_changes.changes_by_xml[amdpar_xml]
        if relevant_changes:
            amendment['changes'] = list(relevant_changes.items())
        if amdpar_xml in authority_by_xml:
            amendment['authority'] = authority_by_xml[amdpar_xml]

        amendments.append(amendment)

    return amendments