def test_listing(self): Document(id='ver1-a-b', doc_type='cfr', version='ver1', label_string='a-b', text='textex', node_type='ty').save() Document(id='aaa-a-b', doc_type='cfr', version='aaa', label_string='a-b', text='textex', node_type='ty').save() Document(id='333-a-b', doc_type='cfr', version='333', label_string='a-b', text='textex', node_type='ty').save() Document(id='four-a-b', doc_type='cfr', version='four', label_string='a-b', text='textex', node_type='ty').save() results = self.dmr.listing('cfr', 'a-b') self.assertEqual([('333', 'a-b'), ('aaa', 'a-b'), ('four', 'a-b'), ('ver1', 'a-b')], results) Document(id='ver1-1111', doc_type='cfr', version='ver1', label_string='1111', text='aaaa', node_type='ty', root=True).save() Document(id='ver2-1111', doc_type='cfr', version='ver2', label_string='1111', text='bbbb', node_type='ty', root=True).save() Document(id='ver3-1111', doc_type='cfr', version='ver3', label_string='1111', text='cccc', node_type='ty', root=False).save() results = self.dmr.listing('cfr') self.assertEqual([('ver1', '1111'), ('ver2', '1111')], results)
def test_get_preamble(self): Document(doc_type='preamble', version='verver', label_string='a-b', text='ttt', node_type='tyty').save() self.assertEqual( { 'text': 'ttt', 'label': ['a', 'b'], 'lft': 1, 'children': [], 'node_type': 'tyty' }, self.dmr.get('preamble', 'a-b', 'verver'), )
def _transform(self, reg, doc_type, version=None): """Create the Django object""" return Document( id=build_id(reg, version), doc_type=doc_type, version=version, parent_id=(build_id(reg['parent'], version) if reg.get('parent') else None), tree_id=reg['tree_id'], level=reg['level'], lft=reg['left'], rght=reg['right'], label_string='-'.join(reg['label']), text=reg['text'], title=reg.get('title', ''), node_type=reg['node_type'], root=(len(reg['label']) == 1), )