def test_empty_force_no_source(self): slot_dict = OrderedDict({"interface": "content"}) slot_name = "slot-test" slot = ContentSlot(use_source_key=False, slot_name=slot_name) self.assertEqual(slot_dict, slot.to_yaml_object()) self.assertEqual(slot_name, slot.slot_name) self.assertRaises(errors.SlotValidationError, slot.validate) self.assertEqual(set(), slot.get_content_dirs(installed_path=""))
def test_empty(self): slot_dict = OrderedDict({"interface": "content"}) slot_name = "slot-test" slot = ContentSlot(slot_name=slot_name) # "use_source_key" is default, account for that. transformed_dict = slot_dict.copy() transformed_dict["source"] = {} self.assertEqual(transformed_dict, slot.to_yaml_object()) self.assertEqual(slot_name, slot.slot_name) self.assertRaises(errors.SlotValidationError, slot.validate) self.assertEqual(set(), slot.get_content_dirs(installed_path=""))
def test_explicit_content(self): slot_dict = OrderedDict({ "interface": "content", "content": "content-test" }) slot_name = "slot-test" slot = ContentSlot.from_dict(slot_dict=slot_dict, slot_name=slot_name) assert slot_dict == slot.to_yaml_object()
def test_write_from_dict(self): slot_dict = OrderedDict({ "interface": "content", "write": ["some/path"] }) slot_name = "slot-test" slot = ContentSlot.from_dict(slot_dict=slot_dict, slot_name=slot_name) slot.validate() self.assertEqual(slot_dict, slot.to_yaml_object()) self.assertEqual(slot_name, slot.slot_name) self.assertEqual(slot_dict["write"], slot.write) self.assertEqual(set(slot_dict["write"]), slot.get_content_dirs(installed_path=""))
def test_read_from_dict(self): slot_dict = OrderedDict({ "interface": "content", "content": "explicit-content", "read": ["some/path"], }) slot_name = "slot-test" slot = ContentSlot.from_dict(slot_dict=slot_dict, slot_name=slot_name) slot.validate() self.assertEqual(slot_dict, slot.to_yaml_object()) self.assertEqual(slot_name, slot.slot_name) self.assertEqual(slot_dict["read"], slot.read) self.assertEqual(set(slot_dict["read"]), slot.get_content_dirs(installed_path="")) self.assertEqual(slot_dict["content"], slot.content)
def test_write_from_dict_force_source_key(self): slot_dict = OrderedDict({ "interface": "content", "write": ["some/path"] }) slot_name = "slot-test" slot = ContentSlot.from_dict(slot_dict=slot_dict, slot_name=slot_name) slot.use_source_key = True slot.validate() transformed_dict = slot_dict.copy() transformed_dict["source"] = dict() transformed_dict["source"]["write"] = transformed_dict.pop("write") self.assertEqual(transformed_dict, slot.to_yaml_object()) self.assertEqual(slot_name, slot.slot_name) self.assertEqual(slot_dict["write"], slot.write) self.assertEqual(set(slot_dict["write"]), slot.get_content_dirs(installed_path=""))