class ProbertTestStorage(testtools.TestCase): def setUp(self): super(ProbertTestStorage, self).setUp() with open(FAKE_PROBE_ALL_JSON) as f: self.results = json.load(f) self.storage = Storage(results=self.results) def test_storage_init(self): self.assertNotEqual(None, self.storage) def test_storage_get_devices(self): storage_keys = self.results.get('storage').keys() self.assertEqual(sorted(self.storage.get_devices()), sorted(storage_keys)) def test_storage_get_devices_no_storage(self): s = Storage() self.assertEqual([], s.get_devices()) def test_storage_get_devices_by_key(self): key = 'DEVTYPE' val = 'partition' plist_1 = self.storage.get_devices_by_key(key, val) plist_2 = [ p for p in self.results['storage'].keys() if self.results['storage'][p][key] == val ] self.assertEqual(sorted(plist_1), sorted(plist_2)) def test_storage_get_devices_by_key_invalid_key(self): key = 'lactobacillus' val = 'sourbeer' plist_1 = self.storage.get_devices_by_key(key, val) plist_2 = [] self.assertEqual(sorted(plist_1), sorted(plist_2)) def test_storage_get_devices_by_key_invalid_value(self): key = 'DEVTYPE' val = 'supercomputer' plist_1 = self.storage.get_devices_by_key(key, val) plist_2 = [] self.assertEqual(sorted(plist_1), sorted(plist_2)) def test_storage_get_partitions(self): device = '/dev/sda' plist_1 = self.storage.get_partitions(device) plist_2 = [ p for p in self.storage.get_devices_by_key('DEVTYPE', 'partition') if p.startswith(device) ] self.assertEqual(sorted(plist_1), sorted(plist_2)) def test_storage_get_partitions_no_parts(self): results = {'storage': {'/dev/sda': {'DEVTYPE': 'disk', 'MAJOR': '8'}}} s = Storage(results=results) device = '/dev/sda' self.assertEqual([], s.get_partitions(device)) def test_storage_get_disk_no_disk(self): s = Storage() self.assertEqual([], s.get_disks()) def test_storage_get_disks(self): disks = [ d for d in self.results['storage'].keys() if self.results['storage'][d]['MAJOR'] == '8' and self.results['storage'][d]['DEVTYPE'] == 'disk' ] self.assertEqual(sorted(self.storage.get_disks()), sorted(disks)) def test_storage_get_device_size(self): disk = self.storage.get_disks().pop() size = self.results['storage'][disk]['attrs']['size'] self.assertEqual(self.storage.get_device_size(disk), size)
def test_storage_get_partitions_no_parts(self): results = {'storage': {'/dev/sda': {'DEVTYPE': 'disk', 'MAJOR': '8'}}} s = Storage(results=results) device = '/dev/sda' self.assertEqual([], s.get_partitions(device))