1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
import json
import moto.server as server
from moto import mock_aws
"""
Test the different server responses
"""
@mock_aws
def test_create_identity_pool():
backend = server.create_backend_app("cognito-identity")
test_client = backend.test_client()
res = test_client.post(
"/",
data={"IdentityPoolName": "test", "AllowUnauthenticatedIdentities": True},
headers={
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.CreateIdentityPool"
},
)
json_data = json.loads(res.data.decode("utf-8"))
assert json_data["IdentityPoolName"] == "test"
@mock_aws
def test_get_id():
backend = server.create_backend_app("cognito-identity")
test_client = backend.test_client()
res = test_client.post(
"/",
data={"IdentityPoolName": "test", "AllowUnauthenticatedIdentities": True},
headers={
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.CreateIdentityPool"
},
)
json_data = json.loads(res.data.decode("utf-8"))
res = test_client.post(
"/",
data=json.dumps(
{
"AccountId": "someaccount",
"IdentityPoolId": json_data["IdentityPoolId"],
"Logins": {"someurl": "12345"},
}
),
headers={
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetId"
},
)
json_data = json.loads(res.data.decode("utf-8"))
assert ":" in json_data["IdentityId"]
@mock_aws
def test_list_identities():
backend = server.create_backend_app("cognito-identity")
test_client = backend.test_client()
res = test_client.post(
"/",
data={"IdentityPoolName": "test", "AllowUnauthenticatedIdentities": True},
headers={
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.CreateIdentityPool"
},
)
json_data = json.loads(res.data.decode("utf-8"))
identity_pool_id = json_data["IdentityPoolId"]
res = test_client.post(
"/",
data=json.dumps(
{
"AccountId": "someaccount",
"IdentityPoolId": identity_pool_id,
"Logins": {"someurl": "12345"},
}
),
headers={
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetId"
},
)
json_data = json.loads(res.data.decode("utf-8"))
identity_id = json_data["IdentityId"]
res = test_client.post(
"/",
data=json.dumps({"IdentityPoolId": identity_pool_id}),
headers={
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.ListIdentities"
},
)
json_data = json.loads(res.data.decode("utf-8"))
assert "IdentityPoolId" in json_data and "Identities" in json_data
assert identity_id in [x["IdentityId"] for x in json_data["Identities"]]
|