Пример #1
0
 def test_ListNode_create(self):
     con = Connection('http://0.0.0.0:3333')
     con.login('*****@*****.**', 'test')
     node = ListNode(con=con,
                     project=self.project,
                     label=LangString({Languages.DE: "root node 1"}),
                     comment=LangString({Languages.DE: "first root node"}),
                     name="test_node_1").create()
     self.assertIsNotNone(node.id)
     self.assertEqual(node.project, self.project)
     self.assertEqual(node.label['de'], "root node 1")
     self.assertEqual(node.comment['de'], "first root node")
     self.assertEqual(node.name, "test_node_1")
     self.assertTrue(node.isRootNode)
Пример #2
0
    def test_langstring_tojson(self):
        """Test converting a LangString to JSON and JSON-LD"""
        ls = LangString('Ein simpler String')
        json = ls.toJsonObj()
        self.assertEqual(json, 'Ein simpler String')
        json = ls.toJsonLdObj()
        self.assertEqual(json, 'Ein simpler String')

        ls = LangString({
            Languages.DE: 'Ein simpler String',
            Languages.FR: 'Quelque chose en français'
        })
        json = ls.toJsonObj()
        expected = [{
            'language': 'de',
            'value': 'Ein simpler String'
        }, {
            'language': 'fr',
            'value': 'Quelque chose en français'
        }]
        self.assertEqual(json, expected)
        jsonld = ls.toJsonLdObj()
        expected = [{
            '@language': 'de',
            '@value': 'Ein simpler String'
        }, {
            '@language': 'fr',
            '@value': 'Quelque chose en français'
        }]
        self.assertEqual(jsonld, expected)
Пример #3
0
 def test_langstring_instantiation3(self):
     """Test a LangString using string and Languages-enums as index."""
     ls = LangString({
         Languages.DE: 'Ein simpler String',
         Languages.FR: 'Quelque chose en français'
     })
     self.assertEqual(ls[Languages.DE], 'Ein simpler String')
     self.assertEqual(ls['fr'], 'Quelque chose en français')
Пример #4
0
 def test_langstring_change(self):
     """test if changing a LangString item works."""
     ls = LangString({
         Languages.DE: 'Ein simpler String',
         Languages.FR: 'Quelque chose en français'
     })
     ls['de'] = 'gagaga'
     self.assertEqual(ls[Languages.DE], 'gagaga')
     self.assertEqual(ls['fr'], 'Quelque chose en français')
Пример #5
0
 def test_langstring_iterator(self):
     """Test iterating over a LangString."""
     ls = LangString({
         Languages.DE: 'Ein simpler String',
         Languages.FR: 'Quelque chose en français'
     })
     for tmp in ls:
         if tmp[0] == Languages.DE:
             self.assertEqual(tmp[1], 'Ein simpler String')
         elif tmp[0] == Languages.FR:
             self.assertEqual(tmp[1], 'Quelque chose en français')
Пример #6
0
 def test_langstring_fromjsonld(self):
     """Test reading a LangString from JSON-LD as used in Knora data/ontologies"""
     test = [{
         '@language': 'en',
         '@value': 'This is a test'
     }, {
         '@language': 'de',
         '@value': 'Das ist ein Test'
     }]
     ls = LangString.fromJsonLdObj(test)
     self.assertEqual(ls['de'], 'Das ist ein Test')
     self.assertEqual(ls[Languages.EN], 'This is a test')
Пример #7
0
 def test_langstring_fromjson(self):
     """Test reading a LangString from JSON as used in Knora Admin."""
     test = [{
         'language': 'en',
         'value': 'This is a test'
     }, {
         'language': 'de',
         'value': 'Das ist ein Test'
     }]
     ls = LangString.fromJsonObj(test)
     self.assertEqual(ls['de'], 'Das ist ein Test')
     self.assertEqual(ls[Languages.EN], 'This is a test')
Пример #8
0
 def test_ListNode_update(self):
     """
     Update the data of a node...
     :return:
     """
     con = Connection('http://0.0.0.0:3333')
     con.login('*****@*****.**', 'test')
     node = ListNode(con=con,
                     project=self.project,
                     label=LangString({Languages.DE: "root node 3"}),
                     comment=LangString({Languages.DE: "Third root node"}),
                     name="test_node_3").create()
     node.addLabel('fr', 'Une racine d\' une liste')
     node.rmLabel('de')
     node.addComment('fr', 'un commentaire en français')
     node.rmComment('de')
     node.name = 'GAGAGA'
     node.update()
     self.assertEqual(node.label['fr'], 'Une racine d\' une liste')
     self.assertEqual(node.comment['fr'], 'un commentaire en français')
     self.assertEqual(node.name, 'GAGAGA')
