@@ -1342,6 +1342,83 @@ def test_related_item_for_multilingue_document(self):
13421342 content [3 ],
13431343 intra_work_relation .attrib .get ('relationship-type' ))
13441344
1345+ def test_related_item_includes_has_preprint_relation (self ):
1346+ self ._article .data ['article' ]['v241' ] = [
1347+ {
1348+ 'i' : '10.1590/SciELOPreprints.9348' ,
1349+ 't' : 'preprint' ,
1350+ 'n' : 'doi' ,
1351+ }
1352+ ]
1353+ xmlcrossref = create_xmlcrossref_with_n_journal_article_element (
1354+ ['pt' , 'en' , 'es' ])
1355+
1356+ data = [self ._article , xmlcrossref ]
1357+ xmlcrossref = export_crossref .XMLProgramRelatedItemPipe ()
1358+ raw , xml = xmlcrossref .transform (data )
1359+
1360+ # main journal_article keeps its translations and gains the preprint
1361+ main_program = xml .findall ('.//journal_article' )[0 ].find ('program' )
1362+ relations = main_program .findall ('related_item/intra_work_relation' )
1363+ relation_types = [r .attrib .get ('relationship-type' ) for r in relations ]
1364+
1365+ self .assertIn ('hasPreprint' , relation_types )
1366+ preprint_node = next (
1367+ r for r in relations
1368+ if r .attrib .get ('relationship-type' ) == 'hasPreprint'
1369+ )
1370+ self .assertEqual ('doi' , preprint_node .attrib .get ('identifier-type' ))
1371+ self .assertEqual ('10.1590/SciELOPreprints.9348' , preprint_node .text )
1372+
1373+ # translations should not get the hasPreprint relation
1374+ for journal_article in xml .findall ('.//journal_article' )[1 :]:
1375+ translation_relations = journal_article .findall (
1376+ 'program/related_item/intra_work_relation' )
1377+ translation_types = [
1378+ r .attrib .get ('relationship-type' )
1379+ for r in translation_relations
1380+ ]
1381+ self .assertNotIn ('hasPreprint' , translation_types )
1382+
1383+ def test_related_item_without_preprint_does_not_emit_has_preprint (self ):
1384+ # ensure no v241 entries -> no hasPreprint relation is emitted
1385+ self ._article .data ['article' ].pop ('v241' , None )
1386+ xmlcrossref = create_xmlcrossref_with_n_journal_article_element (
1387+ ['pt' , 'en' , 'es' ])
1388+
1389+ data = [self ._article , xmlcrossref ]
1390+ xmlcrossref = export_crossref .XMLProgramRelatedItemPipe ()
1391+ raw , xml = xmlcrossref .transform (data )
1392+
1393+ relation_types = [
1394+ r .attrib .get ('relationship-type' )
1395+ for r in xml .findall (
1396+ './/program/related_item/intra_work_relation' )
1397+ ]
1398+ self .assertNotIn ('hasPreprint' , relation_types )
1399+
1400+ def test_related_item_ignores_non_preprint_related_articles (self ):
1401+ self ._article .data ['article' ]['v241' ] = [
1402+ {
1403+ 'i' : '10.1590/some-other.1234' ,
1404+ 't' : 'commentary' ,
1405+ 'n' : 'doi' ,
1406+ }
1407+ ]
1408+ xmlcrossref = create_xmlcrossref_with_n_journal_article_element (
1409+ ['pt' , 'en' , 'es' ])
1410+
1411+ data = [self ._article , xmlcrossref ]
1412+ xmlcrossref = export_crossref .XMLProgramRelatedItemPipe ()
1413+ raw , xml = xmlcrossref .transform (data )
1414+
1415+ relation_types = [
1416+ r .attrib .get ('relationship-type' )
1417+ for r in xml .findall (
1418+ './/program/related_item/intra_work_relation' )
1419+ ]
1420+ self .assertNotIn ('hasPreprint' , relation_types )
1421+
13451422 def test_collection_for_multilingue_document (self ):
13461423 xmlcrossref = create_xmlcrossref_with_n_journal_article_element (
13471424 ['pt' , 'en' , 'es' ], 'doi_data' )
0 commit comments