예제 #1
0
def create_xml_changes(amended_labels,
                       section,
                       notice_changes,
                       subpart_label=None):
    """For PUT/POST, match the amendments to the section nodes that got
    parsed, and actually create the notice changes. """
    def per_node(node):
        node.child_labels = [c.label_id() for c in node.children]

    struct.walk(section, per_node)

    amend_map = changes.match_labels_and_changes(amended_labels, section)

    for label, amendments in amend_map.iteritems():
        for amendment in amendments:
            if amendment['action'] in ('POST', 'PUT'):
                if (subpart_label and amendment['action'] == 'POST'
                        and len(label.split('-')) == 2):
                    amendment['extras'] = {'subpart': subpart_label}
                if 'field' in amendment:
                    nodes = changes.create_field_amendment(label, amendment)
                else:
                    nodes = changes.create_add_amendment(amendment)
                for n in nodes:
                    notice_changes.update(n)
            elif amendment['action'] == 'RESERVE':
                change = changes.create_reserve_amendment(amendment)
                notice_changes.update(change)
            elif amendment['action'] not in ('DELETE', 'MOVE'):
                logging.info('NOT HANDLED: %s' % amendment['action'])
def test_match_labels_and_changes_move():
    labels_amended = [Amendment('MOVE', '200-?-1', '200-?-2')]
    amend_map = changes.match_labels_and_changes(labels_amended, None)
    assert dict(amend_map) == {
        '200-1': [{'action': 'MOVE', 'destination': ['200', '2'],
                   'amdpar_xml': None}]
    }
예제 #3
0
def create_xml_changes(amended_labels, section, notice_changes,
                       subpart_label=None):
    """For PUT/POST, match the amendments to the section nodes that got
    parsed, and actually create the notice changes. """

    def per_node(node):
        node.child_labels = [c.label_id() for c in node.children]
    struct.walk(section, per_node)

    amend_map = changes.match_labels_and_changes(amended_labels, section)

    for label, amendments in amend_map.iteritems():
        for amendment in amendments:
            if amendment['action'] in ('POST', 'PUT'):
                if (subpart_label and amendment['action'] == 'POST'
                        and len(label.split('-')) == 2):
                    amendment['extras'] = {'subpart': subpart_label}
                if 'field' in amendment:
                    nodes = changes.create_field_amendment(label, amendment)
                else:
                    nodes = changes.create_add_amendment(amendment)
                for n in nodes:
                    notice_changes.update(n)
            elif amendment['action'] == 'RESERVE':
                change = changes.create_reserve_amendment(amendment)
                notice_changes.update(change)
            elif amendment['action'] not in ('DELETE', 'MOVE'):
                logging.info('NOT HANDLED: %s' % amendment['action'])
    def test_match_labels_and_changes_reserve(self):
        labels_amended = [Amendment("RESERVE", "200-2-a")]
        amend_map = changes.match_labels_and_changes(labels_amended, self.section_node())
        self.assertEqual(["200-2-a"], amend_map.keys())

        amendments = amend_map["200-2-a"]
        self.assertEqual(amendments[0]["action"], "RESERVE")
        self.assertEqual(amendments[0]["node"], Node("n2a", label=["200", "2", "a"]))
 def test_match_labels_and_changes_move(self):
     labels_amended = [Amendment('MOVE', '200-1', '200-2')]
     amend_map = changes.match_labels_and_changes(labels_amended, None)
     self.assertEqual(
         amend_map,
         {'200-1': [{
             'action': 'MOVE',
             'destination': ['200', '2']
         }]})
 def test_match_labels_and_changes_delete(self):
     labels_amended = [Amendment('DELETE', '200-?-1-a-i')]
     amend_map = changes.match_labels_and_changes(labels_amended, None)
     self.assertEqual(
         dict(amend_map),
         {'200-1-a-i': [{
             'action': 'DELETE',
             'amdpar_xml': None
         }]})
