def validate(TestCaseKey, StmTestCase, MethodologyKey, MethodologyJson, EnableResourceCheck): plLogger = PLLogger.GetLogger("methodology") plLogger.LogDebug("begin.validate.RunMethodologyTestCommand.") if TestCaseKey: # Check if test case key exists in installed methodologies test_case_handle, err_str = mm_utils.get_test_case_from_key(TestCaseKey) return err_str elif StmTestCase: hnd_reg = CHandleRegistry.Instance() test_case = hnd_reg.Find(StmTestCase) if test_case is None or not test_case.IsTypeOf("StmTestCase"): plLogger.LogError("Was unable to find StmTestCase with handle " + str(StmTestCase) + " in the system.") return "Could not find StmTestCase" else: # Must specify a key and json if not MethodologyKey or not MethodologyJson: return "Must specify a TestCaseKey, StmTestCase or MethodologyKey and MethodologyJson" # Validate against the schema this_cmd = get_this_cmd() res = json_utils.validate_json(MethodologyJson, this_cmd.Get("InputJsonSchema")) if res != "": return "Methodology JSON is invalid or does not conform to the schema: " + res # Load the json if it passes schema validation err_str, meth_json = json_utils.load_json(MethodologyJson) if err_str != "": return err_str # Check the MethodologyKey matches the meth key in the json if MethodologyKey != meth_json["methodology_key"]: return "Methodology Key does not match the methodology_key in the JSON" plLogger.LogDebug("end.validate.RunMethodologyTestCommand") return ""
except Exception, e: err_str = str(e) result = cmd.Get("PassFailState") TestCaseKey = cmd.Get("TestCaseKey") cmd.MarkDelete() # Verify create command passed if err_str or result is None or result != "PASSED": err_str = "Failed to create methodology test case. " + err_str plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False if TestCaseKey: # Get test case from installed methodologies StmTestCase, err_str = mm_utils.get_test_case_from_key(TestCaseKey) if err_str: plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False # Get the StmTestCase object test_case = hnd_reg.Find(StmTestCase) if test_case is None or not test_case.IsTypeOf("StmTestCase"): err_str = "Was unable to find StmTestCase with handle " + str(StmTestCase) + " in the system." plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False # Get the StmMethodology so we can get the meth key stm_meth = test_case.GetObject("StmMethodology", RelationType("ParentChild", 1))