Esempio n. 1
0
 def test_media_type(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertIsNone(sut.media_type)
     media_type = MediaType('text/plain')
     sut.media_type = media_type
     self.assertEquals(media_type, sut.media_type)
Esempio n. 2
0
def _load_object(loader: _Loader, element: ElementTree.Element, gramps_tree_directory_path):
    handle = element.get('handle')
    entity_id = element.get('id')
    file_element = _xpath1(element, './ns:file')
    file_path = path.join(gramps_tree_directory_path, file_element.get('src'))
    file = File(entity_id, file_path)
    file.media_type = MediaType(file_element.get('mime'))
    description = file_element.get('description')
    if description:
        file.description = description
    note_handle_elements = _xpath(element, './ns:noteref')
    for note_handle_element in note_handle_elements:
        file.notes.append(loader._notes[note_handle_element.get('hlink')])
    _load_attribute_privacy(file, element, 'attribute')
    loader._files[handle] = _IntermediateFile(file, _load_citationref_as_handles(element))
Esempio n. 3
0
def _parse_object(ancestry: _IntermediateAncestry, element: Element,
                  gramps_directory_path):
    handle = _xpath1(element, './@handle')
    entity_id = str(_xpath1(element, './@id'))
    file_element = _xpath1(element, './ns:file')
    file_path = path.join(gramps_directory_path,
                          str(_xpath1(file_element, './@src')))
    file = File(entity_id, file_path)
    file.media_type = MediaType(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])
    _parse_attribute_privacy(file, element, 'attribute')
    ancestry.files[handle] = file
Esempio n. 4
0
 def test_file_should_encode_full(self):
     with NamedTemporaryFile() as f:
         note = Note('the_note', 'The Note')
         file = File('the_file', f.name)
         file.media_type = MediaType('text/plain')
         file.notes.append(note)
         Person('the_person').files.append(file)
         expected = {
             '$schema':
             '/schema.json#/definitions/file',
             'id':
             'the_file',
             'mediaType':
             'text/plain',
             'resources': [
                 '/en/person/the_person/index.json',
             ],
             'notes': [
                 '/en/note/the_note/index.json',
             ],
             'links': [
                 {
                     'url': '/en/file/the_file/index.json',
                     'relationship': 'canonical',
                     'mediaType': 'application/json',
                 },
                 {
                     'url': '/nl/file/the_file/index.json',
                     'relationship': 'alternate',
                     'locale': 'nl-NL',
                 },
                 {
                     'url': '/en/file/the_file/index.html',
                     'relationship': 'alternate',
                     'mediaType': 'text/html',
                 },
             ],
         }
         self.assert_encodes(expected, file, 'file')