def test_match_labels_and_changes_reserve():
    labels_amended = [Amendment('RESERVE', '200-?-2-a')]
    amend_map = changes.match_labels_and_changes(
        labels_amended, _section_node())
    assert set(amend_map.keys()) == {'200-2-a'}

    amendments = amend_map['200-2-a']
    assert amendments[0]['action'] == 'RESERVE'
    assert amendments[0]['node'] == Node('n2a', label=['200', '2', 'a'])
    def test_match_labels_and_changes_reserve(self):
        labels_amended = [Amendment('RESERVE', '200-?-2-a')]
        amend_map = changes.match_labels_and_changes(
            labels_amended, self.section_node())
        six.assertCountEqual(self, ['200-2-a'], amend_map.keys())

        amendments = amend_map['200-2-a']
        self.assertEqual(amendments[0]['action'], 'RESERVE')
        self.assertEqual(
            amendments[0]['node'], Node('n2a', label=['200', '2', 'a']))
    def test_match_labels_and_changes_reserve(self):
        labels_amended = [Amendment('RESERVE', '200-?-2-a')]
        amend_map = changes.match_labels_and_changes(labels_amended,
                                                     self.section_node())
        six.assertCountEqual(self, ['200-2-a'], amend_map.keys())

        amendments = amend_map['200-2-a']
        self.assertEqual(amendments[0]['action'], 'RESERVE')
        self.assertEqual(amendments[0]['node'],
                         Node('n2a', label=['200', '2', 'a']))
    def test_match_labels_and_changes(self):
        labels_amended = [Amendment("POST", "200-2"), Amendment("PUT", "200-2-a")]

        amend_map = changes.match_labels_and_changes(labels_amended, self.section_node())

        self.assertEqual(2, len(amend_map.keys()))

        for label, amendments in amend_map.items():
            amend = amendments[0]
            self.assertFalse(amend["candidate"])
            self.assertTrue(amend["action"] in ["POST", "PUT"])
    def test_match_labels_and_changes_candidate(self):
        labels_amended = [Amendment("POST", "200-2"), Amendment("PUT", "200-2-a-1-i")]

        n1 = Node("n2", label=["200", "2"])
        n2 = Node("n2a", label=["200", "2", "i"])

        n1.children = [n2]
        root = Node("root", label=["200"], children=[n1])

        amend_map = changes.match_labels_and_changes(labels_amended, root)

        self.assertTrue(amend_map["200-2-a-1-i"][0]["candidate"])
        self.assertTrue(amend_map["200-2-a-1-i"][0]["node"].label_id(), "200-2-a-1-i")
    def test_match_labels_and_changes(self):
        labels_amended = [Amendment('POST', '200-?-2'),
                          Amendment('PUT', '200-?-2-a')]

        amend_map = changes.match_labels_and_changes(
            labels_amended, self.section_node())

        self.assertEqual(2, len(amend_map.keys()))

        for label, amendments in amend_map.items():
            amend = amendments[0]
            self.assertFalse(amend['candidate'])
            self.assertTrue(amend['action'] in ['POST', 'PUT'])
def test_match_labels_and_changes():
    labels_amended = [Amendment('POST', '200-?-2'),
                      Amendment('PUT', '200-?-2-a')]

    amend_map = changes.match_labels_and_changes(
        labels_amended, _section_node())

    assert len(amend_map) == 2

    for amendments in amend_map.values():
        amend = amendments[0]
        assert not amend['candidate']
        assert amend['action'] in ('POST', 'PUT')
예제 #14
0
def create_xmlless_changes(amended_labels, notice_changes):
    """Deletes, moves, and the like do not have an associated XML structure.
    Add their changes"""
    amend_map = changes.match_labels_and_changes(amended_labels, None)
    for label, amendments in amend_map.iteritems():
        for amendment in amendments:
            if amendment['action'] == 'DELETE':
                notice_changes.update({label: {'action': amendment['action']}})
            elif amendment['action'] == 'MOVE':
                change = {'action': amendment['action']}
                destination = [d for d in amendment['destination'] if d != '?']
                change['destination'] = destination
                notice_changes.update({label: change})
            elif amendment['action'] not in ('POST', 'PUT', 'RESERVE'):
                print 'NOT HANDLED: %s' % amendment['action']
