def test_ref_list_citation_with_no_id(self):
     """for test coverage an article with a ref_list with a citation that has no id attribute"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     citation = Citation()
     citation.article_title = "An article title"
     article.ref_list = [citation]
     c_xml = generate.build_crossref_xml([article])
     crossref_xml_string = c_xml.output_xml()
     self.assertTrue('<citation key="1">' in crossref_xml_string)
 def test_generate_no_contributors(self):
     """Test when an article has no contributors"""
     # build an article object and component, generate Crossref XML
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     # generate the crossrefXML
     c_xml = generate.build_crossref_xml([article])
     crossref_xml_string = c_xml.output_xml()
     self.assertIsNotNone(crossref_xml_string)
     # A quick test just look for a string value to test
     self.assertTrue("<contributors" not in crossref_xml_string)
 def test_set_titles(self):
     """test stripping unwanted tags from title"""
     doi = "10.7554/eLife.00666"
     article = Article(doi, self.title)
     expected_contains = (
         "<titles><title>Test article for Desulfocapsa sulfexigens</title></titles>"
     )
     # generate
     crossref_object = generate.build_crossref_xml([article])
     crossref_xml_string = crossref_object.output_xml()
     # test assertion
     self.assertTrue(expected_contains in crossref_xml_string)
 def test_set_abstract(self):
     """test stripping unwanted tags from abstract"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     article.abstract = self.abstract
     expected_contains = (
         "<jats:abstract><jats:p>An abstract. Desulfocapsa sulfexigens." +
         " Stock and Wise (1990).</jats:p></jats:abstract>")
     # generate
     crossref_object = generate.build_crossref_xml([article])
     crossref_xml_string = crossref_object.output_xml()
     # test assertion
     self.assertTrue(expected_contains in crossref_xml_string)
 def test_generate_blank_affiliation(self):
     """Test when a contributor has a blank affiliation"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     author = Contributor("author", "Surname", "Given names")
     aff = Affiliation()
     aff.text = ""
     author.set_affiliation(aff)
     # generate the crossrefXML
     c_xml = generate.build_crossref_xml([article])
     crossref_xml_string = c_xml.output_xml()
     self.assertIsNotNone(crossref_xml_string)
     # A quick test just look for a string value to test
     self.assertTrue("<affiliation>" not in crossref_xml_string)
예제 #6
0
def crossref_convert(file_path):
    if not file_path:
        return None
    config_section = 'elife'
    try:
        articles = generate.build_articles_for_crossref([file_path])
    except:
        # parsing failed somehow
        return None
    crossref_config = None
    #if config_section:
    #    crossref_config = parse_raw_config(raw_config(config_section))
    crossref_xml_object = generate.build_crossref_xml(articles, crossref_config)
    crossref_xml = crossref_xml_object.output_xml(pretty=True, indent="\t")
    return crossref_xml
 def test_article_preprint(self):
     """test for an article with preprint data"""
     doi = "10.7554/eLife.00666"
     article = Article(doi, title="Sample article")
     article.preprint = Preprint(uri="https://example.org/")
     expected_contains = (
         "<rel:program>"
         "<rel:related_item>"
         '<rel:intra_work_relation identifier-type="uri"'
         ' relationship-type="hasPreprint">https://example.org/'
         "</rel:intra_work_relation>"
         "</rel:related_item>"
         "</rel:program>")
     # generate
     crossref_object = generate.build_crossref_xml([article])
     crossref_xml_string = crossref_object.output_xml()
     # test assertion
     self.assertTrue(expected_contains in crossref_xml_string)
 def test_component_subtitle_no_face_markup(self):
     """build an article object and component, generate Crossref XML"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     component = Component()
     component.title = "A component"
     component.subtitle = (
         "A <sc>STRANGE</sc> <italic>subtitle</italic>, " +
         "and this tag is <not_allowed>!</not_allowed>")
     expected_subtitle = ("A STRANGE subtitle, and this tag is"
                          " &lt;not_allowed&gt;!&lt;/not_allowed&gt;")
     article.component_list = [component]
     # generate the crossrefXML
     c_xml = generate.build_crossref_xml([article])
     crossref_xml_string = c_xml.output_xml()
     self.assertIsNotNone(crossref_xml_string)
     # A quick test just look for the expected string to test for tags and escape characters
     self.assertTrue(expected_subtitle in crossref_xml_string)
 def test_ref_list_data_citation_with_pmid(self):
     """
     for test coverage an article with a ref_list with a
     data citation that has a pmid attribute
     """
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     citation = Citation()
     citation.data_title = "An data title"
     citation.publication_type = "data"
     citation.pmid = "pmid"
     article.ref_list = [citation]
     expected_contains = (
         "<rel:program><rel:related_item><rel:description>An data title</rel:description>"
         +
         '<rel:inter_work_relation identifier-type="pmid" relationship-type="references">'
         +
         "pmid</rel:inter_work_relation></rel:related_item></rel:program>")
     # generate
     c_xml = generate.build_crossref_xml([article])
     crossref_xml_string = c_xml.output_xml()
     # test assertion
     self.assertTrue(expected_contains in crossref_xml_string)
 def test_set_datasets(self):
     """a basic non-XML example for set_datasets"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     # dataset_1 example with a uri
     dataset_1 = Dataset()
     dataset_1.dataset_type = "datasets"
     dataset_1.uri = (
         "https://github.com/elifesciences/XML-mapping/blob/master/elife-00666.xml"
     )
     dataset_1.title = "Kitchen sink"
     # dataset_2 example with accession_id
     dataset_2 = Dataset()
     dataset_2.dataset_type = "prev_published_datasets"
     dataset_2.accession_id = "EGAS00001000968"
     # dataset_3 example with doi
     dataset_3 = Dataset()
     dataset_3.dataset_type = "prev_published_datasets"
     dataset_3.doi = "10.5061/dryad.cv323"
     # dataset_4 example with no dataset_type will be treated as a generated dataset by default
     dataset_4 = Dataset()
     dataset_4.uri = "http://cghub.ucsc.edu"
     # dataset_5 example with an unsupported dataset_type
     dataset_5 = Dataset()
     dataset_5.dataset_type = "foo"
     dataset_5.uri = "https://elifesciences.org"
     # dataset_6 example with no identifier, not get added to the XML output, for test coverage
     dataset_6 = Dataset()
     dataset_6.dataset_type = "prev_published_datasets"
     # add the datasets to the article object
     article.add_dataset(dataset_1)
     article.add_dataset(dataset_2)
     article.add_dataset(dataset_3)
     article.add_dataset(dataset_4)
     article.add_dataset(dataset_5)
     article.add_dataset(dataset_6)
     # expected values
     expected_xml_snippet_1 = (
         "<rel:program><rel:related_item><rel:description>Kitchen sink</rel:description>"
         + '<rel:inter_work_relation identifier-type="uri" ' +
         'relationship-type="isSupplementedBy">' +
         "https://github.com/elifesciences/XML-mapping/blob/master/elife-00666.xml"
         + "</rel:inter_work_relation></rel:related_item>")
     expected_xml_snippet_2 = (
         '<rel:related_item><rel:inter_work_relation identifier-type="accession" '
         +
         'relationship-type="references">EGAS00001000968</rel:inter_work_relation>'
         + "</rel:related_item>")
     expected_xml_snippet_3 = (
         '<rel:related_item><rel:inter_work_relation identifier-type="doi" '
         +
         'relationship-type="references">10.5061/dryad.cv323</rel:inter_work_relation>'
         + "</rel:related_item>")
     expected_xml_snippet_4 = (
         '<rel:related_item><rel:inter_work_relation identifier-type="uri" '
         + 'relationship-type="isSupplementedBy">http://cghub.ucsc.edu' +
         "</rel:inter_work_relation></rel:related_item>")
     expected_xml_snippet_5 = (
         '<rel:related_item><rel:inter_work_relation identifier-type="uri" '
         +
         'relationship-type="isSupplementedBy">https://elifesciences.org' +
         "</rel:inter_work_relation></rel:related_item>")
     # generate output
     c_xml = generate.build_crossref_xml([article])
     crossref_xml_string = c_xml.output_xml()
     self.assertIsNotNone(crossref_xml_string)
     # Test for expected strings in the XML output
     self.assertTrue(expected_xml_snippet_1 in crossref_xml_string)
     self.assertTrue(expected_xml_snippet_2 in crossref_xml_string)
     self.assertTrue(expected_xml_snippet_3 in crossref_xml_string)
     self.assertTrue(expected_xml_snippet_4 in crossref_xml_string)
     self.assertTrue(expected_xml_snippet_5 in crossref_xml_string)