Esempio n. 1
0
 def test_save(self):
     
     create_class(ClassToSave, client=self.client)
     
     class_to_save = ClassToSave()
     class_to_save.int_field = 10
     class_to_save.str_field = 'foobar'
     class_to_save.datetime_field = Arrow.utcnow()
     class_to_save.float_field = 12345.547
     class_to_save.save(client=self.client)
     loaded_class = ClassToSave.get(class_to_save.rid, client=self.client)
     self.assertEqual(class_to_save.__class__, loaded_class.__class__)
     self.assertEqual(loaded_class.rid, class_to_save.rid)
     self.assertEqual(loaded_class.str_field, class_to_save.str_field)
     self.assertEqual(loaded_class.int_field, class_to_save.int_field)
     self.assertEqual(loaded_class.datetime_field, class_to_save.datetime_field)
     self.assertEqual(loaded_class.float_field, class_to_save.float_field)
     self.assertEqual(loaded_class.bool_field, class_to_save.bool_field)
     class_to_save.int_field = 20
     class_to_save.str_field = 'foobarioioioioio'
     class_to_save.datetime_field = Arrow.utcnow()
     class_to_save.float_field = None
     class_to_save.bool_field = False
     class_to_save.save(client=self.client)
     loaded_class = ClassToSave.get(class_to_save.rid, client=self.client)
     self.assertEqual(class_to_save.__class__, loaded_class.__class__)
     self.assertEqual(loaded_class.rid, class_to_save.rid)
     self.assertEqual(loaded_class.str_field, class_to_save.str_field)
     self.assertEqual(loaded_class.int_field, class_to_save.int_field)
     self.assertEqual(loaded_class.datetime_field, class_to_save.datetime_field)
     self.assertEqual(loaded_class.float_field, class_to_save.float_field)
     self.assertEqual(loaded_class.bool_field, class_to_save.bool_field)
Esempio n. 2
0
 def test_delete_record(self):
     
     create_class(ClassToDelete, client=self.client)
     ctd = ClassToDelete()
     ctd.str_field = 'jfksfjdsl'
     ctd.save(client=self.client)
     self.assertTrue(delete(ctd.rid, client=self.client))
     self.assertIsNone(ClassToDelete.get(ctd.rid, client=self.client))
Esempio n. 3
0
 def test_delete(self):
     
     create_class(ClassToDelete, client=self.client)
     class_to_delete = ClassToDelete()
     class_to_delete.str_field = 'fdjsfdsf'
     self.assertRaises(OgormError, class_to_delete.delete)
     class_to_delete.save(client=self.client)
     self.assertTrue(class_to_delete.delete(client=self.client))
     self.assertIsNone(ClassToDelete.get(class_to_delete.rid, client=self.client))
Esempio n. 4
0
    def test_create_class_with_attribues(self):

        create_class(ClassWithAttributes, client=self.client)

        # we will get the properties and make sure they are
        # correct types and names
        r = self.client.command("select expand(properties) from ( select expand(classes) from metadata:schema) where name = '%s'" % get_orient_valid_class_name(ClassWithAttributes))
        cwa = ClassWithAttributes()
        # loop through the fields and make sure they are defined
        # the way we expect in OrientDB
        for f in cwa._fields.keys():
            self.assertTrue(any(x.type == cwa._fields[f].orientdb_type_id for x in r))
            self.assertTrue(any(x.name == to_java_case(f) for x in r))
Esempio n. 5
0
    def test_create_class(self):

        r = self.client.command("select expand(classes) from metadata:schema")
        self.assertFalse(any(x.name == get_orient_valid_class_name(Foo) for x in r))

        create_class(Foo, client=self.client)

        r = self.client.command("select expand(classes) from metadata:schema")

        # we are making sure that the class is defined in Orient
        # by looping through all the defined classes and looking
        # for Foo, note that Foo doesn't have any attributes
        # or properties to check, we just need to know its there
        self.assertTrue(any(x.name == get_orient_valid_class_name(Foo) for x in r))
Esempio n. 6
0
    def test_create_inheriting_class(self):
        
        create_class(ClassWithAttributes, client=self.client)
        create_class(InheritingClass, client=self.client)

        # we will get the properties and make sure they are
        # correct types and names
        r = self.client.command("select expand(properties) from ( select expand(classes) from metadata:schema) where name = '%s'" % get_orient_valid_class_name(InheritingClass))
        ic = InheritingClass()
        # loop through the fields and make sure they are defined
        # the way we expect in OrientDB
        # orient will NOT show inherited fields
        for f in ic._fields.keys():
            if not ic._fields[f].inherited:
                self.assertTrue(any(x.type == ic._fields[f].orientdb_type_id for x in r))
                self.assertTrue(any(x.name == to_java_case(f) for x in r))
