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 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_create_add_amendment(self): root = self.build_tree() amendment = {'node': root, 'action': 'POST'} amendments = changes.create_add_amendment(amendment) self.assertEqual(6, len(amendments)) amends = {} for a in amendments: amends.update(a) for l in ['200-1-i', '200-1', '200-2', '200-3-a', '200-3', '200']: self.assertTrue(l in amends) for label, node in amends.items(): self.assertEqual(label, '-'.join(node['node'].label)) self.assertEqual(node['action'], 'POST')
def test_create_add_amendment(self): root = self.build_tree() amendment = {'node': root, 'action': 'POST'} amendments = changes.create_add_amendment(amendment) self.assertEqual(6, len(amendments)) amends = {} for a in amendments: amends.update(a) for l in ['200-1-i', '200-1', '200-2', '200-3-a', '200-3', '200']: self.assertTrue(l in amends) for label, node in amends.items(): self.assertEqual(label, '-'.join(node['node'].label)) self.assertEqual(node['action'], 'POST')
def test_create_add_amendment(self): root = self.build_tree() amendment = {"node": root, "action": "POST"} amendments = changes.create_add_amendment(amendment) self.assertEqual(6, len(amendments)) amends = {} for a in amendments: amends.update(a) for l in ["200-1-i", "200-1", "200-2", "200-3-a", "200-3", "200"]: self.assertTrue(l in amends) for label, node in amends.items(): self.assertEqual(label, "-".join(node["node"]["label"])) self.assertEqual(node["action"], "POST") self.assertFalse("children" in node["node"])
def test_create_add_amendment_parent_label(self): """If an amendment has an explicit parent_label, it should only be applied to the root of the tree""" root = self.build_tree() amendment = {'node': root, 'action': 'POST', 'parent_label': ['arbitrary']} amendments = changes.create_add_amendment(amendment) self.assertEqual(6, len(amendments)) amends = {} for a in amendments: amends.update(a) self.assertEqual(amends['200'].get('parent_label'), ['arbitrary']) for label, change in amends.items(): if label == '200': self.assertEqual(change['parent_label'], ['arbitrary']) else: self.assertFalse('parent_label' in change)
def test_create_add_amendment_parent_label(): """If an amendment has an explicit parent_label, it should only be applied to the root of the tree""" root = _build_tree() amendment = {'node': root, 'action': 'POST', 'parent_label': ['arbitrary']} amendments = changes.create_add_amendment(amendment) assert len(amendments) == 6 amends = {} for a in amendments: amends[a.label_id] = a.content assert amends['200'].get('parent_label') == ['arbitrary'] for label, change in amends.items(): if label == '200': assert change['parent_label'] == ['arbitrary'] else: assert 'parent_label' not in change
def test_create_add_amendment(): root = _build_tree() amendment = {'node': root, 'action': 'POST'} amendments = changes.create_add_amendment(amendment) assert len(amendments) == 6 amends = {} for a in amendments: amends[a.label_id] = a.content for l in ['200-1-i', '200-1', '200-2', '200-3-a', '200-3', '200']: assert l in amends for label, node in amends.items(): assert label == '-'.join(node['node']['label']) assert node['action'] == 'POST' assert 'children' not in node['node']
def test_create_add_amendment_parent_label(self): """If an amendment has an explicit parent_label, it should only be applied to the root of the tree""" root = self.build_tree() amendment = { 'node': root, 'action': 'POST', 'parent_label': ['arbitrary'] } amendments = changes.create_add_amendment(amendment) self.assertEqual(6, len(amendments)) amends = {} for a in amendments: amends.update(a) self.assertEqual(amends['200'].get('parent_label'), ['arbitrary']) for label, change in amends.items(): if label == '200': self.assertEqual(change['parent_label'], ['arbitrary']) else: self.assertFalse('parent_label' in change)
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'])