From a4a8949166d561dceffc13acfcec6733abe7553e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz?= <38426907+nluk@users.noreply.github.com> Date: Sun, 24 Oct 2021 15:29:16 +0200 Subject: [PATCH] CognitoIDP github.com/spulec/moto/issues/4452 - missing EstimatedNumberOfUsers (#4470) --- moto/cognitoidp/models.py | 1 + tests/test_cognitoidp/test_cognitoidp.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/moto/cognitoidp/models.py b/moto/cognitoidp/models.py index 3fe810b2b..dd1c52055 100644 --- a/moto/cognitoidp/models.py +++ b/moto/cognitoidp/models.py @@ -76,6 +76,7 @@ class CognitoIdpUserPool(BaseModel): "CreationDate": time.mktime(self.creation_date.timetuple()), "LastModifiedDate": time.mktime(self.last_modified_date.timetuple()), "MfaConfiguration": self.mfa_config, + "EstimatedNumberOfUsers": len(self.users), } def to_json(self, extended=False): diff --git a/tests/test_cognitoidp/test_cognitoidp.py b/tests/test_cognitoidp/test_cognitoidp.py index dbe59f656..ea4870b8a 100644 --- a/tests/test_cognitoidp/test_cognitoidp.py +++ b/tests/test_cognitoidp/test_cognitoidp.py @@ -215,6 +215,22 @@ def test_describe_user_pool(): result["UserPool"]["LambdaConfig"]["PreSignUp"].should.equal(value) +@mock_cognitoidp +def test_describe_user_pool_estimated_number_of_users(): + conn = boto3.client("cognito-idp", "us-west-2") + user_pool_id = conn.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"] + + result = conn.describe_user_pool(UserPoolId=user_pool_id) + result["UserPool"]["EstimatedNumberOfUsers"].should.equal(0) + + users_count = random.randint(2, 6) + for _ in range(users_count): + conn.admin_create_user(UserPoolId=user_pool_id, Username=str(uuid.uuid4())) + + result = conn.describe_user_pool(UserPoolId=user_pool_id) + result["UserPool"]["EstimatedNumberOfUsers"].should.equal(users_count) + + @mock_cognitoidp def test_describe_user_pool_resource_not_found(): conn = boto3.client("cognito-idp", "us-east-1")