SageMaker: correct describe_model_package_group does not exist msg (#7246)

This commit is contained in:
Guilherme de Amorim 2024-01-25 19:38:37 -03:00 committed by GitHub
parent 876cfeaa9c
commit a04ef58386
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 1 deletions

View File

@ -32,6 +32,7 @@ lint:
format:
black moto/ tests/
ruff --fix moto/ tests/
test-only:
rm -f .coverage

View File

@ -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

View File

@ -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"