Esempio n. 1
0
    def test_save_record_invalid(self):
        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.save_record(list())

        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.save_record(examples.primer_example())

        class InvalidProvRecordExtend(ProvRecord):
            pass

        with self.assertRaises(InvalidArgumentTypeException):
            doc = examples.primer_example()
            identifier = doc.valid_qualified_name("prov:example")
            self.provapi.save_record(
                InvalidProvRecordExtend(bundle=doc, identifier=identifier))
Esempio n. 2
0
    def test_get_element(self):
        """
        Try to save a single record without document_id
        and get the record back from the db

        """
        self.clear_database()
        doc = examples.primer_example()
        agent = list(doc.get_records(ProvAgent)).pop()
        entity = list(doc.get_records(ProvEntity)).pop()
        activity = list(doc.get_records(ProvActivity)).pop()

        #Try to save the 3 class types
        agent_id = self.provapi.save_element(agent)
        entity_id = self.provapi.save_element(entity)
        activity_id = self.provapi.save_element(activity)

        self.assertIsInstance(agent_id, QualifiedName)
        self.assertIsInstance(entity_id, QualifiedName)
        self.assertIsInstance(activity_id, QualifiedName)

        agent_restored = self.provapi.get_element(agent_id)
        entity_restored = self.provapi.get_element(entity_id)
        activity_restored = self.provapi.get_element(activity_id)

        self.assertEqual(agent_restored, agent)
        self.assertEqual(entity_restored, entity)
        self.assertEqual(activity_restored, activity)
Esempio n. 3
0
    def test_get_document_as_provn(self):
        example = examples.primer_example()
        document_id = self.provapi.create_document_from_prov(example)

        prov_str = self.provapi.get_document_as_provn(document_id)
        self.assertIsNotNone(prov_str)
        self.assertIsInstance(prov_str, str)
Esempio n. 4
0
    def test_prov_primer_example(self):
        prov_document = examples.primer_example()
        stored_document_id = self.provapi.create_document_from_prov(
            prov_document)
        stored_document = self.provapi.get_document_as_prov(stored_document_id)

        self.assertEqual(stored_document, prov_document)
Esempio n. 5
0
    def test_save_relation_invalid(self):

        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.save_relation(None)

        with self.assertRaises(InvalidArgumentTypeException):
            doc = examples.primer_example()
            element = list(doc.get_records(ProvEntity)).pop()
            self.provapi.save_relation(element)
Esempio n. 6
0
    def test_get_document_as_json(self):
        example = examples.primer_example()
        document_id = self.provapi.create_document_from_prov(example)

        prov_str = self.provapi.get_document_as_json(document_id)
        self.assertIsNotNone(prov_str)
        self.assertIsInstance(prov_str, str)
        prov_document_reverse = ProvDocument.deserialize(content=prov_str,
                                                         format="json")
        self.assertEqual(prov_document_reverse, example)
Esempio n. 7
0
 def test_save_document_from_prov(self):
     """
     Try to create a primer example document
     :return:
     """
     self.clear_database()
     example = examples.primer_example()
     document_id = self.provapi.save_document_from_prov(example)
     self.assertIsNotNone(document_id)
     self.assertIsInstance(document_id, str)
Esempio n. 8
0
    def test_create_document(self):
        # test prov document input
        example = examples.primer_example()
        document_id = self.provapi.create_document_from_prov(example)
        self.assertIsNotNone(document_id)
        self.assertIsInstance(document_id, str)

        # test invalid options input
        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.create_document(1)
Esempio n. 9
0
    def test_save_relation_with_unknown_nodes(self):
        """
        Test to create a relation were the start and end node dose not exist
        This should also work
        """
        self.clear_database()
        doc = examples.primer_example()
        relation = list(doc.get_records(ProvRelation)).pop()

        self.provapi.save_relation(relation)
Esempio n. 10
0
    def test_save_bundle_invalid(self):
        """
        Test the public method to save bundles with invalid arguments
        """
        doc = examples.primer_example()

        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.save_bundle(doc)

        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.save_bundle(None)
Esempio n. 11
0
    def test_get_document_as_provn(self):
        """
        Try to get a document in provn
        :return:
        """
        self.clear_database()
        example = examples.primer_example()
        document_id = self.provapi.save_document_from_prov(example)

        prov_str = self.provapi.get_document_as_provn(document_id)
        self.assertIsNotNone(prov_str)
        self.assertIsInstance(prov_str, str)
Esempio n. 12
0
    def test_prov_primer_example(self):
        """
        This test try to save and restore a common prov example document

        :return:
        """
        self.clear_database()
        prov_document = examples.primer_example()
        stored_document_id = self.provapi.save_document_from_prov(
            prov_document)
        stored_document = self.provapi.get_document_as_prov(stored_document_id)

        self.assertEqual(stored_document, prov_document)
Esempio n. 13
0
    def test_get_document_as_json(self):
        """
        try to get the document as json
        :return:
        """
        self.clear_database()
        example = examples.primer_example()
        document_id = self.provapi.save_document_from_prov(example)

        prov_str = self.provapi.get_document_as_json(document_id)
        self.assertIsNotNone(prov_str)
        self.assertIsInstance(prov_str, str)
        prov_document_reverse = ProvDocument.deserialize(content=prov_str,
                                                         format="json")
        self.assertEqual(prov_document_reverse, example)
Esempio n. 14
0
    def test_save_document(self):
        """
        Try to create a document from a prov instnace
        :return:
        """
        self.clear_database()
        # test prov document input
        example = examples.primer_example()
        document_id = self.provapi.save_document_from_prov(example)
        self.assertIsNotNone(document_id)
        self.assertIsInstance(document_id, str)

        # test invalid options input
        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.save_document(1)
Esempio n. 15
0
    def test_save_element(self):
        """
        Try to save a single record without document_di

        """
        self.clear_database()

        doc = examples.primer_example()
        agent = list(doc.get_records(ProvAgent)).pop()
        entity = list(doc.get_records(ProvEntity)).pop()
        activity = list(doc.get_records(ProvActivity)).pop()

        #Try to save the 3 class types
        self.provapi.save_element(agent)
        self.provapi.save_element(entity)
        self.provapi.save_element(activity)
Esempio n. 16
0
    def test_save_record(self):
        """
        Test to save a record (a element or a relation)
        """
        self.clear_database()
        doc = examples.primer_example()
        element = list(doc.get_records(ProvActivity)).pop()
        relation = list(doc.get_records(ProvRelation)).pop()

        #save element
        self.provapi.save_record(element)
        db_element = self.provapi.get_element(element.identifier)

        self.assertEqual(db_element, element)

        #Save relation
        self.provapi.save_record(relation)
Esempio n. 17
0
 def test_create_document_from_prov(self):
     example = examples.primer_example()
     document_id = self.provapi.create_document_from_prov(example)
     self.assertIsNotNone(document_id)
     self.assertIsInstance(document_id, str)