当前位置: 首页>>代码示例>>Python>>正文


Python TestDisk.save方法代码示例

本文整理汇总了Python中ovs.dal.hybrids.t_testdisk.TestDisk.save方法的典型用法代码示例。如果您正苦于以下问题:Python TestDisk.save方法的具体用法?Python TestDisk.save怎么用?Python TestDisk.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ovs.dal.hybrids.t_testdisk.TestDisk的用法示例。


在下文中一共展示了TestDisk.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_invalidqueries

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_invalidqueries(self):
     """
     Validates invalid queries
     """
     machine = TestMachine()
     machine.name = 'machine'
     machine.save()
     disk = TestDisk()
     disk.name = 'disk'
     disk.machine = machine
     disk.save()
     setattr(DataList.select, 'SOMETHING', 'SOMETHING')
     with self.assertRaises(NotImplementedError):
         DataList({'object': TestDisk,
                   'data': DataList.select.SOMETHING,
                   'query': {'type': DataList.where_operator.AND,
                             'items': [('machine.name', DataList.operator.EQUALS, 'machine')]}})  # noqa
     setattr(DataList.where_operator, 'SOMETHING', 'SOMETHING')
     with self.assertRaises(NotImplementedError):
         DataList({'object': TestDisk,
                   'data': DataList.select.COUNT,
                   'query': {'type': DataList.where_operator.SOMETHING,
                             'items': [('machine.name', DataList.operator.EQUALS, 'machine')]}})  # noqa
     setattr(DataList.operator, 'SOMETHING', 'SOMETHING')
     with self.assertRaises(NotImplementedError):
         DataList({'object': TestDisk,
                   'data': DataList.select.COUNT,
                   'query': {'type': DataList.where_operator.AND,
                             'items': [('machine.name', DataList.operator.SOMETHING, 'machine')]}})  # noqa
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:31,代码来源:test_basic.py

示例2: test_recursive

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_recursive(self):
     """
     Validates the recursive save
     """
     machine = TestMachine()
     machine.name = 'original'
     machine.save()
     disks = []
     for i in xrange(0, 10):
         disk = TestDisk()
         disk.name = 'test_{0}'.format(i)
         if i % 2:
             disk.machine = machine
         else:
             disk.machine = machine
             self.assertEqual(disk.machine.name, 'original', 'child should be set')
             disk.machine = None
             self.assertIsNone(disk.machine, 'child should be cleared')
             disks.append(disk)
         disk.save()
     counter = 1
     for disk in machine.disks:
         disk.size = counter
         counter += 1
     machine.save(recursive=True)
     disk = TestDisk(machine.disks[0].guid)
     self.assertEqual(disk.size, 1, 'lists should be saved recursively')
     disk.machine.name = 'mtest'
     disk.save(recursive=True)
     machine2 = TestMachine(machine.guid)
     self.assertEqual(machine2.disks[1].size, 2, 'lists should be saved recursively')
     self.assertEqual(machine2.name, 'mtest', 'properties should be saved recursively')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:34,代码来源:test_basic.py

示例3: test_preinit

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_preinit(self):
     """
     Validates whether initial data is loaded on object creation
     """
     disk = TestDisk(data={'name': 'diskx'})
     disk.save()
     self.assertEqual(disk.name, 'diskx', 'Disk name should be preloaded')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:9,代码来源:test_basic.py

示例4: test_copy

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_copy(self):
     """
     Validates whether the copy function works correct
     """
     machine = TestMachine()
     machine.name = 'testmachine1'
     machine.save()
     disk1 = TestDisk()
     disk1.name = 'test1'
     disk1.size = 100
     disk1.order = 1
     disk1.type = 'ONE'
     disk1.machine = machine
     disk1.save()
     disk2 = TestDisk()
     disk2.copy(disk1)
     self.assertEqual(disk2.name, 'test1', 'Properties should be copied')
     self.assertEqual(disk2.size, 100, 'Properties should be copied')
     self.assertEqual(disk2.order, 1, 'Properties should be copied')
     self.assertEqual(disk2.type, 'ONE', 'Properties should be copied')
     self.assertEqual(disk2.machine, None, 'Relations should not be copied')
     disk3 = TestDisk()
     disk3.copy(disk1, include_relations=True)
     self.assertEqual(disk3.machine.name, 'testmachine1', 'Relations should be copied')
     disk4 = TestDisk()
     disk4.copy(disk1, include=['name'])
     self.assertEqual(disk4.name, 'test1', 'Name should be copied')
     self.assertEqual(disk4.size, 0, 'Size should not be copied')
     self.assertEqual(disk4.machine, None, 'Relations should not be copied')
     disk5 = TestDisk()
     disk5.copy(disk1, exclude=['name'])
     self.assertEqual(disk5.name, None, 'Name should not be copied')
     self.assertEqual(disk5.size, 100, 'Size should be copied')
     self.assertEqual(disk5.machine, None, 'Relations should not be copied')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:36,代码来源:test_basic.py

