def _parse_object(ancestry: _IntermediateAncestry, element: Element, gramps_file_path): handle = _xpath1(element, './@handle') entity_id = str(_xpath1(element, './@id')) file_element = _xpath1(element, './ns:file') file_path = join(dirname(gramps_file_path), str(_xpath1(file_element, './@src'))) file = File(entity_id, file_path) file.type = str(_xpath1(file_element, './@mime')) description = str(_xpath1(file_element, './@description')) if description: file.description = description note_handles = _xpath(element, './ns:noteref/@hlink') for note_handle in note_handles: file.notes.append(ancestry.notes[note_handle]) ancestry.files[handle] = file
def test_file_should_encode_full(self): with NamedTemporaryFile() as f: file = File('the_file', f.name) file.type = 'text/plain' file.notes.append(Note('The Note')) Person('the_person').files.append(file) expected = { '$schema': '/schema.json#/definitions/file', 'id': 'the_file', 'type': 'text/plain', 'entities': [ '/person/the_person/index.json', ], 'notes': [ { 'text': 'The Note', }, ], } self.assert_encodes(expected, file, 'file')