Skip to content
Snippets Groups Projects
Commit c0444670 authored by Valentin Rigal's avatar Valentin Rigal Committed by Erwan Rouchet
Browse files

writting metadatas to db during git import

parent 43be1ff4
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ from arkindex.dataimport.config import ConfigFile, ImportType, VolumesImportForm
from arkindex.dataimport.iiif import IIIFParser
from arkindex.documents.surface import SurfaceImporter
from arkindex.documents.surface_link import CorpusSurfaceLinker
from arkindex.documents.tei import TeiParser
import os.path
import logging
......@@ -167,7 +168,11 @@ class MetadataFileType(FileType):
return config.path_match(ImportType.Metadata, path) and path.endswith('.xml')
def handle(self):
logger.warning('Metadata imports are not yet supported')
parser = TeiParser(self.full_path)
matches = parser.match_database(self.flow.dataimport.corpus)
logger.info('Found {} metadatas matching DB'.format(len(matches)))
for db_elt, tei_elt in matches:
tei_elt.save(db_elt, self.flow.dataimport.revision)
class ConfigFileType(FileType):
......
......@@ -119,3 +119,16 @@ class TestFileTypes(FixtureTestCase):
self.flow.config.path_match.return_value = False
self.assertFalse(MetadataFileType.match('path/to/some.xml', self.flow.config))
@patch('arkindex.documents.models.Act')
@patch('arkindex.documents.tei.TeiElement')
@patch('arkindex.dataimport.filetypes.TeiParser')
def test_metadata_handle(self, tei_parser_mock, tei_elt_mock, db_elt_mock):
tei_parser_mock().match_database.return_value = [(db_elt_mock(), tei_elt_mock())]
self.flow.config.path_match.return_value = True
metadatas_diff = SimpleDiff(DiffType.Modification, 'a.xml', 'b.xml')
ft = MetadataFileType(self.flow, metadatas_diff)
ft.handle()
self.assertEqual(tei_parser_mock.call_args, call('the/repo/b.xml'))
self.assertEqual(tei_parser_mock().match_database.call_args, call(self.corpus))
self.assertEqual(tei_elt_mock().save.call_count, 1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment