Exemplo n.º 1
0
 def test_citation(self) -> None:
     ScientificExtension.ext(self.collection).apply(citation=CITATION)
     self.assertEqual(CITATION,
                      ScientificExtension.ext(self.collection).citation)
     self.assertIn(scientific.CITATION_PROP, self.collection.extra_fields)
     self.assertFalse(self.collection.get_links(ScientificRelType.CITE_AS))
     self.collection.validate()
Exemplo n.º 2
0
 def test_remove_all_publications_with_none(self) -> None:
     ScientificExtension.ext(self.collection).apply(DOI)
     ScientificExtension.ext(self.collection).remove_publication()
     self.assertFalse(ScientificExtension.ext(self.collection).publications)
     links = self.collection.get_links(ScientificRelType.CITE_AS)
     self.assertEqual(1, len(links))
     self.assertEqual(DOI_URL, links[0].target)
     self.collection.validate()
Exemplo n.º 3
0
 def test_remove_all_publications_with_some(self) -> None:
     ScientificExtension.ext(self.item).apply(DOI,
                                              publications=PUBLICATIONS)
     ScientificExtension.ext(self.item).remove_publication()
     self.assertFalse(ScientificExtension.ext(self.item).publications)
     links = self.item.get_links(ScientificRelType.CITE_AS)
     self.assertEqual(1, len(links))
     self.assertEqual(DOI_URL, links[0].target)
     self.item.validate()
Exemplo n.º 4
0
 def test_remove_publication_one(self) -> None:
     publications = PUBLICATIONS[:1]
     ScientificExtension.ext(self.collection).apply(
         DOI, publications=publications)
     ScientificExtension.ext(self.collection).remove_publication(
         publications[0])
     self.assertFalse(ScientificExtension.ext(self.collection).publications)
     links = self.collection.get_links(ScientificRelType.CITE_AS)
     self.assertEqual(1, len(links))
     self.assertEqual(DOI_URL, links[0].target)
     self.collection.validate()
Exemplo n.º 5
0
    def test_publications(self) -> None:
        ScientificExtension.ext(self.item).apply(publications=PUBLICATIONS)
        self.assertEqual(PUBLICATIONS,
                         ScientificExtension.ext(self.item).publications)
        self.assertIn(scientific.PUBLICATIONS_PROP, self.item.properties)

        links = self.item.get_links(ScientificRelType.CITE_AS)
        doi_urls = [link.get_href() for link in links]
        expected = [PUB1_DOI_URL, PUB2_DOI_URL]
        self.assertCountEqual(expected, doi_urls)
        self.item.validate()
Exemplo n.º 6
0
    def test_publications_one(self) -> None:
        publications = PUBLICATIONS[:1]
        ScientificExtension.ext(
            self.collection).apply(publications=publications)
        self.assertEqual(publications,
                         ScientificExtension.ext(self.collection).publications)
        self.assertIn(scientific.PUBLICATIONS_PROP,
                      self.collection.extra_fields)

        links = self.collection.get_links(ScientificRelType.CITE_AS)
        doi_urls = [link.get_href() for link in links]
        expected = [PUB1_DOI_URL]
        self.assertCountEqual(expected, doi_urls)

        self.collection.validate()
Exemplo n.º 7
0
    def test_extension_not_implemented(self) -> None:
        # Should raise exception if Collection does not include extension URI
        collection = pystac.Collection.from_file(self.example_collection_uri)
        collection.stac_extensions.remove(ScientificExtension.get_schema_uri())

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = ScientificExtension.ext(collection)
Exemplo n.º 8
0
    def test_extension_not_implemented(self) -> None:
        # Should raise exception if Item does not include extension URI
        item = pystac.Item.from_file(self.example_item_uri)
        item.stac_extensions.remove(ScientificExtension.get_schema_uri())

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = ScientificExtension.ext(item)
Exemplo n.º 9
0
    def test_ext_add_to(self) -> None:
        collection = pystac.Collection.from_file(self.example_collection_uri)
        collection.stac_extensions.remove(ScientificExtension.get_schema_uri())
        self.assertNotIn(ScientificExtension.get_schema_uri(),
                         collection.stac_extensions)

        _ = ScientificExtension.ext(collection, add_if_missing=True)

        self.assertIn(ScientificExtension.get_schema_uri(),
                      collection.stac_extensions)
