OLD | NEW |
(Empty) | |
| 1 import mock |
| 2 import unittest |
| 3 |
| 4 from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping |
| 5 |
| 6 class BlockDeviceTypeTests(unittest.TestCase): |
| 7 def setUp(self): |
| 8 self.block_device_type = BlockDeviceType() |
| 9 |
| 10 def check_that_attribute_has_been_set(self, name, value, attribute): |
| 11 self.block_device_type.endElement(name, value, None) |
| 12 self.assertEqual(getattr(self.block_device_type, attribute), value) |
| 13 |
| 14 def test_endElement_sets_correct_attributes_with_values(self): |
| 15 for arguments in [("volumeId", 1, "volume_id"), |
| 16 ("virtualName", "some name", "ephemeral_name"), |
| 17 ("snapshotId", 1, "snapshot_id"), |
| 18 ("volumeSize", 1, "size"), |
| 19 ("status", "some status", "status"), |
| 20 ("attachTime", 1, "attach_time"), |
| 21 ("somethingRandom", "somethingRandom", "somethingRando
m")]: |
| 22 self.check_that_attribute_has_been_set(arguments[0], arguments[1], a
rguments[2]) |
| 23 |
| 24 def test_endElement_with_name_NoDevice_value_true(self): |
| 25 self.block_device_type.endElement("NoDevice", 'true', None) |
| 26 self.assertEqual(self.block_device_type.no_device, True) |
| 27 |
| 28 def test_endElement_with_name_NoDevice_value_other(self): |
| 29 self.block_device_type.endElement("NoDevice", 'something else', None) |
| 30 self.assertEqual(self.block_device_type.no_device, False) |
| 31 |
| 32 def test_endElement_with_name_deleteOnTermination_value_true(self): |
| 33 self.block_device_type.endElement("deleteOnTermination", "true", None) |
| 34 self.assertEqual(self.block_device_type.delete_on_termination, True) |
| 35 |
| 36 def test_endElement_with_name_deleteOnTermination_value_other(self): |
| 37 self.block_device_type.endElement("deleteOnTermination", 'something else
', None) |
| 38 self.assertEqual(self.block_device_type.delete_on_termination, False) |
| 39 |
| 40 class BlockDeviceMappingTests(unittest.TestCase): |
| 41 def setUp(self): |
| 42 self.block_device_mapping = BlockDeviceMapping() |
| 43 |
| 44 def block_device_type_eq(self, b1, b2): |
| 45 if isinstance(b1, BlockDeviceType) and isinstance(b2, BlockDeviceType): |
| 46 return all([b1.connection == b2.connection, |
| 47 b1.ephemeral_name == b2.ephemeral_name, |
| 48 b1.no_device == b2.no_device, |
| 49 b1.volume_id == b2.volume_id, |
| 50 b1.snapshot_id == b2.snapshot_id, |
| 51 b1.status == b2.status, |
| 52 b1.attach_time == b2.attach_time, |
| 53 b1.delete_on_termination == b2.delete_on_termination, |
| 54 b1.size == b2.size]) |
| 55 |
| 56 def test_startElement_with_name_ebs_sets_and_returns_current_value(self): |
| 57 retval = self.block_device_mapping.startElement("ebs", None, None) |
| 58 assert self.block_device_type_eq(retval, BlockDeviceType(self.block_devi
ce_mapping)) |
| 59 |
| 60 def test_startElement_with_name_virtualName_sets_and_returns_current_value(s
elf): |
| 61 retval = self.block_device_mapping.startElement("virtualName", None, Non
e) |
| 62 assert self.block_device_type_eq(retval, BlockDeviceType(self.block_devi
ce_mapping)) |
| 63 |
| 64 def test_endElement_with_name_device_sets_current_name(self): |
| 65 self.block_device_mapping.endElement("device", "/dev/null", None) |
| 66 self.assertEqual(self.block_device_mapping.current_name, "/dev/null") |
| 67 |
| 68 def test_endElement_with_name_device_sets_current_name(self): |
| 69 self.block_device_mapping.endElement("deviceName", "some device name", N
one) |
| 70 self.assertEqual(self.block_device_mapping.current_name, "some device na
me") |
| 71 |
| 72 def test_endElement_with_name_item_sets_current_name_key_to_current_value(se
lf): |
| 73 self.block_device_mapping.current_name = "some name" |
| 74 self.block_device_mapping.current_value = "some value" |
| 75 self.block_device_mapping.endElement("item", "some item", None) |
| 76 self.assertEqual(self.block_device_mapping["some name"], "some value") |
| 77 |
| 78 if __name__ == "__main__": |
| 79 unittest.main() |
OLD | NEW |