示例5: test_dol_advanced

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_dol_advanced(self):
     """
     Validates the DataObjectList advanced functions (indexer, sort)
     """
     sizes = [7, 2, 0, 4, 6, 1, 5, 9, 3, 8]
     guids = []
     for i in xrange(0, 10):
         disk = TestDisk()
         disk.name = 'disk_{0}'.format(i)
         disk.size = sizes[i]
         disk.save()
         guids.append(disk.guid)
     data = DataList({'object': TestDisk,
                      'data': DataList.select.GUIDS,
                      'query': {'type': DataList.where_operator.AND,
                                'items': []}}).data
     disks = DataObjectList(data, TestDisk)
     disks.sort()
     guids.sort()
     self.assertEqual(disks[0].guid, guids[0], 'Disks should be sorted on guid')
     self.assertEqual(disks[4].guid, guids[4], 'Disks should be sorted on guid')
     disks.sort(cmp=lambda a, b: a.size - b.size)
     self.assertEqual(disks[0].size, 0, 'Disks should be sorted on size')
     self.assertEqual(disks[4].size, 4, 'Disks should be sorted on size')
     disks.sort(key=lambda a: a.name)
     self.assertEqual(disks[0].name, 'disk_0', 'Disks should be sorted on name')
     self.assertEqual(disks[4].name, 'disk_4', 'Disks should be sorted on name')
     filtered = disks[1:4]
     self.assertEqual(filtered[0].name, 'disk_1', 'Disks should be properly sliced')
     self.assertEqual(filtered[2].name, 'disk_3', 'Disks should be properly sliced')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:32,代码来源:test_basic.py

示例6: inject_new

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def inject_new(datalist_object):
     """
     Creates a new object
     """
     _ = datalist_object
     disk_x = TestDisk()
     disk_x.name = 'test'
     disk_x.save()
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:10,代码来源:test_basic.py

示例7: test_save_deleted

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_save_deleted(self):
     """
     Validates whether saving a previously deleted object raises
     """
     disk = TestDisk()
     disk.name = 'disk'
     disk.save()
     disk.delete()
     self.assertRaises(ObjectNotFoundException, disk.save, 'Cannot resave a deleted object')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:11,代码来源:test_basic.py

示例8: test_primarykeyvalidation

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_primarykeyvalidation(self):
     """
     Validates whether the passed in key (guid) of an object is validated
     """
     self.assertRaises(ValueError, TestDisk, 'foo', None)
     disk = TestDisk()  # Should not raise
     disk.name = 'disk'
     disk.save()
     _ = TestDisk(disk.guid)  # Should not raise
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:11,代码来源:test_basic.py

示例9: test_clearedcache

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_clearedcache(self):
     """
     Validates the correct behavior when the volatile cache is cleared
     """
     disk = TestDisk()
     disk.name = 'somedisk'
     disk.save()
     VolatileFactory.store.delete(disk._key)
     disk2 = TestDisk(disk.guid)
     self.assertEqual(disk2.name, 'somedisk', 'Disk should be fetched from persistent store')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:12,代码来源:test_basic.py

示例10: test_discard

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_discard(self):
     """
     Validates the behavior regarding pending changes discard
     """
     disk = TestDisk()
     disk.name = 'one'
     disk.save()
     disk.name = 'two'
     # Discarding an object should rollback all changes
     disk.discard()
     self.assertEqual(disk.name, 'one', 'Data should be discarded')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:13,代码来源:test_basic.py

