Skip to content
Snippets Groups Projects
Commit c55c4175 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Merge branch 'metadata-dates' into 'master'

writting metadatas to db during git import

See merge request !239
parents 43be1ff4 c0444670
No related branches found
No related tags found
1 merge request!239writting metadatas to db during git import
......@@ -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