def test_get_list_path_impl(self): path_list = ['src\\wpsremote\\xmpp_data\\test\\tmp\\123', 'src\\wpsremote\\xmpp_data\\test\\tmp'] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") items = config_instance.get_list_path_impl(cp, "Input1", "path_list") for i in items: self.assertIsInstance(i, path.path) self.assertIn(i, path_list)
def test_get_list_int_impl(self): int_list = [0, 1, 2, 3] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") items = config_instance.get_list_int_impl(cp, "Input1", "int_list") for i in items: self.assertIsInstance(i, int) self.assertIn(i, int_list)
def test_get_list_float_impl(self): float_list = [0.12, 1.6, 2.55, 3.4] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") items = config_instance.get_list_float_impl(cp, "Input1", "float_list") for i in items: self.assertIsInstance(i, float) self.assertIn(i, float_list)
def test_defaults(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") default_section = cp.defaults() self.assertIsNotNone(default_section) self.assertIsNotNone(default_section.items()) for d in default_section.items(): self.assertIn(d, TestConfigParser.DEFAULT_ITEMS)
def test_get_list_list_impl(self): list_list = [['item_0'], ['item_1'], ['item_2']] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") items = config_instance.get_list_list_impl(cp, "Input1", "list") for i in items: self.assertIsInstance(i, list) self.assertIn(i, list_list)
def setUp(self): self.remote_config = config_instance.create( "./src/wpsremote/xmpp_data/test/test_remote.config") self.xmpp_bus = XMPPBus(self.remote_config, "service_name", "service_name_namespace") self.xep_0045_plugin = self.xmpp_bus.xmpp.plugin["xep_0045"] self.from_obj_mock = mock.Mock()
def test_readfp(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") fp = open("./src/wpsremote/xmpp_data/test/service.config") cp.readfp(fp) fp.close() default_section = cp.defaults() for d in default_section.items(): if d == ('servicePassword', 'admin'): self.assertNotIn(d, TestConfigParser.DEFAULT_ITEMS)
def test_options(self): options = [ 'class', 'input_ref', 'alias', 'template', 'service', 'namespace', 'description', 'executable_path', 'executable_cmd', 'output_dir', 'unique_execution_id', 'workdir', 'active', 'max_running_time_seconds', 'servicepassword', 'process_weight' ] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") opts = cp.options("Action1") for o in opts: self.assertIn(o, options)
def test_items(self): items_list = [ ('service', 'Service'), ('namespace', 'default'), ('description', 'foo service'), ('executable_path', '\\code\\etl'), ('executable_cmd', 'python \\code\\etl\\etl.py'), ('output_dir', 'src\\wpsremote\\xmpp_data\\test\\tmp'), ('unique_execution_id', '123'), ('workdir', 'src\\wpsremote\\xmpp_data\\test\\tmp\\123'), ('active', 'True'), ('max_running_time_seconds', '10'), ('servicepassword', 'admin'), ('class', 'updateJSONfile'), ('input_ref', 'timeHorizon'), ('source_filepath', '.\\configs\\OAAonDemand\\CMREOAA_MainConfigFile_template.json'), ('target_filepath', 'src\\wpsremote\\xmpp_data\\test\\tmp\\123\\config.json'), ('json_path_expr', "['Config']['timeHorizon']"), ('process_weight', '{"weight": "10", "coefficient": "1.5"}') ] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") for i in cp.items("Action3"): self.assertIn(i, items_list)
def setUp(self): os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) self.remote_config = config_instance.create( "./src/wpsremote/xmpp_data/test/test_remote.config" ) self.xmpp_bus = XMPPBus(self.remote_config, "service_name", "service_name_namespace") self.xep_0045_plugin = self.xmpp_bus.xmpp.plugin["xep_0045"] self.from_obj_mock = mock.Mock() self.from_obj_mock.__class__ = mock.Mock rooms = { self.xmpp_bus._get_MUC_JId(): { "resource": { "role": "not_visitor" } } } self.xep_0045_plugin.rooms = rooms self.from_obj_mock.resource = "resource" test_msg = pickle.dumps({ "test_message": "test message" }) msg = { "type": "normal", "body": "topic=request&id=123&baseURL=test_base_url&message={}".format(test_msg), "from": self.from_obj_mock } # ExecuteMessage self.execute_message = self.xmpp_bus.CreateIndipendentMessage(msg) # cleaner Resource.clean_up_all = staticmethod(mock_clean_up_all) self.cleaner = Resource() # monitor resource_monitor.ResourceMonitor = MockResourceMonitor # wps agent args self.params_file = "./src/wpsremote/xmpp_data/test/test_params.p" pickle.dump( self.execute_message, open(self.params_file, "wb") ) self.args = Namespace( executionid=None, logconf='./src/wpsremote/xmpp_data/test/logger_test.properties', params=self.params_file, remoteconfig='./src/wpsremote/xmpp_data/test/test_remote.config', runtype='service', serviceconfig='./src/wpsremote/xmpp_data/test/test_service.config' )
def test_copy_INI_file_add_param(self): copy_path = "./src/wpsremote/xmpp_data/test/copy_of_test_service.config" param_dict = { "source": "./src/wpsremote/xmpp_data/test/test_service.config", "target": copy_path, "param_section": "Input3", "param_name": "another_param", "param_value_ref": "input3_another_param" } cifap = CopyINIFileAddParam(param_dict) input_values = { "input3_another_param": "Another value" } self.assertFalse(os.path.isfile(copy_path)) cifap.execute(input_values) self.assertTrue(os.path.isfile(copy_path)) config = config_instance.create(copy_path) self.assertEqual("Another value", config.get("Input3", "another_param")) os.remove(copy_path)
def test_create_config_parser(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertIsNotNone(cp) self.assertIsInstance(cp, ConfigParser.ConfigParser)
def test_set(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertTrue(cp.getboolean("DEFAULT", "active")) cp.set("DEFAULT", "active", "False") self.assertFalse(cp.getboolean("DEFAULT", "active"))
def test_has_option(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertTrue(cp.has_option("DEFAULT", "active"))
def test_remove_section(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertTrue(cp.has_section("Action1")) cp.remove_section("Action1") self.assertFalse(cp.has_section("Action1"))
def test_get(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertEqual("admin", cp.get("DEFAULT", "servicePassword"))
def test_items_without_defaults(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") for section in TestConfigParser.CONFIG_SECTIONS: items = config_instance.items_without_defaults(cp, section, raw=False) for i in items: self.assertNotIn(i, TestConfigParser.DEFAULT_ITEMS)
def test_read(self): filenames = ["./src/wpsremote/xmpp_data/test/service.config"] cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") fn = cp.read("./src/wpsremote/xmpp_data/test/service.config") self.assertEqual(fn, filenames)
def test_has_section(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertTrue(cp.has_section("Input1"))
def test_add_section(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertRaises(DuplicateSectionError, lambda: cp.add_section("Input1")) self.assertNotIn("Input5", cp.sections()) cp.add_section("Input5") self.assertIn("Input5", cp.sections())
def test_get_path(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") item = config_instance.get_path(cp, "DEFAULT", "output_dir") self.assertIsInstance(item, path.path) self.assertEqual("src\\wpsremote\\xmpp_data\\test\\tmp", item)
def test_sections(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") sections = cp.sections() self.assertIsNotNone(sections) for s in sections: self.assertIn(s, TestConfigParser.CONFIG_SECTIONS)
def test_getboolean(self): cp = config_instance.create("./src/wpsremote/xmpp_data/test/test_service.config") self.assertIs(True, cp.getboolean("DEFAULT", "active"))