From a04ef583864ff2e572a06e30fde6c1d175e56317 Mon Sep 17 00:00:00 2001 From: Guilherme de Amorim Date: Thu, 25 Jan 2024 19:38:37 -0300 Subject: [PATCH] SageMaker: correct describe_model_package_group does not exist msg (#7246) --- Makefile | 1 + moto/sagemaker/models.py | 8 +++++++- .../test_sagemaker_model_package_groups.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aa403f097..9c80b4c46 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ lint: format: black moto/ tests/ + ruff --fix moto/ tests/ test-only: rm -f .coverage diff --git a/moto/sagemaker/models.py b/moto/sagemaker/models.py index 241dbdfa3..a828ee3a2 100644 --- a/moto/sagemaker/models.py +++ b/moto/sagemaker/models.py @@ -3334,8 +3334,14 @@ class SageMakerModelBackend(BaseBackend): ) -> ModelPackageGroup: model_package_group = self.model_package_groups.get(model_package_group_name) if model_package_group is None: + model_package_group_arn = arn_formatter( + region_name=self.region_name, + account_id=self.account_id, + _type="model-package-group", + _id=f"{model_package_group_name}", + ) raise ValidationError( - f"Model package group {model_package_group_name} not found" + f"ModelPackageGroup {model_package_group_arn} does not exist." ) return model_package_group diff --git a/tests/test_sagemaker/test_sagemaker_model_package_groups.py b/tests/test_sagemaker/test_sagemaker_model_package_groups.py index 15ba43a8a..d9d50a261 100644 --- a/tests/test_sagemaker/test_sagemaker_model_package_groups.py +++ b/tests/test_sagemaker/test_sagemaker_model_package_groups.py @@ -4,6 +4,8 @@ from datetime import datetime from unittest import SkipTest import boto3 +import pytest +from botocore.exceptions import ClientError from dateutil.tz import tzutc # type: ignore from freezegun import freeze_time @@ -193,6 +195,21 @@ def test_describe_model_package_group(): assert resp["CreationTime"] == datetime(2020, 1, 1, 0, 0, 0, tzinfo=tzutc()) +@mock_sagemaker +def test_describe_model_package_group_not_exists(): + if settings.TEST_SERVER_MODE: + raise SkipTest("Can't freeze time in ServerMode") + client = boto3.client("sagemaker", region_name="eu-west-1") + + with pytest.raises(ClientError) as e: + client.describe_model_package_group( + ModelPackageGroupName="test-model-package-group" + ) + + assert e.value.response["Error"]["Code"] == "ValidationException" + assert "does not exist" in e.value.response["Error"]["Message"] + + @mock_sagemaker def test_list_tags_model_package_group(): region_name = "eu-west-1"