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)
def save(self, client=None): if self.rid is None: insert(self, client=client) else: update(self, client=client)