本文整理汇总了Python中ovs.dal.hybrids.t_testdisk.TestDisk类的典型用法代码示例。如果您正苦于以下问题:Python TestDisk类的具体用法?Python TestDisk怎么用?Python TestDisk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestDisk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalidqueries
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
示例2: test_preinit
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')
示例3: test_dol_advanced
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')
示例4: _clean_all
def _clean_all(self):
"""
Cleans all disks and machines
"""
machine = TestMachine()
prefix = '{0}_{1}_'.format(DataObject.NAMESPACE, machine._classname)
keys = self.persistent.prefix(prefix)
for key in keys:
try:
guid = key.replace(prefix, '')
machine = TestMachine(guid)
for disk in machine.disks:
disk.delete()
machine.delete()
except (ObjectNotFoundException, ValueError):
pass
for key in self.persistent.prefix('ovs_reverseindex_{0}'.format(machine._classname)):
self.persistent.delete(key)
disk = TestDisk()
prefix = '{0}_{1}_'.format(DataObject.NAMESPACE, disk._classname)
keys = self.persistent.prefix(prefix)
for key in keys:
try:
guid = key.replace(prefix, '')
disk = TestDisk(guid)
disk.delete()
except (ObjectNotFoundException, ValueError):
pass
for key in self.persistent.prefix('ovs_reverseindex_{0}'.format(disk._classname)):
self.persistent.delete(key)
示例5: inject_new
def inject_new(datalist_object):
"""
Creates a new object
"""
_ = datalist_object
disk_x = TestDisk()
disk_x.name = 'test'
disk_x.save()
示例6: test_invalidpropertyassignment
def test_invalidpropertyassignment(self):
"""
Validates whether the correct exception is raised when properties are assigned with a wrong
type
"""
disk = TestDisk()
disk.size = 100
with self.assertRaises(TypeError):
disk.machine = TestDisk()
示例7: test_primarykeyvalidation
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
示例8: test_updateproperty
def test_updateproperty(self):
"""
Validates the behavior regarding updating properties
"""
disk = TestDisk()
disk.name = 'test'
disk.description = 'desc'
# A property should be writable
self.assertIs(disk.name, 'test', 'Property should be updated')
self.assertIs(disk.description, 'desc', 'Property should be updated')
示例9: test_clearedcache
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')
示例10: test_datapersistent
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')
示例11: test_volatileproperty
def test_volatileproperty(self):
"""
Validates the volatile behavior of dynamic properties
"""
disk = TestDisk()
disk.size = 1000000
value = disk.used_size
# Volatile properties should be stored for the correct amount of time
time.sleep(2)
self.assertEqual(disk.used_size, value, 'Value should still be from cache')
time.sleep(2)
self.assertEqual(disk.used_size, value, 'Value should still be from cache')
time.sleep(2)
# ... after which they should be reloaded from the backend
self.assertNotEqual(disk.used_size, value, 'Value should be different')
示例12: test_relation_inheritance
def test_relation_inheritance(self):
"""
Validates whether relations on inherited hybrids behave OK
"""
machine = TestMachine()
machine.name = 'machine'
machine.save()
disk = TestDisk()
disk.name = 'disk'
disk.machine = machine # Validates relation acceptance (accepts TestEMachine)
disk.save()
machine.the_disk = disk # Validates whether _relations is build correctly
machine.save()
disk2 = TestDisk(disk.guid)
self.assertEqual(Descriptor(disk2.machine.__class__), Descriptor(TestEMachine), 'The machine should be a TestEMachine')
示例13: test_datastoreraises
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)
示例14: test_reduceddatalist
def test_reduceddatalist(self):
"""
Validates the reduced list
"""
disk = TestDisk()
disk.name = 'test'
disk.save()
data = DataList({'object': TestDisk,
'data': DataList.select.GUIDS,
'query': {'type': DataList.where_operator.AND,
'items': []}}).data
datalist = DataObjectList(data, TestDisk)
self.assertEqual(len(datalist), 1, 'There should be only one item ({0})'.format(len(datalist)))
item = datalist.reduced[0]
with self.assertRaises(AttributeError):
print item.name
self.assertEqual(item.guid, disk.guid, 'The guid should be available')
示例15: test_persistency
def test_persistency(self):
"""
Validates whether the object is fetches from the correct storage backend
"""
disk = TestDisk()
disk.name = 'test'
disk.save()
# Right after a save, the cache is invalidated
disk2 = TestDisk(disk.guid)
self.assertFalse(disk2._metadata['cache'], 'Object should be retreived from persistent backend')
# Subsequent calls will retreive the object from cache
disk3 = TestDisk(disk.guid)
self.assertTrue(disk3._metadata['cache'], 'Object should be retreived from cache')
# After the object expiry passed, it will be retreived from backend again
DummyVolatileStore().delete(disk._key) # We clear the entry
disk4 = TestDisk(disk.guid)
self.assertFalse(disk4._metadata['cache'], 'Object should be retreived from persistent backend')