本文整理汇总了Python中ovs.dal.hybrids.t_testdisk.TestDisk.storage方法的典型用法代码示例。如果您正苦于以下问题:Python TestDisk.storage方法的具体用法?Python TestDisk.storage怎么用?Python TestDisk.storage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.dal.hybrids.t_testdisk.TestDisk
的用法示例。
在下文中一共展示了TestDisk.storage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mandatory_fields
# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import storage [as 别名]
def test_mandatory_fields(self):
"""
Validates whether mandatory properties and relations work
"""
machine = TestMachine()
machine.extended = 'extended'
machine.name = 'machine'
machine.save()
disk = TestDisk()
# Modify relation to mandatory
[_ for _ in disk._relations if _.name == 'machine'][0].mandatory = True
# Continue test
disk.name = None
with self.assertRaises(MissingMandatoryFieldsException) as exception:
disk.save()
self.assertIn('name', exception.exception.message, 'Field name should be in exception message: {0}'.format(exception.exception.message))
self.assertIn('machine', exception.exception.message, 'Field machine should be in exception message: {0}'.format(exception.exception.message))
disk.name = 'disk'
disk.machine = machine
disk.save()
disk.description = 'test'
disk.storage = machine
disk.save()
# Restore relation
[_ for _ in disk._relations if _.name == 'machine'][0].mandatory = False
示例2: test_queries
# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import storage [as 别名]
def test_queries(self):
"""
Validates whether executing queries returns the expected results
"""
machine = TestMachine()
machine.name = 'machine'
machine.save()
for i in xrange(0, 20):
disk = TestDisk()
disk.name = 'test_{0}'.format(i)
disk.size = i
if i < 10:
disk.machine = machine
else:
disk.storage = machine
disk.save()
self.assertEqual(len(machine.disks), 10, 'query should find added machines')
# pylint: disable=line-too-long
list_1 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.EQUALS, 1)]}}).data # noqa
self.assertEqual(list_1, 1, 'list should contain int 1')
list_2 = DataList({'object': TestDisk,
'data': DataList.select.GUIDS,
'query': {'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.EQUALS, 1)]}}).data # noqa
found_object = Descriptor(TestDisk, list_2[0]).get_object(True)
self.assertEqual(found_object.name, 'test_1', 'list should contain correct machine')
list_3 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.GT, 3),
('size', DataList.operator.LT, 6)]}}).data # noqa
self.assertEqual(list_3, 2, 'list should contain int 2') # disk 4 and 5
list_4 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.OR,
'items': [('size', DataList.operator.LT, 3),
('size', DataList.operator.GT, 6)]}}).data # noqa
# at least disk 0, 1, 2, 7, 8, 9, 10-19
self.assertGreaterEqual(list_4, 16, 'list should contain >= 16')
list_5 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('machine.guid', DataList.operator.EQUALS, machine.guid), # noqa
{'type': DataList.where_operator.OR,
'items': [('size', DataList.operator.LT, 3),
('size', DataList.operator.GT, 6)]}]}}).data # noqa
self.assertEqual(list_5, 6, 'list should contain int 6') # disk 0, 1, 2, 7, 8, 9
list_6 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.LT, 3),
('size', DataList.operator.GT, 6)]}}).data # noqa
self.assertEqual(list_6, 0, 'list should contain int 0') # no disks
list_7 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.OR,
'items': [('machine.guid', DataList.operator.EQUALS, '123'), # noqa
('used_size', DataList.operator.EQUALS, -1),
{'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.GT, 3),
('size', DataList.operator.LT, 6)]}]}}).data # noqa
self.assertEqual(list_7, 2, 'list should contain int 2') # disk 4 and 5
list_8 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('machine.name', DataList.operator.EQUALS, 'machine'), # noqa
('name', DataList.operator.EQUALS, 'test_3')]}}).data # noqa
self.assertEqual(list_8, 1, 'list should contain int 1') # disk 3
list_9 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.GT, 3),
{'type': DataList.where_operator.AND,
'items': [('size', DataList.operator.LT, 6)]}]}}).data # noqa
self.assertEqual(list_9, 2, 'list should contain int 2') # disk 4 and 5
list_10 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.OR,
'items': [('size', DataList.operator.LT, 3),
{'type': DataList.where_operator.OR,
'items': [('size', DataList.operator.GT, 6)]}]}}).data # noqa
# at least disk 0, 1, 2, 7, 8, 9, 10-19
self.assertGreaterEqual(list_10, 16, 'list should contain >= 16')
list_11 = DataList({'object': TestDisk,
'data': DataList.select.COUNT,
'query': {'type': DataList.where_operator.AND,
'items': [('storage.name', DataList.operator.EQUALS, 'machine')]}}).data # noqa
self.assertEqual(list_11, 10, 'list should contain int 10') # disk 10-19