Пример #9
0
 def test_ListNode_hierarchy(self):
     """
     Create a node and a sub-node
     :return: None
     """
     con = Connection('http://0.0.0.0:3333')
     con.login('*****@*****.**', 'test')
     node = ListNode(con=con,
                     project=self.project,
                     label=LangString({Languages.DE: "root node 2"}),
                     comment=LangString({Languages.DE: "second root node"}),
                     name="test_node_2").create()
     node2 = ListNode(
         con=con,
         project=self.project,
         label=LangString({Languages.DE: 'Eine Knoten der Liste'}),
         comment=LangString({Languages.DE: "So ein Kommentar"}),
         name="NODE2",
         parent=node).create()
     self.assertEqual(node2.label['de'], 'Eine Knoten der Liste')
     self.assertEqual(node2.comment['de'], "So ein Kommentar")
     self.assertEqual(node2.name, "NODE2")
     self.assertFalse(node2.isRootNode)
Пример #10
0
class TestResourceClass(unittest.TestCase):
    project = "http://rdfh.ch/projects/0001"

    label = LangString({Languages.DE: 'MyResClassLabel'})
    comment = LangString(
        {Languages.DE: 'This is a resource class for testing'})
    name = 'MyResClassName'

    def test_ResourceClass_create(self):
        #
        # Connect to Knora
        #
        con = Connection('http://0.0.0.0:3333')
        con.login('*****@*****.**', 'test')

        #
        # Create a test ontology
        #
        onto = Ontology(
            con=con,
            project=self.project,
            name='resclass-test-onto-1',
            label='resclass test ontology 1',
        ).create()
        last_modification_date = onto.lastModificationDate
        self.assertIsNotNone(onto.id)
        #
        # Create new resource class
        #
        last_modification_date, resclass = ResourceClass(
            con=con,
            context=onto.context,
            name=self.name,
            ontology_id=onto.id,
            label=self.label,
            comment=self.comment).create(last_modification_date)
        onto.lastModificationDate = last_modification_date
        self.assertIsNotNone(resclass.id)

        self.assertEqual(resclass.name, self.name)
        self.assertEqual(resclass.label['de'], self.label['de'])
        self.assertEqual(resclass.comment['de'], self.comment['de'])

        #
        # Delete the new resource class
        #
        last_modification_date = resclass.delete(last_modification_date)
        onto.lastModificationDate = last_modification_date

    def test_ResourceClass_update(self):
        #
        # Connect to Knora
        #
        con = Connection('http://0.0.0.0:3333')
        con.login('*****@*****.**', 'test')

        #
        # Create a test ontology
        #
        onto = Ontology(
            con=con,
            project=self.project,
            name='resclass-test-onto-2',
            label='resclass test ontology 2',
        ).create()
        last_modification_date = onto.lastModificationDate
        self.assertIsNotNone(onto.id)
        #
        # create test resource class
        #
        last_modification_date, resclass = ResourceClass(
            con=con,
            context=onto.context,
            name=self.name,
            ontology_id=onto.id,
            label=self.label,
            comment=self.comment).create(last_modification_date)
        onto.lastModificationDate = last_modification_date
        self.assertIsNotNone(resclass.id)

        #
        # Modify the resource class
        #
        resclass.addLabel('en', "This is english gaga")
        resclass.rmLabel('de')
        resclass.addComment('it', "Commentario italiano")
        last_modification_date, resclass = resclass.update(
            last_modification_date)
        onto.lastModificationDate = last_modification_date
        self.assertEqual(resclass.label['en'], "This is english gaga")
        self.assertEqual(resclass.comment['it'], "Commentario italiano")

        #
        # Now delete the resource class to clean up
        #
        last_modification_date = resclass.delete(last_modification_date)
        onto.lastModificationDate = last_modification_date
