def test_create_xmlless_changes(self): labels_amended = [Amendment('DELETE', '200-2-a'), Amendment('MOVE', '200-2-b', '200-2-c')] notice_changes = changes.NoticeChanges() build.create_xmlless_changes(labels_amended, notice_changes) delete = notice_changes.changes['200-2-a'][0] move = notice_changes.changes['200-2-b'][0] self.assertEqual({'action': 'DELETE'}, delete) self.assertEqual({'action': 'MOVE', 'destination': ['200', '2', 'c']}, move)
def test_parse_appendix_changes(self, whole): amends = [ Amendment('POST', '111-Appendix:A'), Amendment('POST', '111-Appendix:A'), Amendment('PUT', '111-Appendix:B-12'), Amendment('PUT', '111-Appendix:D'), Amendment('PUT', '111-Appendix:E-12-b') ] build_appendix.parse_appendix_changes(amends, '1234', 'XML') self.assertEqual(3, whole.call_count)
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_create_xml_changes_child_stars(self): labels_amended = [Amendment('PUT', '200-2-a')] xml = etree.fromstring("<ROOT><P>(a) Content</P><STARS /></ROOT>") n2a = Node('(a) Content', label=['200', '2', 'a'], source_xml=xml.xpath('//P')[0]) n2b = Node('(b) Content', label=['200', '2', 'b']) n2 = Node('n2', label=['200', '2'], children=[n2a, n2b]) root = Node('root', label=['200'], children=[n2]) notice_changes = changes.NoticeChanges() build.create_xml_changes(labels_amended, root, notice_changes) self.assertTrue('200-2-a' in notice_changes.changes) self.assertTrue(1, len(notice_changes.changes['200-2-a'])) change = notice_changes.changes['200-2-a'][0] self.assertEqual('PUT', change['action']) self.assertFalse('field' in change) n2a.text = n2a.text + ":" n2a.source_xml.text = n2a.source_xml.text + ":" notice_changes = changes.NoticeChanges() build.create_xml_changes(labels_amended, root, notice_changes) self.assertTrue('200-2-a' in notice_changes.changes) self.assertTrue(1, len(notice_changes.changes['200-2-a'])) change = notice_changes.changes['200-2-a'][0] self.assertEqual('PUT', change['action']) self.assertEqual('[text]', change.get('field'))
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_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_write_encoding(self): writer = FSWriteContent("replace/it") writer.write(Node("Content")) wrote = json.loads(open(settings.OUTPUT_DIR + '/replace/it').read()) self.assertEqual(wrote['text'], 'Content') writer.write(Amendment("action", "label")) wrote = json.loads(open(settings.OUTPUT_DIR + '/replace/it').read()) self.assertEqual(wrote, ['action', ['label']]) writer.write(Amendment("action", "label", 'destination')) wrote = json.loads(open(settings.OUTPUT_DIR + '/replace/it').read()) self.assertEqual(wrote, ['action', ['label'], 'destination']) writer.write(DesignateAmendment("action", ["label"], 'destination')) wrote = json.loads(open(settings.OUTPUT_DIR + '/replace/it').read()) self.assertEqual(wrote, ['action', [['label']], 'destination'])
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_create_xml_changes_reserve(self): labels_amended = [Amendment('RESERVE', '200-2-a')] n2a = Node('[Reserved]', label=['200', '2', 'a']) n2 = Node('n2', label=['200', '2'], children=[n2a]) root = Node('root', label=['200'], children=[n2]) notice_changes = changes.NoticeChanges() build.create_xml_changes(labels_amended, root, notice_changes) reserve = notice_changes.changes['200-2-a'][0] self.assertEqual(reserve['action'], 'RESERVE') self.assertEqual(reserve['node']['text'], u'[Reserved]')
def test_process_new_subpart(self): xml = self.new_subpart_xml() notice_xml = etree.fromstring(xml) par = notice_xml.xpath('//AMDPAR')[1] amended_label = Amendment('POST', '105-Subpart:B') notice = {'cfr_parts': ['105']} subpart_changes = build.process_new_subpart(notice, amended_label, par) new_nodes_added = ['105-Subpart-B', '105-30', '105-30-def0', '105-30-a'] self.assertEqual(new_nodes_added, subpart_changes.keys()) for l, n in subpart_changes.items(): self.assertEqual(n['action'], 'POST') self.assertEqual( subpart_changes['105-Subpart-B']['node']['node_type'], 'subpart')
def test_create_xml_changes_stars_hole(self): labels_amended = [Amendment('PUT', '200-2-a')] n2a1 = Node('(1) * * *', label=['200', '2', 'a', '1']) n2a2 = Node('(2) a2a2a2', label=['200', '2', 'a', '2']) n2a = Node('(a) aaa', label=['200', '2', 'a'], children=[n2a1, n2a2]) n2 = Node('n2', label=['200', '2'], children=[n2a]) root = Node('root', label=['200'], children=[n2]) notice_changes = changes.NoticeChanges() build.create_xml_changes(labels_amended, root, notice_changes) for label in ('200-2-a', '200-2-a-2'): self.assertTrue(label in notice_changes.changes) self.assertEqual(1, len(notice_changes.changes[label])) change = notice_changes.changes[label][0] self.assertEqual('PUT', change['action']) self.assertFalse('field' in change) self.assertTrue('200-2-a-1' in notice_changes.changes) self.assertEqual(1, len(notice_changes.changes['200-2-a-1'])) change = notice_changes.changes['200-2-a-1'][0] self.assertEqual('KEEP', change['action']) self.assertFalse('field' in change)
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'}]})