示例11: test_datapersistent

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_datapersistent(self):
     """
     Validates whether data is persisted correctly
     """
     disk = TestDisk()
     guid = disk.guid
     disk.name = 'test'
     disk.save()
     # Retreiving an object should return the data as when it was saved
     disk2 = TestDisk(guid)
     self.assertEqual(disk.name, disk2.name, 'Data should be persistent')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:13,代码来源:test_basic.py

示例12: test_newobject_delete

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_newobject_delete(self):
     """
     Validates the behavior on object deletions
     """
     disk = TestDisk()
     disk.name = 'disk'
     disk.save()
     # An object should always have a guid
     guid = disk.guid
     self.assertIsNotNone(guid, 'Guid should not be None')
     # After deleting, the object should not be retreivable
     disk.delete()
     self.assertRaises(Exception, TestDisk, guid, None)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:15,代码来源:test_basic.py

示例13: test_datastoreraises

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_datastoreraises(self):
     """
     Validates the "datastore_wins" behavior in the usecase where it's supposed to raise
     """
     disk = TestDisk()
     disk.name = 'initial'
     disk.save()
     disk2 = TestDisk(disk.guid, datastore_wins=None)
     disk.name = 'one'
     disk.save()
     disk2.name = 'two'
     # with datastore_wins set to None, concurrency conflicts are raised
     self.assertRaises(ConcurrencyException, disk2.save)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:15,代码来源:test_basic.py

示例14: test_saveorder

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_saveorder(self):
     """
     Validates whether the order of saving related objects doesn't matter
     """
     machine1 = TestMachine()
     machine1.name = 'machine'
     disk1_1 = TestDisk()
     disk1_1.name = 'disk1'
     disk1_1.machine = machine1
     disk1_1.save()
     disk1_2 = TestDisk()
     disk1_2.name = 'disk2'
     disk1_2.machine = machine1
     disk1_2.save()
     machine1.save()
     self.assertEqual(len(machine1.disks), 2, 'There should be two disks. {0}'.format(len(machine1.disks)))
     machine2 = TestMachine()
     machine2.name = 'machine'
     machine2.save()
     disk2_1 = TestDisk()
     disk2_1.name = 'disk1'
     disk2_1.machine = machine2
     disk2_1.save()
     disk2_2 = TestDisk()
     disk2_2.name = 'disk2'
     disk2_2.machine = machine2
     disk2_2.save()
     self.assertEqual(len(machine2.disks), 2, 'There should be two disks. {0}'.format(len(machine2.disks)))
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:30,代码来源:test_basic.py

示例15: test_ownrelations

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import save [as 别名]
 def test_ownrelations(self):
     """
     Validates whether relations to the object itself are working
     """
     pdisk = TestDisk()
     pdisk.name = 'parent'
     pdisk.save()
     cdisk1 = TestDisk()
     cdisk1.name = 'child 1'
     cdisk1.size = 100
     cdisk1.parent = pdisk
     cdisk1.save()
     cdisk2 = TestDisk()
     cdisk2.name = 'child 2'
     cdisk2.size = 100
     cdisk2.parent = pdisk
     cdisk2.save()
     self.assertEqual(len(pdisk.children), 2, 'There should be 2 children ({0})'.format(len(pdisk.children)))
     self.assertEqual(cdisk1.parent.name, 'parent', 'Parent should be loaded correctly')
     data = DataList({'object': TestDisk,
                      'data': DataList.select.GUIDS,
                      'query': {'type': DataList.where_operator.AND,
                                'items': [('parent.name', DataList.operator.EQUALS, 'parent')]}}).data
     datalist = DataObjectList(data, TestDisk)
     self.assertEqual(len(datalist), 2, 'There should be two items ({0})'.format(len(datalist)))
     cdisk2.parent = None
     cdisk2.save()
     data = DataList({'object': TestDisk,
                      'data': DataList.select.GUIDS,
                      'query': {'type': DataList.where_operator.AND,
                                'items': [('parent.name', DataList.operator.EQUALS, 'parent')]}}).data
     datalist = DataObjectList(data, TestDisk)
     self.assertEqual(len(datalist), 1, 'There should be one item ({0})'.format(len(datalist)))
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:35,代码来源:test_basic.py


注:本文中的ovs.dal.hybrids.t_testdisk.TestDisk.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。