Repository: getmoto/moto
Pull request #6972 (2023-10-30 22:03:27)

Sagemaker: Fix pagination for ModelPackages(Groups)
Partial fix for #6970 

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/getmoto/moto/pull/6972?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) Report
> Merging [#6972](https://app.codecov.io/gh/getmoto/moto/pull/6972?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) (adf07c4) into [master](https://app.codecov.io/gh/getmoto/moto/commit/6323c6c255851228fbdc3501a8348043a4940fa7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) (6323c6c) will **not change** coverage.
> Report is 1 commits behind head on master.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #6972   +/-   ##
=======================================
  Coverage   95.83%   95.83%           
=======================================
  Files         830      830           
  Lines       81381    81381           
=======================================
  Hits        77988    77988           
  Misses       3393     3393           
```

| [Flag](https://app.codecov.io/gh/getmoto/moto/pull/6972/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | Coverage Δ | |
|---|---|---|
| [servertests](https://app.codecov.io/gh/getmoto/moto/pull/6972/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `36.65% <ø> (ø)` | |
| [unittests](https://app.codecov.io/gh/getmoto/moto/pull/6972/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `95.77% <ø> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Files](https://app.codecov.io/gh/getmoto/moto/pull/6972?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | Coverage Δ | |
|---|---|---|
| [moto/sagemaker/models.py](https://app.codecov.io/gh/getmoto/moto/pull/6972?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto#diff-bW90by9zYWdlbWFrZXIvbW9kZWxzLnB5) | `92.30% <ø> (ø)` | |



Patch:
diff --git a/moto/sagemaker/models.py b/moto/sagemaker/models.py
index a61d87f8a..aa855b321 100644
--- a/moto/sagemaker/models.py
+++ b/moto/sagemaker/models.py
@@ -52,13 +52,13 @@ PAGINATION_MODEL = {
         "input_token": "next_token",
         "limit_key": "max_results",
         "limit_default": 100,
-        "unique_attribute": "ModelPackageGroupArn",
+        "unique_attribute": "model_package_group_arn",
     },
     "list_model_packages": {
         "input_token": "next_token",
         "limit_key": "max_results",
         "limit_default": 100,
-        "unique_attribute": "ModelPackageArn",
+        "unique_attribute": "model_package_arn",
     },
     "list_notebook_instances": {
         "input_token": "next_token",


Test patch:
diff --git a/tests/test_sagemaker/test_sagemaker_model_package_groups.py b/tests/test_sagemaker/test_sagemaker_model_package_groups.py
index 147975064..966286ed0 100644
--- a/tests/test_sagemaker/test_sagemaker_model_package_groups.py
+++ b/tests/test_sagemaker/test_sagemaker_model_package_groups.py
@@ -31,34 +31,34 @@ def test_create_model_package_group():
 @mock_sagemaker
 def test_list_model_package_groups():
     client = boto3.client("sagemaker", region_name="eu-west-1")
+    group1 = "test-model-package-group-1"
+    desc1 = "test-model-package-group-description-1"
     client.create_model_package_group(
-        ModelPackageGroupName="test-model-package-group-1",
-        ModelPackageGroupDescription="test-model-package-group-description-1",
+        ModelPackageGroupName=group1, ModelPackageGroupDescription=desc1
     )
+
+    group2 = "test-model-package-group-2"
+    desc2 = "test-model-package-group-description-2"
     client.create_model_package_group(
-        ModelPackageGroupName="test-model-package-group-2",
-        ModelPackageGroupDescription="test-model-package-group-description-2",
+        ModelPackageGroupName=group2,
+        ModelPackageGroupDescription=desc2,
     )
-    resp = client.list_model_package_groups()
 
-    assert (
-        resp["ModelPackageGroupSummaryList"][0]["ModelPackageGroupName"]
-        == "test-model-package-group-1"
-    )
-    assert "ModelPackageGroupDescription" in resp["ModelPackageGroupSummaryList"][0]
-    assert (
-        resp["ModelPackageGroupSummaryList"][0]["ModelPackageGroupDescription"]
-        == "test-model-package-group-description-1"
-    )
-    assert (
-        resp["ModelPackageGroupSummaryList"][1]["ModelPackageGroupName"]
-        == "test-model-package-group-2"
-    )
-    assert "ModelPackageGroupDescription" in resp["ModelPackageGroupSummaryList"][1]
-    assert (
-        resp["ModelPackageGroupSummaryList"][1]["ModelPackageGroupDescription"]
-        == "test-model-package-group-description-2"
-    )
+    summary = client.list_model_package_groups()["ModelPackageGroupSummaryList"]
+
+    assert summary[0]["ModelPackageGroupName"] == group1
+    assert summary[0]["ModelPackageGroupDescription"] == desc1
+
+    assert summary[1]["ModelPackageGroupName"] == group2
+    assert summary[1]["ModelPackageGroupDescription"] == desc2
+
+    # Pagination
+    resp = client.list_model_package_groups(MaxResults=1)
+    assert len(resp["ModelPackageGroupSummaryList"]) == 1
+
+    resp = client.list_model_package_groups(MaxResults=1, NextToken=resp["NextToken"])
+    assert len(resp["ModelPackageGroupSummaryList"]) == 1
+    assert "NextToken" not in resp
 
 
 @mock_sagemaker
diff --git a/tests/test_sagemaker/test_sagemaker_model_packages.py b/tests/test_sagemaker/test_sagemaker_model_packages.py
index c54e6e8a2..4d9f326ae 100644
--- a/tests/test_sagemaker/test_sagemaker_model_packages.py
+++ b/tests/test_sagemaker/test_sagemaker_model_packages.py
@@ -133,29 +133,40 @@ def test_list_model_packages_approval_status():
 @mock_sagemaker
 def test_list_model_packages_model_package_group_name():
     client = boto3.client("sagemaker", region_name="eu-west-1")
+    group1 = "test-model-package-group"
     client.create_model_package(
         ModelPackageName="test-model-package",
         ModelPackageDescription="test-model-package-description",
-        ModelPackageGroupName="test-model-package-group",
+        ModelPackageGroupName=group1,
     )
     client.create_model_package(
         ModelPackageName="test-model-package",
         ModelPackageDescription="test-model-package-description-2",
-        ModelPackageGroupName="test-model-package-group",
+        ModelPackageGroupName=group1,
     )
     client.create_model_package(
         ModelPackageName="test-model-package-2",
         ModelPackageDescription="test-model-package-description-3",
-        ModelPackageGroupName="test-model-package-group",
+        ModelPackageGroupName=group1,
     )
     client.create_model_package(
         ModelPackageName="test-model-package-without-group",
-        ModelPackageDescription="test-model-package-description-without-group",
+        ModelPackageDescription="diff_group",
     )
-    resp = client.list_model_packages(ModelPackageGroupName="test-model-package-group")
+    resp = client.list_model_packages(ModelPackageGroupName=group1)
 
     assert len(resp["ModelPackageSummaryList"]) == 3
 
+    # Pagination
+    resp = client.list_model_packages(ModelPackageGroupName=group1, MaxResults=2)
+    assert len(resp["ModelPackageSummaryList"]) == 2
+
+    resp = client.list_model_packages(
+        ModelPackageGroupName=group1, MaxResults=2, NextToken=resp["NextToken"]
+    )
+    assert len(resp["ModelPackageSummaryList"]) == 1
+    assert "NextToken" not in resp
+
 
 @mock_sagemaker
 def test_list_model_packages_model_package_type():