Exemplo n.º 10
0
    def test_ext_add_to(self) -> None:
        item = pystac.Item.from_file(self.example_item_uri)
        item.stac_extensions.remove(ScientificExtension.get_schema_uri())
        self.assertNotIn(ScientificExtension.get_schema_uri(),
                         item.stac_extensions)

        _ = ScientificExtension.ext(item, add_if_missing=True)

        self.assertIn(ScientificExtension.get_schema_uri(),
                      item.stac_extensions)
Exemplo n.º 11
0
    def test_doi(self) -> None:
        ScientificExtension.ext(self.item).apply(DOI)
        self.assertEqual(DOI, ScientificExtension.ext(self.item).doi)
        self.assertIn(scientific.DOI_PROP, self.item.properties)
        link = self.item.get_links(ScientificRelType.CITE_AS)[0]
        self.assertEqual(DOI_URL, link.get_href())
        self.item.validate()

        # Check that setting the doi does not cause extra links.

        # Same doi.
        ScientificExtension.ext(self.item).doi = DOI
        self.assertEqual(1,
                         len(self.item.get_links(ScientificRelType.CITE_AS)))
        self.item.validate()

        # Different doi.
        ScientificExtension.ext(self.item).doi = PUB1_DOI
        self.assertEqual(1,
                         len(self.item.get_links(ScientificRelType.CITE_AS)))
        link = self.item.get_links(ScientificRelType.CITE_AS)[0]
        self.assertEqual(PUB1_DOI_URL, link.get_href())
        self.item.validate()
Exemplo n.º 12
0
    def test_remove_publication_forward(self) -> None:
        ScientificExtension.ext(self.item).apply(DOI,
                                                 publications=PUBLICATIONS)

        ScientificExtension.ext(self.item).remove_publication(PUBLICATIONS[0])
        self.assertEqual([PUBLICATIONS[1]],
                         ScientificExtension.ext(self.item).publications)
        links = self.item.get_links(ScientificRelType.CITE_AS)
        self.assertEqual(2, len(links))
        self.assertEqual(DOI_URL, links[0].target)
        self.assertEqual(PUB2_DOI_URL, links[1].target)
        self.item.validate()

        ScientificExtension.ext(self.item).remove_publication(PUBLICATIONS[1])
        self.assertFalse(ScientificExtension.ext(self.item).publications)
        links = self.item.get_links(ScientificRelType.CITE_AS)
        self.assertEqual(1, len(links))
        self.assertEqual(DOI_URL, links[0].target)
        self.item.validate()
Exemplo n.º 13
0
    def test_remove_publication_reverse(self) -> None:
        ScientificExtension.ext(self.collection).apply(
            DOI, publications=PUBLICATIONS)

        ScientificExtension.ext(self.collection).remove_publication(
            PUBLICATIONS[1])
        self.assertEqual([PUBLICATIONS[0]],
                         ScientificExtension.ext(self.collection).publications)
        links = self.collection.get_links(ScientificRelType.CITE_AS)
        self.assertEqual(2, len(links))
        self.assertEqual(PUB1_DOI_URL, links[1].target)

        self.collection.validate()
        ScientificExtension.ext(self.collection).remove_publication(
            PUBLICATIONS[0])
        links = self.collection.get_links(ScientificRelType.CITE_AS)
        self.assertEqual(1, len(links))
        self.assertEqual(DOI_URL, links[0].target)
        self.collection.validate()
Exemplo n.º 14
0
 def test_citation(self) -> None:
     ScientificExtension.ext(self.item).apply(citation=CITATION)
     self.assertEqual(CITATION, ScientificExtension.ext(self.item).citation)
     self.assertIn(scientific.CITATION_PROP, self.item.properties)
     self.assertFalse(self.item.get_links(ScientificRelType.CITE_AS))
     self.item.validate()
Exemplo n.º 15
0
def process_scientific(item, granule):
    scientific_extension = ScientificExtension.ext(item, add_if_missing=True)
    for attribute in granule.AdditionalAttributes.AdditionalAttribute:
        if attribute.Name == "IDENTIFIER_PRODUCT_DOI":
            scientific_extension.doi = attribute.Values.Value.cdata