예제 #15
0
def create_xmlless_changes(amended_labels, notice_changes):
    """Deletes, moves, and the like do not have an associated XML structure.
    Add their changes"""
    amend_map = changes.match_labels_and_changes(amended_labels, None)
    for label, amendments in amend_map.iteritems():
        for amendment in amendments:
            if amendment['action'] == 'DELETE':
                notice_changes.update({label: {'action': amendment['action']}})
            elif amendment['action'] == 'MOVE':
                change = {'action': amendment['action']}
                destination = [d for d in amendment['destination'] if d != '?']
                change['destination'] = destination
                notice_changes.update({label: change})
            elif amendment['action'] not in ('POST', 'PUT', 'RESERVE'):
                logging.info('NOT HANDLED: %s' % amendment['action'])
    def test_match_labels_and_changes(self):
        labels_amended = [
            Amendment('POST', '200-?-2'),
            Amendment('PUT', '200-?-2-a')
        ]

        amend_map = changes.match_labels_and_changes(labels_amended,
                                                     self.section_node())

        self.assertEqual(2, len(amend_map.keys()))

        for label, amendments in amend_map.items():
            amend = amendments[0]
            self.assertFalse(amend['candidate'])
            self.assertTrue(amend['action'] in ['POST', 'PUT'])
def test_match_labels_and_changes_candidate():
    labels_amended = [
        Amendment('POST', '200-?-2'),
        Amendment('PUT', '200-?-2-a-1-i')]

    n1 = Node('n2', label=['200', '2'])
    n2 = Node('n2a', label=['200', '2', 'i'])

    n1.children = [n2]
    root = Node('root', label=['200'], children=[n1])

    amend_map = changes.match_labels_and_changes(
        labels_amended, root)

    assert amend_map['200-2-a-1-i'][0]['candidate']
    assert amend_map['200-2-a-1-i'][0]['node'].label_id() == '200-2-a-1-i'
예제 #18
0
def create_xmlless_change(amendment, notice_changes):
    """Deletes, moves, and the like do not have an associated XML structure.
    Add their changes"""
    amend_map = changes.match_labels_and_changes([amendment], None)
    for label, amendments in amend_map.items():
        for amendment in amendments:
            if amendment['action'] == 'DELETE':
                notice_changes.add_changes(
                    amendment['amdpar_xml'],
                    {label: {'action': amendment['action']}})
            elif amendment['action'] == 'MOVE':
                change = {'action': amendment['action']}
                destination = [d for d in amendment['destination'] if d != '?']
                change['destination'] = destination
                notice_changes.add_changes(
                    amendment['amdpar_xml'], {label: change})
            else:
                logger.warning("Unknown action: %s", amendment['action'])
예제 #19
0
def create_xml_changes(amended_labels, section, notice_changes):
    """For PUT/POST, match the amendments to the section nodes that got
    parsed, and actually create the notice changes. """

    def per_node(node):
        node.child_labels = [c.label_id() for c in node.children]
    walk(section, per_node)

    amend_map = changes.match_labels_and_changes(amended_labels, section)

    for label, amendments in amend_map.items():
        for amendment in amendments:
            if amendment['action'] in ('POST', 'PUT', 'INSERT'):
                if 'field' in amendment:
                    nodes = changes.create_field_amendment(label, amendment)
                else:
                    nodes = changes.create_add_amendment(amendment)
                for n in nodes:
                    notice_changes.add_changes(amendment['amdpar_xml'], n)
            elif amendment['action'] == 'RESERVE':
                change = changes.create_reserve_amendment(amendment)
                notice_changes.add_changes(amendment['amdpar_xml'], change)
            else:
                logger.warning("Unknown action: %s", amendment['action'])
 def test_match_labels_and_changes_move(self):
     labels_amended = [Amendment('MOVE', '200-1', '200-2')]
     amend_map = changes.match_labels_and_changes(labels_amended, None)
     self.assertEqual(amend_map, {
         '200-1': [{'action': 'MOVE', 'destination': ['200', '2']}]})
 def test_match_labels_and_changes_delete(self):
     labels_amended = [Amendment('DELETE', '200-?-1-a-i')]
     amend_map = changes.match_labels_and_changes(labels_amended, None)
     self.assertEqual(dict(amend_map), {
         '200-1-a-i': [{'action': 'DELETE', 'amdpar_xml': None}]})
 def test_match_labels_and_changes_move(self):
     labels_amended = [Amendment("MOVE", "200-1", "200-2")]
     amend_map = changes.match_labels_and_changes(labels_amended, None)
     self.assertEqual(amend_map, {"200-1": [{"action": "MOVE", "destination": ["200", "2"]}]})
 def test_match_labels_and_changes_delete(self):
     labels_amended = [Amendment("DELETE", "200-1-a-i")]
     amend_map = changes.match_labels_and_changes(labels_amended, None)
     self.assertEqual(amend_map, {"200-1-a-i": [{"action": "DELETE"}]})