使用pytest.fixtures和mock_cognitoidp
@pytest.fixture(scope="function")
def cognito(aws_credentials):
import moto
with moto.mock_cognitoidp():
yield boto3.client('cognito-idp', region_name='us-east-1')
def test_cognito(cognito):
client_name = str(uuid.uuid4())
value = str(uuid.uuid4)
user_pool_id = cognito.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"]
user_pool_client_id = cognito.create_user_pool_client(
UserPoolId=user_pool_id, ClientName=client_name, CallbackURLs=[value]
)['UserPoolClient']['ClientId']
Username=str(uuid.uuid4())
UserAttributes=[
{"Name":"full_name",
'Value':"Satej Sarker"}
]
obj={
"ClientId": user_pool_client_id,
"Username":Username,
"Password":'satejsarker'
}
user=cognito.sign_up(ClientId=user_pool_client_id,
Username=username,
Password="abc1234"
它给我的错误,例如sign_up尚未实现 但与其他模块完美配合。并在实际的AWS环境中使用此代码