def get_model_graph(data: Dict[str, Any]) -> Graph: """Get model graph.""" graph_reader = GraphReader() return graph_reader.read( model_path=RequestDataProcessor.get_string_value(data, "path"), expanded_groups=data.get("group", []), )
def test_get_string_value_with_single_value(self) -> None: """Test get_string_value when single value was provided.""" expected = "expected_value" data = { "requested_key": [expected], } self.assertEqual( "expected_value", RequestDataProcessor.get_string_value(data, "requested_key"), )
def get_code_template(data: dict) -> Response: """Get code template file for requested Workload.""" workload_id = RequestDataProcessor.get_string_value(data, "workload_id") workdir = Workdir() workload_data = workdir.get_workload_data(workload_id) code_template_path = workload_data.get("code_template_path") if not code_template_path: raise NotFoundException(f"Unable to find code template file for {workload_id}") return ResponseGenerator.serve_from_filesystem( path=code_template_path, mimetype="text/x-python", )
def test_get_string_value_with_multiple_values(self) -> None: """Test get_string_value when many values were provided.""" expected = "expected_value" data = { "requested_key": [ expected, " and ", "some", "more", ], } self.assertEqual( "expected_value", RequestDataProcessor.get_string_value(data, "requested_key"), )
def get_output(data: dict) -> Response: """Get config file for requested Workload.""" workload_id = RequestDataProcessor.get_string_value(data, "workload_id") workdir = Workdir() workload_data = workdir.get_workload_data(workload_id) log_path = workload_data.get("log_path") if not log_path: raise NotFoundException(f"Unable to find output log for {workload_id}") try: response = ResponseGenerator.serve_from_filesystem( path=log_path, mimetype="text/plain", ) except Exception as e: response = ResponseGenerator.from_exception(e) return ResponseGenerator.add_refresh( response=response, refresh_time=3, )
def test_get_string_fails_when_data_missing(self) -> None: """Test get_string_value fails.""" data: Dict[str, Any] = {} with self.assertRaisesRegex(ClientErrorException, "Missing requested_key parameter"): RequestDataProcessor.get_string_value(data, "requested_key")