def test_can_add_hardware_identifier(self): manager = SupportedHardwareManager() hardware = 'PowerX' self.assertEqual(len(manager), 0) manager.add(hardware) self.assertEqual(len(manager), 1) self.assertIn(hardware, manager)
def create_package(self): pkg = Package(version=self.version, product=self.product) pkg.objects.create(self.obj_options) pkg.supported_hardware.add(self.hardware) # control supported hardware hw = SupportedHardwareManager() hw.add(self.hardware) # control objects objs = ObjectsManager() objs.create(self.obj_options) return pkg, hw, objs
def test_can_compare_managers(self): manager1 = SupportedHardwareManager() manager2 = SupportedHardwareManager() self.assertEqual(manager1, manager2) manager1.add('hardware') self.assertNotEqual(manager1, manager2) manager2.add('hardware') self.assertEqual(manager1, manager2)
def test_can_create_package_from_dump(self): dump = { 'product': self.product, 'version': self.version, } # Supported hardware hardware_dump = {'supported-hardware': 'any'} dump.update(hardware_dump) hardware = SupportedHardwareManager(dump=hardware_dump) # Objects object_dump = { 'filename': self.obj_fn, 'mode': 'copy', 'target-type': 'device', 'target': '/dev/sda', 'target-path': '/boot', 'filesystem': 'ext4', } objects_dump = {'objects': [[object_dump], [object_dump]]} dump.update(objects_dump) objects = ObjectsManager(dump=objects_dump) pkg = Package(dump=dump) self.assertEqual(pkg.version, self.version) self.assertEqual(pkg.product, self.product) self.assertEqual(pkg.supported_hardware, hardware) self.assertEqual(pkg.objects, objects)
def test_can_construct_from_dump_when_some(self): manager = SupportedHardwareManager(dump={ 'supported-hardware': ['h1', 'h2'], }) self.assertEqual(len(manager), 2) self.assertIn('h1', manager) self.assertIn('h2', manager)
def test_can_remove_hardware_identifier(self): manager = SupportedHardwareManager() manager.add('PowerX') manager.add('PowerY') self.assertEqual(len(manager), 2) manager.remove('PowerX') self.assertEqual(len(manager), 1) manager.remove('PowerY') self.assertEqual(len(manager), 0)
def test_can_serialize_as_metadata_when_some(self): manager = SupportedHardwareManager() manager.add('PowerZ') manager.add('PowerY') manager.add('PowerX') expected = {'supported-hardware': ['PowerX', 'PowerY', 'PowerZ']} observed = manager.to_metadata() self.assertEqual(observed, expected)
def test_construct_from_dump_raises_error_when_invalid(self): invalid_dumps = [ {}, {'supported-hardware': None}, {'supported-hardware': 'other'}, {'supported-hardware': 42}, ] for dump in invalid_dumps: with self.assertRaises(ValueError, msg=SUPPORTED_HARDWARE_ERROR): SupportedHardwareManager(dump=dump)
def test_can_reset_list_of_hardware_identifiers(self): manager = SupportedHardwareManager() manager.add('h1') manager.add('h2') self.assertEqual(len(manager), 2) manager.reset() self.assertEqual(len(manager), 0)
def test_can_serialize_manager_as_string_when_some(self): manager = SupportedHardwareManager() manager.add('PowerX') manager.add('PowerY') manager.add('PowerZ') with open('tests/core/fixtures/hardware/string_some.txt') as fp: expected = fp.read().strip() observed = str(manager) self.assertEqual(observed, expected)
def test_can_create_package(self): pkg = Package(version=self.version, product=self.product) self.assertEqual(pkg.version, self.version) self.assertEqual(pkg.product, self.product) self.assertEqual(pkg.objects, ObjectsManager()) self.assertEqual(pkg.supported_hardware, SupportedHardwareManager())
def test_can_serialize_as_metadata_when_any(self): manager = SupportedHardwareManager() expected = {'supported-hardware': 'any'} observed = manager.to_metadata() self.assertEqual(observed, expected)
def test_can_serialize_as_template_when_any(self): manager = SupportedHardwareManager() expected = {'supported-hardware': 'any'} observed = manager.to_template() self.assertEqual(expected, observed)
def test_can_serialize_as_template_when_some(self): manager = SupportedHardwareManager() manager.add('PowerX') expected = {'supported-hardware': ['PowerX']} observed = manager.to_template() self.assertEqual(expected, observed)
def test_can_construct_from_dump_when_any(self): manager = SupportedHardwareManager(dump={ 'supported-hardware': ANY, }) self.assertEqual(len(manager), 0)
def test_cant_remove_unknown_hardware_identifier(self): manager = SupportedHardwareManager() with self.assertRaises(KeyError): manager.remove('unknown-hardware')
def test_cant_add_same_hardware_identifier_twice(self): manager = SupportedHardwareManager() manager.add('PowerX') manager.add('PowerX') self.assertEqual(len(manager), 1)