Пример #11
0
class TestPropertyClass(unittest.TestCase):
    project = "http://rdfh.ch/projects/0001"
    onto_name = 'propclass-test'
    onto_label = 'propclass_test_ontology'

    onto: Ontology
    last_modification_date: LastModificationDate
    con: Connection

    name = 'MyPropClassName'
    object = 'TextValue'
    label = LangString({Languages.DE: 'MyPropClassLabel'})
    comment = LangString(
        {Languages.DE: 'This is a property class for testing'})

    def setUp(self) -> None:
        #
        # Connect to Knora
        #
        self.con = Connection('http://0.0.0.0:3333')
        self.con.login('*****@*****.**', 'test')

        #
        # Create a test ontology
        #
        self.onto = Ontology(
            con=self.con,
            project=self.project,
            name=self.onto_name,
            label=self.onto_label,
        ).create()
        self.assertIsNotNone(self.onto.id)
        self.last_modification_date = self.onto.lastModificationDate

    def tearDown(self):
        #
        # remove test ontology
        #
        result = self.onto.delete()
        self.assertIsNotNone(result)

    def test_PropertyClass_create(self):
        #
        # Create new property class
        #
        self.last_modification_date, propclass = PropertyClass(
            con=self.con,
            context=self.onto.context,
            name=self.name,
            ontology_id=self.onto.id,
            object=self.object,
            label=self.label,
            comment=self.comment).create(self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertIsNotNone(propclass.id)

        self.assertEqual(propclass.name, self.name)
        self.assertEqual(propclass.label['de'], self.label['de'])
        self.assertEqual(propclass.comment['de'], self.comment['de'])

        #
        # Again get ontology data
        #
        self.onto = self.onto.read()
        self.last_modification_date = self.onto.lastModificationDate
        self.last_modification_date = propclass.delete(
            self.last_modification_date)

        #
        # Again get ontology data
        #
        self.onto = self.onto.read()

    def test_PropertyClass_update(self):
        self.onto = self.onto.read()

        #
        # create test resource class
        #
        self.last_modification_date, propclass = PropertyClass(
            con=self.con,
            context=self.onto.context,
            name=self.name,
            ontology_id=self.onto.id,
            object=self.object,
            label=self.label,
            comment=self.comment).create(self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertIsNotNone(propclass.id)

        #
        # Modify the property class
        #
        propclass.addLabel('en', "This is english gaga")
        propclass.rmLabel('de')
        propclass.addComment('it', "Commentario italiano")
        self.last_modification_date, propclass = propclass.update(
            self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertEqual(propclass.label['en'], "This is english gaga")
        self.assertEqual(propclass.comment['it'], "Commentario italiano")

        #
        # Now delete the resource class to clean up
        #
        self.last_modification_date = propclass.delete(
            self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
Пример #12
0
 def test_langstring_emptyness(self):
     """Test if a LanGstring can be emptied and if the emptyness is detected."""
     ls = LangString()
     self.assertTrue(ls.isEmpty())
     ls = LangString('Ein simpler String')
     ls.empty()
     self.assertTrue(ls.isEmpty())
     ls = LangString({
         Languages.DE: 'Ein simpler String',
         Languages.FR: 'Quelque chose en français'
     })
     ls.empty()
     self.assertTrue(ls.isEmpty())
Пример #13
0
 def test_langstring_instantiation1(self):
     """Test a LangString without language."""
     ls = LangString('Ein simpler String')
     self.assertEqual(ls[None], 'Ein simpler String')
Пример #14
0
class TestAllClass(unittest.TestCase):
    project = "http://rdfh.ch/projects/0001"
    onto_name = 'all-test'
    onto_label = 'all_test_ontology'

    resclass_name = 'MyResClassName'
    resclass_label = LangString({Languages.DE: 'MyResClassLabel'})
    resclass_comment = LangString(
        {Languages.DE: 'This is a resource class for testing'})

    propclass_name = 'MyPropClassName'
    propclass_object = 'TextValue'
    propclass_label = LangString({Languages.DE: 'MyPropClassLabel'})
    propclass_comment = LangString(
        {Languages.DE: 'This is a property class for testing'})

    con: Connection
    onto: Ontology
    last_modification_date: LastModificationDate

    def setUp(self) -> None:
        #
        # Connect to Knora
        #
        self.con = Connection('http://0.0.0.0:3333')
        self.con.login('*****@*****.**', 'test')

        #
        # Create a test ontology
        #
        self.onto = Ontology(
            con=self.con,
            project=self.project,
            name=self.onto_name,
            label=self.onto_label,
        ).create()
        self.last_modification_date = self.onto.lastModificationDate
        self.assertIsNotNone(self.onto.id)

    def tearDown(self):
        #
        # remove test ontology
        #
        result = self.onto.delete()
        self.assertIsNotNone(result)

    def test_AllThings_create(self):
        #
        # Create new resource class
        #
        self.last_modification_date, resclass = ResourceClass(
            con=self.con,
            context=self.onto.context,
            name=self.resclass_name,
            ontology_id=self.onto.id,
            label=self.resclass_label,
            comment=self.resclass_comment).create(self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertIsNotNone(resclass.id)

        self.assertEqual(resclass.name, self.resclass_name)
        self.assertEqual(resclass.label['de'], self.resclass_label['de'])
        self.assertEqual(resclass.comment['de'], self.resclass_comment['de'])

        #
        # Create new property class
        #
        self.last_modification_date, propclass = PropertyClass(
            con=self.con,
            context=self.onto.context,
            name=self.propclass_name,
            ontology_id=self.onto.id,
            object=self.propclass_object,
            label=self.propclass_label,
            comment=self.propclass_comment).create(self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertIsNotNone(propclass.id)

        self.assertEqual(propclass.name, self.propclass_name)
        self.assertEqual(propclass.label['de'], self.propclass_label['de'])
        self.assertEqual(propclass.comment['de'], self.propclass_comment['de'])

        #
        # Create HasProperty (cardinality)
        #
        self.last_modification_date = resclass.addProperty(
            propclass.id, Cardinality.C_1, self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertEqual(
            resclass.getProperty(propclass.id).cardinality, Cardinality.C_1)
        self.assertIsNotNone(self.last_modification_date)

        #
        # Modify HasProperty (cardinality)
        #
        self.last_modification_date = resclass.updateProperty(
            propclass.id, Cardinality.C_1_n, self.last_modification_date)
        self.onto.lastModificationDate = self.last_modification_date
        self.assertEqual(
            resclass.getProperty(propclass.id).cardinality, Cardinality.C_1_n)
        self.assertIsNotNone(self.last_modification_date)