Techdebt: Replace sure with regular asserts in Cognito (#6496)
This commit is contained in:
parent
426a8ad5ea
commit
39313ffc5b
@ -1,6 +1,5 @@
|
||||
import boto3
|
||||
from unittest import mock
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
from botocore.exceptions import ClientError
|
||||
from datetime import datetime
|
||||
import pytest
|
||||
@ -23,9 +22,10 @@ def test_create_identity_pool_invalid_name(name):
|
||||
IdentityPoolName=name, AllowUnauthenticatedIdentities=False
|
||||
)
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("ValidationException")
|
||||
err["Message"].should.equal(
|
||||
f"1 validation error detected: Value '{name}' at 'identityPoolName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\w\\s+=,.@-]+"
|
||||
assert err["Code"] == "ValidationException"
|
||||
assert (
|
||||
err["Message"]
|
||||
== f"1 validation error detected: Value '{name}' at 'identityPoolName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\w\\s+=,.@-]+"
|
||||
)
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ def test_update_identity_pool(key, initial_value, updated_value):
|
||||
)
|
||||
|
||||
first = conn.describe_identity_pool(IdentityPoolId=res["IdentityPoolId"])
|
||||
first[key].should.equal(initial_value)
|
||||
assert first[key] == initial_value
|
||||
|
||||
response = conn.update_identity_pool(
|
||||
IdentityPoolId=res["IdentityPoolId"],
|
||||
@ -126,10 +126,10 @@ def test_update_identity_pool(key, initial_value, updated_value):
|
||||
AllowUnauthenticatedIdentities=False,
|
||||
**dict({key: updated_value}),
|
||||
)
|
||||
response[key].should.equal(updated_value)
|
||||
assert response[key] == updated_value
|
||||
|
||||
second = conn.describe_identity_pool(IdentityPoolId=res["IdentityPoolId"])
|
||||
second[key].should.equal(response[key])
|
||||
assert second[key] == response[key]
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
@ -138,17 +138,17 @@ def test_describe_identity_pool_with_invalid_id_raises_error():
|
||||
with pytest.raises(ClientError) as cm:
|
||||
conn.describe_identity_pool(IdentityPoolId="us-west-2_non-existent")
|
||||
|
||||
cm.value.operation_name.should.equal("DescribeIdentityPool")
|
||||
cm.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
cm.value.response["Error"]["Message"].should.equal("us-west-2_non-existent")
|
||||
cm.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
assert cm.value.operation_name == "DescribeIdentityPool"
|
||||
assert cm.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||
assert cm.value.response["Error"]["Message"] == "us-west-2_non-existent"
|
||||
assert cm.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||
|
||||
|
||||
# testing a helper function
|
||||
def test_get_random_identity_id():
|
||||
identity_id = get_random_identity_id("us-west-2")
|
||||
region, identity_id = identity_id.split(":")
|
||||
region.should.equal("us-west-2")
|
||||
assert region == "us-west-2"
|
||||
UUID(identity_id, version=4) # Will throw an error if it's not a valid UUID
|
||||
|
||||
|
||||
@ -189,8 +189,8 @@ def test_get_credentials_for_identity():
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
result = conn.get_credentials_for_identity(IdentityId="12345")
|
||||
|
||||
result["Credentials"].get("Expiration").should.be.a(datetime)
|
||||
result.get("IdentityId").should.equal("12345")
|
||||
assert isinstance(result["Credentials"]["Expiration"], datetime)
|
||||
assert result.get("IdentityId") == "12345"
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
|
@ -1,7 +1,5 @@
|
||||
import json
|
||||
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
import moto.server as server
|
||||
from moto import mock_cognitoidentity
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -50,7 +50,7 @@ class TestCognitoUserDeleter(TestCase):
|
||||
"REFRESH_TOKEN": refresh_token,
|
||||
},
|
||||
)
|
||||
exc.exception.response["Error"]["Code"].should.equal("NotAuthorizedException")
|
||||
assert exc.exception.response["Error"]["Code"] == "NotAuthorizedException"
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
@ -84,8 +84,8 @@ class TestCognitoUserPoolDuplidateEmails(TestCase):
|
||||
UserAttributes=[{"Name": "email", "Value": "user2@test.com"}],
|
||||
)
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("AliasExistsException")
|
||||
err["Message"].should.equal("An account with the given email already exists.")
|
||||
assert err["Code"] == "AliasExistsException"
|
||||
assert err["Message"] == "An account with the given email already exists."
|
||||
|
||||
def test_use_existing_email__when_username_is_login(self):
|
||||
# Because we cannot use the email as username,
|
||||
|
@ -2,7 +2,6 @@ import os
|
||||
|
||||
import boto3
|
||||
import uuid
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
@ -37,7 +36,7 @@ class TestCreateUserPoolWithPredeterminedID(TestCase):
|
||||
resp = requests.get(
|
||||
"http://localhost:5000/moto-api/recorder/download-recording"
|
||||
)
|
||||
resp.status_code.should.equal(200)
|
||||
assert resp.status_code == 200
|
||||
return resp.content.decode("utf-8")
|
||||
else:
|
||||
return recorder.download_recording()
|
||||
@ -107,8 +106,8 @@ class TestCreateUserPoolWithPredeterminedID(TestCase):
|
||||
with pytest.raises(ClientError) as exc:
|
||||
self.client.describe_user_pool(UserPoolId=self.pool_id)
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("ResourceNotFoundException")
|
||||
assert err["Code"] == "ResourceNotFoundException"
|
||||
|
||||
# It is created - just with a different ID
|
||||
all_pools = self.client.list_user_pools(MaxResults=5)["UserPools"]
|
||||
all_pools.should.have.length_of(1)
|
||||
assert len(all_pools) == 1
|
||||
|
@ -44,7 +44,7 @@ def test_sign_up_user_without_authentication():
|
||||
"Authorization": "AWS4-HMAC-SHA256 Credential=abcd/20010101/us-east-2/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=...",
|
||||
},
|
||||
)
|
||||
json.loads(res.data)["UserPoolClients"].should.have.length_of(1)
|
||||
assert len(json.loads(res.data)["UserPoolClients"]) == 1
|
||||
|
||||
# Sign Up User
|
||||
data = {"ClientId": client_id, "Username": "test@gmail.com", "Password": "P2$Sword"}
|
||||
@ -53,8 +53,8 @@ def test_sign_up_user_without_authentication():
|
||||
data=json.dumps(data),
|
||||
headers={"X-Amz-Target": "AWSCognitoIdentityProviderService.SignUp"},
|
||||
)
|
||||
res.status_code.should.equal(200)
|
||||
json.loads(res.data).should.have.key("UserConfirmed").equals(False)
|
||||
assert res.status_code == 200
|
||||
assert json.loads(res.data)["UserConfirmed"] is False
|
||||
|
||||
# Confirm Sign Up User
|
||||
data = {
|
||||
@ -79,7 +79,7 @@ def test_sign_up_user_without_authentication():
|
||||
data=json.dumps(data),
|
||||
headers={"X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth"},
|
||||
)
|
||||
res.status_code.should.equal(200)
|
||||
assert res.status_code == 200
|
||||
access_token = json.loads(res.data)["AuthenticationResult"]["AccessToken"]
|
||||
|
||||
# Get User
|
||||
@ -89,11 +89,11 @@ def test_sign_up_user_without_authentication():
|
||||
data=json.dumps(data),
|
||||
headers={"X-Amz-Target": "AWSCognitoIdentityProviderService.GetUser"},
|
||||
)
|
||||
res.status_code.should.equal(200)
|
||||
assert res.status_code == 200
|
||||
data = json.loads(res.data)
|
||||
data.should.have.key("UserPoolId").equals(user_pool_id)
|
||||
data.should.have.key("Username").equals("test@gmail.com")
|
||||
data.should.have.key("UserStatus").equals("CONFIRMED")
|
||||
assert data["UserPoolId"] == user_pool_id
|
||||
assert data["Username"] == "test@gmail.com"
|
||||
assert data["UserStatus"] == "CONFIRMED"
|
||||
|
||||
|
||||
def test_admin_create_user_without_authentication():
|
||||
@ -142,7 +142,7 @@ def test_admin_create_user_without_authentication():
|
||||
"Authorization": "AWS4-HMAC-SHA256 Credential=abcd/20010101/us-east-2/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=...",
|
||||
},
|
||||
)
|
||||
res.status_code.should.equal(200)
|
||||
assert res.status_code == 200
|
||||
|
||||
# Initiate Auth
|
||||
data = {
|
||||
@ -174,9 +174,9 @@ def test_admin_create_user_without_authentication():
|
||||
"X-Amz-Target": "AWSCognitoIdentityProviderService.RespondToAuthChallenge"
|
||||
},
|
||||
)
|
||||
res.status_code.should.equal(200)
|
||||
assert res.status_code == 200
|
||||
response = json.loads(res.data)
|
||||
|
||||
response.should.have.key("AuthenticationResult")
|
||||
response["AuthenticationResult"].should.have.key("IdToken")
|
||||
response["AuthenticationResult"].should.have.key("AccessToken")
|
||||
assert "AuthenticationResult" in response
|
||||
assert "IdToken" in response["AuthenticationResult"]
|
||||
assert "AccessToken" in response["AuthenticationResult"]
|
||||
|
Loading…
Reference in New Issue
Block a user