Esempio n. 7
0
 def test_from_orient(self):
     
     create_class(ClassToInsert, client=self.client)
     
     class_to_insert = ClassToInsert()
     class_to_insert.int_field = 10
     class_to_insert.str_field = 'foobar'
     class_to_insert.datetime_field = Arrow.utcnow()
     class_to_insert.float_field = 12345.547
     class_to_insert.bin_field = bytes('foo','utf-8')
     insert(class_to_insert, client=self.client)
     r = load(class_to_insert.rid, client=self.client)
     result = Model.from_orient(r)
     self.assertEqual(class_to_insert.__class__, result.__class__)
     self.assertEqual(result.rid, class_to_insert.rid)
     self.assertEqual(result.str_field, class_to_insert.str_field)
     self.assertEqual(result.int_field, class_to_insert.int_field)
     self.assertEqual(result.datetime_field, class_to_insert.datetime_field)
     self.assertEqual(result.float_field, class_to_insert.float_field)
     self.assertEqual(result.bin_field, class_to_insert.bin_field)
Esempio n. 8
0
 def test_get(self):
     
     create_class(ClassToGet, client=self.client)
     
     class_to_insert = ClassToGet()
     class_to_insert.int_field = 10
     class_to_insert.str_field = 'foobar'
     class_to_insert.datetime_field = Arrow.utcnow()
     class_to_insert.float_field = 12345.547
     class_to_insert.bin_field = bytes('foo','utf-8')
     class_to_insert.bool_field = True
     insert(class_to_insert, client=self.client)
     loaded_class = ClassToGet.get(class_to_insert.rid, client=self.client)
     self.assertEqual(class_to_insert.__class__, loaded_class.__class__)
     self.assertEqual(loaded_class.rid, class_to_insert.rid)
     self.assertEqual(loaded_class.str_field, class_to_insert.str_field)
     self.assertEqual(loaded_class.int_field, class_to_insert.int_field)
     self.assertEqual(loaded_class.datetime_field, class_to_insert.datetime_field)
     self.assertEqual(loaded_class.float_field, class_to_insert.float_field)
     self.assertEqual(loaded_class.bin_field, class_to_insert.bin_field)
     self.assertEqual(loaded_class.bool_field, class_to_insert.bool_field)
Esempio n. 9
0
    def test_record_update(self):

        create_class(ClassToUpdate, client=self.client)

        class_to_update = ClassToUpdate()
        class_to_update.int_field = 10
        class_to_update.str_field = 'foobar'
        class_to_update.datetime_field = Arrow.utcnow()
        class_to_update.float_field = 12345.547
        insert(class_to_update, client=self.client)
        self.assertIsNotNone(class_to_update.rid)
        r = load(class_to_update.rid, client=self.client)
        self.assertEqual(r._rid, class_to_update.rid)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['str_field']],
                         class_to_update.str_field)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['int_field']],
                         class_to_update.int_field)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['datetime_field']],
                         class_to_update.datetime_field.timestamp)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['float_field']],
                         class_to_update.float_field)
        class_to_update.int_field = 20
        class_to_update.str_field = 'barfoo'
        class_to_update.datetime_field = Arrow.utcnow()
        class_to_update.float_field = None
        update(class_to_update, client=self.client)
        self.assertIsNotNone(class_to_update.rid)
        r = load(class_to_update.rid, client=self.client)
        self.assertEqual(r._rid, class_to_update.rid)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['str_field']],
                         class_to_update.str_field)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['int_field']],
                         class_to_update.int_field)
        self.assertEqual(r.oRecordData[class_to_update._py_to_orient_field_mapping['datetime_field']],
                         class_to_update.datetime_field.timestamp)
        self.assertFalse(class_to_update._py_to_orient_field_mapping['float_field'] in r.oRecordData)
Esempio n. 10
0
    def test_load_record(self):

        create_class(ClassToLoad, client=self.client)

        class_to_insert = ClassToLoad()
        class_to_insert.int_field = 10
        class_to_insert.str_field = 'foobar'
        class_to_insert.datetime_field = Arrow.utcnow()
        class_to_insert.float_field = 12345.547
        class_to_insert.bin_field = bytes('foo', 'utf-8')
        insert(class_to_insert, client=self.client)
        self.assertIsNotNone(class_to_insert.rid)
        r = load(class_to_insert.rid, client=self.client)
        self.assertEqual(r._rid, class_to_insert.rid)
        self.assertEqual(r.oRecordData[class_to_insert._py_to_orient_field_mapping['str_field']],
                         class_to_insert.str_field)
        self.assertEqual(r.oRecordData[class_to_insert._py_to_orient_field_mapping['int_field']],
                         class_to_insert.int_field)
        self.assertEqual(r.oRecordData[class_to_insert._py_to_orient_field_mapping['datetime_field']],
                         class_to_insert.datetime_field.timestamp)
        self.assertEqual(r.oRecordData[class_to_insert._py_to_orient_field_mapping['float_field']],
                         class_to_insert.float_field)
        self.assertEqual(base64.b64decode(r.oRecordData[class_to_insert._py_to_orient_field_mapping['bin_field']].encode()),
                         class_to_insert.bin_field)