def test_update_json_list_in_file_two_times(self):
        target_json_file = path.path("./json_out.json")
        if target_json_file.exists():
            target_json_file.remove()
        source_template_json_file = path.path(
            r"./src/wpsremote/xmpp_data/test/CMREOAA_MainConfigFile_template.json"
        )

        param1 = computation_job_param.ComputationJobParam(
            "minlat", "float", "par title", "min latitude")
        param2 = computation_job_param.ComputationJobParam(
            "maxlat", "float", "par title", "max latitude")

        inputs = computation_job_inputs.ComputationJobInputs()

        action1 = computational_job_input_action_update_json_file.ComputationalJobInputActionUpdateJSONFile(
            "minlat", target_json_file, "['Config']['latLim'][0]",
            source_template_json_file)

        inputs.add_input(param1)
        inputs.add_input(param2)

        inputs.set_values({"minlat": "75.5", "maxlat": "76.5"})
        action1.set_inputs(inputs)

        # check target_json_file
        json_text = target_json_file.text()
        j = json.loads(json_text)
        self.assertTrue(75.5, j['Config']['latLim'][0])
        self.assertTrue(76.5, j['Config']['latLim'][1])
    def test_update_json_file_action_with_string(self):
        os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__),
                                              '..')))
        target_json_file = path.path("./json_out.json")
        if target_json_file.exists():
            target_json_file.remove()
        source_template_json_file = path.path(
            r"./src/wpsremote/xmpp_data/test/CMREOAA_MainConfigFile_template.json"
        )

        param1 = computation_job_param.ComputationJobParam(
            "path_file_name", "string", "par 1", "path_file_name descr")
        inputs = computation_job_inputs.ComputationJobInputs()
        action1 = computational_job_input_action_update_json_file.ComputationalJobInputActionUpdateJSONFile(
            "path_file_name", target_json_file, "['Config']['pathFilename']",
            source_template_json_file)

        inputs.add_input(param1)
        inputs.set_values({"path_file_name": "thisIsOK.txt"})
        action1.set_inputs(inputs)

        # check target_json_file
        json_text = target_json_file.text()
        j = json.loads(json_text)
        self.assertTrue("thisIsOK.txt", j['Config']['pathFilename'])
    def test_update_json_file_action_with_int(self):
        target_json_file = path.path("./json_out.json")
        if target_json_file.exists():
            target_json_file.remove()
        source_template_json_file = path.path(
            r"./src/wpsremote/xmpp_data/test/CMREOAA_MainConfigFile_template.json"
        )

        param1 = computation_job_param.ComputationJobParam(
            "numberOfevaluations", "int", "par 1", "numberOfevaluations descr")
        inputs = computation_job_inputs.ComputationJobInputs()
        action1 = computational_job_input_action_update_json_file.ComputationalJobInputActionUpdateJSONFile(
            "numberOfevaluations", target_json_file,
            "['Config']['nEvaluations']", source_template_json_file)

        inputs.add_input(param1)
        inputs.set_values({"numberOfevaluations": "100"})
        action1.set_inputs(inputs)

        # check target_json_file
        json_text = target_json_file.text()
        j = json.loads(json_text)
        self.assertTrue(100, j['Config']['nEvaluations'])