Ejemplo n.º 1
0
 def test_media_type(self) -> None:
     file_id = 'BETTY01'
     file_path = Path('~')
     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)
Ejemplo n.º 2
0
def _load_object(loader: _Loader, element: ElementTree.Element,
                 gramps_tree_directory_path: Path):
    file_handle = element.get('handle')
    file_id = element.get('id')
    file_element = _xpath1(element, './ns:file')
    file_path = gramps_tree_directory_path / file_element.get('src')
    file = File(file_id, file_path)
    file.media_type = MediaType(file_element.get('mime'))
    description = file_element.get('description')
    if description:
        file.description = description
    _load_attribute_privacy(file, element, 'attribute')
    loader.add_entity(FlattenedEntity(file, file_handle))
    for citation_handle in _load_handles('citationref', element):
        loader.add_association(File, file_handle, 'citations', Citation,
                               citation_handle)
    for note_handle in _load_handles('noteref', element):
        loader.add_association(File, file_handle, 'notes', Note, note_handle)
Ejemplo n.º 3
0
 async 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',
             'entities': [
                 '/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',
                 },
             ],
         }
         await self.assert_encodes(expected, file, 'file')