def distribute_test(self): manager = KickstartManager() module1 = TestModule(commands=["network", "firewall"]) module2 = TestModule(addons=["pony"]) module3 = TestModule(sections=["packages"]) module4 = TestModule(addons=["scorched"]) m1_observer = TestModuleObserver("1", "1", module1) m2_observer = TestModuleObserver("2", "2", module2) m3_observer = TestModuleObserver("3", "3", module3) unavailable_observer = TestModuleObserver("4", "4", module4) unavailable_observer._is_service_available = False manager.module_observers = [ m1_observer, m2_observer, m3_observer, unavailable_observer ] with self._create_ks_files(self._kickstart_include) as filename: manager.split(filename) errors = manager.distribute() self.assertEqual(module1.kickstart, self._m1_kickstart) self.assertEqual(module2.kickstart, self._m2_kickstart) self.assertEqual(module3.kickstart, self._m3_kickstart) self.assertEqual(module4.kickstart, "") self.assertEqual(manager.unprocessed_kickstart, self._unprocessed_kickstart) expected_errors = {("1", 5, 'ks.manager.test.include1.cfg'), ("3", 42, 'ks.manager.test.include.cfg')} actual_errors = set() for service_name, (lineno, file_name), _msg in errors: actual_errors.add((service_name, lineno, file_name)) self.assertEqual(actual_errors, expected_errors)
def distribute_test(self): manager = KickstartManager() module1 = TestModule(commands=["network", "firewall"]) module2 = TestModule(addons=["pony"]) module3 = TestModule(sections=["packages"]) module4 = TestModule(addons=["scorched"]) m1_observer = TestModuleObserver("1", "1", module1) m2_observer = TestModuleObserver("2", "2", module2) m3_observer = TestModuleObserver("3", "3", module3) unavailable_observer = TestModuleObserver("4", "4", module4) unavailable_observer._is_service_available = False manager.module_observers = [ m1_observer, m2_observer, m3_observer, unavailable_observer ] with self._create_ks_files(self._kickstart_include) as filename: manager.split(filename) errors = manager.distribute() self.assertEqual(module1.kickstart, self._m1_kickstart) self.assertEqual(module2.kickstart, self._m2_kickstart) self.assertEqual(module3.kickstart, self._m3_kickstart) self.assertEqual(module4.kickstart, "") self.assertEqual(manager.unprocessed_kickstart, self._unprocessed_kickstart) expected_errors = [{ "success": False, "error_message": "Mocked parse error: \"PARSE_ERROR\" found", "line_number": 5, "module_name": "1", "file_name": "ks.manager.test.include1.cfg" }, { "success": False, "error_message": "Mocked parse error: \"PARSE_ERROR\" found", "line_number": 41, "module_name": "3", "file_name": "ks.manager.test.include.cfg" }] self.assertEqual(errors, expected_errors)