Ejemplo n.º 1
0
 def test_handle_file(self):
     ingester = ZoteroIngest(self.rdf_path)
     ingester.graph = self.g
     predicate, values = ingester.handle_link(RSS.link, self.doc2)
     values = dict(values)
     self.assertIn('link', values)
     self.assertEqual(values['link'], self.link.replace('file://', ''))
Ejemplo n.º 2
0
    def test_handle_title(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_title`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g

        predicate, value = ingester.handle_title(DC.title, "!")
        self.assertEqual(predicate, "name",
                         "DC.title should be flagged as the Resource.name")
Ejemplo n.º 3
0
    def test_handle_type(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_documentType`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g

        predicate, value = ingester.handle_documentType(ZOTERO.itemType, "!")
        self.assertEqual(
            predicate, "entity_type",
            "ZOTERO.itemType should be flagged as the Resource.entity_type")
Ejemplo n.º 4
0
    def test_handle_date(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_date`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g

        predicate, value = ingester.handle_date(DC.date, self.date)
        self.assertIsInstance(
            value, datetime.datetime,
            "ISO-8601 compliant dates should be recast to datetime instances.")
Ejemplo n.º 5
0
 def test_handle_link(self):
     ingester = ZoteroIngest(self.rdf_path)
     ingester.graph = self.g
     predicate, values = ingester.handle_link(RSS.link, self.doc)
     values = dict(values)
     self.assertIn('url', values)
     self.assertEqual(
         values['url'], self.location,
         "The URI of the link target should be interpreted as an URL.")
     self.assertIsInstance(
         values[DCTERMS.dateSubmitted.toPython()], datetime.datetime,
         "dateSubmitted should be recast as a datetime object.")
Ejemplo n.º 6
0
    def test_handle_identifier(self):
        """
        Unit test for :meth:`ZoteroIngest.handle_identifier`\.
        """
        ingester = ZoteroIngest(self.rdf_path)

        # We want to intervene on our original graph here.
        ingester.graph = self.g
        result = ingester.handle_identifier(DC.identifier, self.ident)
        self.assertIsInstance(result, tuple, "Handlers should return tuples.")
        self.assertEqual(
            result[0], 'uri',
            "DCTERMS.URI identifiers should be used as first-class URIs.")
        self.assertEqual(result[1].toPython(), self.test_uri)

        result = ingester.handle_identifier(DC.identifier, self.ident2)
        self.assertIsInstance(result, tuple, "Handlers should return tuples.")
        self.assertEqual(result[0], BIB.doi)
        self.assertEqual(result[1].toPython(), self.test_doi)
Ejemplo n.º 7
0
    def test_handle(self):
        """
        Unit test for :meth:`ZoteroIngest.handle`\.
        """
        ingester = ZoteroIngest(self.rdf_path)
        ingester.graph = self.g
        ingester._new_entry()  # Need somewhere to put the value.
        predicate, value = ingester.handle(DC.identifier, self.ident)
        self.assertEqual(
            value, self.test_uri,
            "handle() should pass along the predicate and value to"
            " handle_identifier(), and return native Python types.")

        predicate, value = ingester.handle(DC.nonsense, "value")
        self.assertEqual(
            predicate, DC.nonsense.toPython(),
            "If there are no special handlers for the predicate, it should be"
            " returned as a native Python type.")
        self.assertEqual(value, "value",
                         "So too with the corresponding value.")