Port test suite from nose to pytest.
This just eliminates all errors on the tests collection. Elimination of failures is left to the next commit.
This commit is contained in:
parent
47dbad291e
commit
77dc60ea97
146 changed files with 1172 additions and 1277 deletions
1
tests/test_iam/__init__.py
Normal file
1
tests/test_iam/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# This file is intentionally left blank.
|
||||
|
|
@ -13,8 +13,7 @@ from moto import mock_config, mock_iam, mock_iam_deprecated, settings
|
|||
from moto.core import ACCOUNT_ID
|
||||
from moto.iam.models import aws_managed_policies
|
||||
from moto.backends import get_backend
|
||||
from nose.tools import assert_raises, assert_equals
|
||||
from nose.tools import raises
|
||||
import pytest
|
||||
|
||||
from datetime import datetime
|
||||
from tests.helpers import requires_boto_gte
|
||||
|
|
@ -93,7 +92,7 @@ def test_get_all_server_certs():
|
|||
def test_get_server_cert_doesnt_exist():
|
||||
conn = boto.connect_iam()
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_server_certificate("NonExistant")
|
||||
|
||||
|
||||
|
|
@ -128,14 +127,14 @@ def test_delete_server_cert():
|
|||
conn.upload_server_cert("certname", "certbody", "privatekey")
|
||||
conn.get_server_certificate("certname")
|
||||
conn.delete_server_cert("certname")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_server_certificate("certname")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_server_cert("certname")
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
@raises(BotoServerError)
|
||||
@pytest.mark.xfail(raises=BotoServerError)
|
||||
def test_get_role__should_throw__when_role_does_not_exist():
|
||||
conn = boto.connect_iam()
|
||||
|
||||
|
|
@ -143,7 +142,7 @@ def test_get_role__should_throw__when_role_does_not_exist():
|
|||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
@raises(BotoServerError)
|
||||
@pytest.mark.xfail(raises=BotoServerError)
|
||||
def test_get_instance_profile__should_throw__when_instance_profile_does_not_exist():
|
||||
conn = boto.connect_iam()
|
||||
|
||||
|
|
@ -181,7 +180,7 @@ def test_create_role_and_instance_profile():
|
|||
def test_create_instance_profile_should_throw_when_name_is_not_unique():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
conn.create_instance_profile(InstanceProfileName="unique-instance-profile")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_instance_profile(InstanceProfileName="unique-instance-profile")
|
||||
|
||||
|
||||
|
|
@ -214,13 +213,13 @@ def test_delete_instance_profile():
|
|||
conn.add_role_to_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_instance_profile(InstanceProfileName="my-profile")
|
||||
conn.remove_role_from_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
conn.delete_instance_profile(InstanceProfileName="my-profile")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
profile = conn.get_instance_profile(InstanceProfileName="my-profile")
|
||||
|
||||
|
||||
|
|
@ -253,7 +252,7 @@ def test_update_login_profile():
|
|||
def test_delete_role():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
# Test deletion failure with a managed policy
|
||||
|
|
@ -264,12 +263,12 @@ def test_delete_role():
|
|||
PolicyName="my-managed-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
conn.attach_role_policy(PolicyArn=response["Policy"]["Arn"], RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
conn.detach_role_policy(PolicyArn=response["Policy"]["Arn"], RoleName="my-role")
|
||||
conn.delete_policy(PolicyArn=response["Policy"]["Arn"])
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
# Test deletion failure with an inline policy
|
||||
|
|
@ -279,11 +278,11 @@ def test_delete_role():
|
|||
conn.put_role_policy(
|
||||
RoleName="my-role", PolicyName="my-role-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
conn.delete_role_policy(RoleName="my-role", PolicyName="my-role-policy")
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
# Test deletion failure with attachment to an instance profile
|
||||
|
|
@ -294,13 +293,13 @@ def test_delete_role():
|
|||
conn.add_role_to_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
conn.remove_role_from_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
# Test deletion with no conflicts
|
||||
|
|
@ -308,7 +307,7 @@ def test_delete_role():
|
|||
RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="/my-path/"
|
||||
)
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
|
||||
|
|
@ -389,7 +388,7 @@ def test_list_role_policies():
|
|||
role.policy_names.should.have.length_of(1)
|
||||
role.policy_names[0].should.equal("test policy 2")
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_role_policy("my-role", "test policy")
|
||||
|
||||
|
||||
|
|
@ -412,7 +411,7 @@ def test_get_role_policy():
|
|||
conn.create_role(
|
||||
RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="my-path"
|
||||
)
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role_policy(RoleName="my-role", PolicyName="does-not-exist")
|
||||
|
||||
|
||||
|
|
@ -442,7 +441,7 @@ def test_create_policy_already_exists():
|
|||
response = conn.create_policy(
|
||||
PolicyName="TestCreatePolicy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
with assert_raises(conn.exceptions.EntityAlreadyExistsException) as ex:
|
||||
with pytest.raises(conn.exceptions.EntityAlreadyExistsException) as ex:
|
||||
response = conn.create_policy(
|
||||
PolicyName="TestCreatePolicy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
|
|
@ -467,7 +466,7 @@ def test_delete_policy():
|
|||
@mock_iam
|
||||
def test_create_policy_versions():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestCreatePolicyVersion".format(
|
||||
ACCOUNT_ID
|
||||
|
|
@ -508,7 +507,7 @@ def test_create_many_policy_versions():
|
|||
),
|
||||
PolicyDocument=MOCK_POLICY,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestCreateManyPolicyVersions".format(
|
||||
ACCOUNT_ID
|
||||
|
|
@ -639,7 +638,7 @@ def test_get_policy_version():
|
|||
PolicyArn="arn:aws:iam::{}:policy/TestGetPolicyVersion".format(ACCOUNT_ID),
|
||||
PolicyDocument=MOCK_POLICY,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestGetPolicyVersion".format(ACCOUNT_ID),
|
||||
VersionId="v2-does-not-exist",
|
||||
|
|
@ -661,7 +660,7 @@ def test_get_aws_managed_policy_version():
|
|||
managed_policy_version_create_date = datetime.strptime(
|
||||
"2015-04-09T15:03:43+00:00", "%Y-%m-%dT%H:%M:%S+00:00"
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_policy_version(
|
||||
PolicyArn=managed_policy_arn, VersionId="v2-does-not-exist"
|
||||
)
|
||||
|
|
@ -679,7 +678,7 @@ def test_get_aws_managed_policy_v4_version():
|
|||
managed_policy_version_create_date = datetime.strptime(
|
||||
"2018-10-08T21:33:45+00:00", "%Y-%m-%dT%H:%M:%S+00:00"
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_policy_version(
|
||||
PolicyArn=managed_policy_arn, VersionId="v2-does-not-exist"
|
||||
)
|
||||
|
|
@ -693,7 +692,7 @@ def test_get_aws_managed_policy_v4_version():
|
|||
@mock_iam
|
||||
def test_list_policy_versions():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
versions = conn.list_policy_versions(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestListPolicyVersions".format(ACCOUNT_ID)
|
||||
)
|
||||
|
|
@ -729,7 +728,7 @@ def test_delete_policy_version():
|
|||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(ACCOUNT_ID),
|
||||
PolicyDocument=MOCK_POLICY,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(
|
||||
ACCOUNT_ID
|
||||
|
|
@ -754,7 +753,7 @@ def test_delete_default_policy_version():
|
|||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(ACCOUNT_ID),
|
||||
PolicyDocument=MOCK_POLICY_2,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(
|
||||
ACCOUNT_ID
|
||||
|
|
@ -767,14 +766,14 @@ def test_delete_default_policy_version():
|
|||
def test_create_user():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_user("my-user")
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
def test_get_user():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_user("my-user")
|
||||
conn.create_user("my-user")
|
||||
conn.get_user("my-user")
|
||||
|
|
@ -783,13 +782,13 @@ def test_get_user():
|
|||
@mock_iam()
|
||||
def test_update_user():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.update_user(UserName="my-user")
|
||||
conn.create_user(UserName="my-user")
|
||||
conn.update_user(UserName="my-user", NewPath="/new-path/", NewUserName="new-user")
|
||||
response = conn.get_user(UserName="new-user")
|
||||
response["User"].get("Path").should.equal("/new-path/")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
|
||||
|
|
@ -846,11 +845,11 @@ def test_user_policies():
|
|||
@mock_iam_deprecated()
|
||||
def test_create_login_profile():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
conn.create_user("my-user")
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
|
||||
|
||||
|
|
@ -858,7 +857,7 @@ def test_create_login_profile():
|
|||
def test_delete_login_profile():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_login_profile("my-user")
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
conn.delete_login_profile("my-user")
|
||||
|
|
@ -867,7 +866,7 @@ def test_delete_login_profile():
|
|||
@mock_iam
|
||||
def test_create_access_key():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_access_key(UserName="my-user")
|
||||
conn.create_user(UserName="my-user")
|
||||
access_key = conn.create_access_key(UserName="my-user")["AccessKey"]
|
||||
|
|
@ -899,22 +898,19 @@ def test_get_all_access_keys():
|
|||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
response = conn.get_all_access_keys("my-user")
|
||||
assert_equals(
|
||||
assert \
|
||||
response["list_access_keys_response"]["list_access_keys_result"][
|
||||
"access_key_metadata"
|
||||
],
|
||||
[],
|
||||
)
|
||||
] == []
|
||||
conn.create_access_key("my-user")
|
||||
response = conn.get_all_access_keys("my-user")
|
||||
assert_equals(
|
||||
assert \
|
||||
sorted(
|
||||
response["list_access_keys_response"]["list_access_keys_result"][
|
||||
"access_key_metadata"
|
||||
][0].keys()
|
||||
),
|
||||
sorted(["status", "create_date", "user_name", "access_key_id"]),
|
||||
)
|
||||
) == \
|
||||
sorted(["status", "create_date", "user_name", "access_key_id"])
|
||||
|
||||
|
||||
@mock_iam
|
||||
|
|
@ -922,13 +918,12 @@ def test_list_access_keys():
|
|||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
conn.create_user(UserName="my-user")
|
||||
response = conn.list_access_keys(UserName="my-user")
|
||||
assert_equals(response["AccessKeyMetadata"], [])
|
||||
assert response["AccessKeyMetadata"] == []
|
||||
access_key = conn.create_access_key(UserName="my-user")["AccessKey"]
|
||||
response = conn.list_access_keys(UserName="my-user")
|
||||
assert_equals(
|
||||
sorted(response["AccessKeyMetadata"][0].keys()),
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"]),
|
||||
)
|
||||
assert \
|
||||
sorted(response["AccessKeyMetadata"][0].keys()) == \
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"]
|
||||
conn = boto3.client(
|
||||
"iam",
|
||||
region_name="us-east-1",
|
||||
|
|
@ -936,10 +931,9 @@ def test_list_access_keys():
|
|||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
response = conn.list_access_keys()
|
||||
assert_equals(
|
||||
sorted(response["AccessKeyMetadata"][0].keys()),
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"]),
|
||||
)
|
||||
assert \
|
||||
sorted(response["AccessKeyMetadata"][0].keys()) == \
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"])
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
|
|
@ -1188,7 +1182,7 @@ def test_enable_virtual_mfa_device():
|
|||
@mock_iam_deprecated()
|
||||
def test_delete_user_deprecated():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_user("my-user")
|
||||
conn.create_user("my-user")
|
||||
conn.delete_user("my-user")
|
||||
|
|
@ -1197,7 +1191,7 @@ def test_delete_user_deprecated():
|
|||
@mock_iam()
|
||||
def test_delete_user():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.delete_user(UserName="my-user")
|
||||
|
||||
# Test deletion failure with a managed policy
|
||||
|
|
@ -1206,12 +1200,12 @@ def test_delete_user():
|
|||
PolicyName="my-managed-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
conn.attach_user_policy(PolicyArn=response["Policy"]["Arn"], UserName="my-user")
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_user(UserName="my-user")
|
||||
conn.detach_user_policy(PolicyArn=response["Policy"]["Arn"], UserName="my-user")
|
||||
conn.delete_policy(PolicyArn=response["Policy"]["Arn"])
|
||||
conn.delete_user(UserName="my-user")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
# Test deletion failure with an inline policy
|
||||
|
|
@ -1219,17 +1213,17 @@ def test_delete_user():
|
|||
conn.put_user_policy(
|
||||
UserName="my-user", PolicyName="my-user-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_user(UserName="my-user")
|
||||
conn.delete_user_policy(UserName="my-user", PolicyName="my-user-policy")
|
||||
conn.delete_user(UserName="my-user")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
# Test deletion with no conflicts
|
||||
conn.create_user(UserName="my-user")
|
||||
conn.delete_user(UserName="my-user")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
|
||||
|
|
@ -1259,7 +1253,7 @@ def test_boto3_generate_credential_report():
|
|||
def test_get_credential_report():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
while (
|
||||
|
|
@ -1282,7 +1276,7 @@ def test_get_credential_report():
|
|||
def test_boto3_get_credential_report():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
conn.create_user(UserName="my-user")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
while result["State"] != "COMPLETE":
|
||||
|
|
@ -1306,7 +1300,7 @@ def test_boto3_get_credential_report_content():
|
|||
if not settings.TEST_SERVER_MODE:
|
||||
iam_backend = get_backend("iam")["global"]
|
||||
iam_backend.users[username].access_keys[1].last_used = timestamp
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
while result["State"] != "COMPLETE":
|
||||
|
|
@ -1336,7 +1330,7 @@ def test_get_access_key_last_used_when_used():
|
|||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_access_key_last_used(AccessKeyId="non-existent-key-id")
|
||||
create_key_response = client.create_access_key(UserName=username)["AccessKey"]
|
||||
# Set last used date using the IAM backend. Moto currently does not have a mechanism for tracking usage of access keys
|
||||
|
|
@ -1448,12 +1442,12 @@ def test_managed_policy():
|
|||
"attached_policies"
|
||||
].should.have.length_of(1)
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.detach_role_policy(
|
||||
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole", role_name
|
||||
)
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.detach_role_policy("arn:aws:iam::aws:policy/Nonexistent", role_name)
|
||||
|
||||
|
||||
|
|
@ -1461,13 +1455,13 @@ def test_managed_policy():
|
|||
def test_boto3_create_login_profile():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_login_profile(UserName="my-user", Password="Password")
|
||||
|
||||
conn.create_user(UserName="my-user")
|
||||
conn.create_login_profile(UserName="my-user", Password="Password")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_login_profile(UserName="my-user", Password="Password")
|
||||
|
||||
|
||||
|
|
@ -1506,7 +1500,7 @@ def test_update_access_key():
|
|||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.update_access_key(
|
||||
UserName=username, AccessKeyId="non-existent-key", Status="Inactive"
|
||||
)
|
||||
|
|
@ -1527,7 +1521,7 @@ def test_get_access_key_last_used_when_unused():
|
|||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_access_key_last_used(AccessKeyId="non-existent-key-id")
|
||||
create_key_response = client.create_access_key(UserName=username)["AccessKey"]
|
||||
resp = client.get_access_key_last_used(
|
||||
|
|
@ -1566,7 +1560,7 @@ def test_get_ssh_public_key():
|
|||
iam.create_user(UserName=username)
|
||||
public_key = MOCK_CERT
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_ssh_public_key(
|
||||
UserName=username, SSHPublicKeyId="xxnon-existent-keyxx", Encoding="SSH"
|
||||
)
|
||||
|
|
@ -1607,7 +1601,7 @@ def test_update_ssh_public_key():
|
|||
iam.create_user(UserName=username)
|
||||
public_key = MOCK_CERT
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.update_ssh_public_key(
|
||||
UserName=username, SSHPublicKeyId="xxnon-existent-keyxx", Status="Inactive"
|
||||
)
|
||||
|
|
@ -1634,7 +1628,7 @@ def test_delete_ssh_public_key():
|
|||
iam.create_user(UserName=username)
|
||||
public_key = MOCK_CERT
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.delete_ssh_public_key(
|
||||
UserName=username, SSHPublicKeyId="xxnon-existent-keyxx"
|
||||
)
|
||||
|
|
@ -1827,14 +1821,14 @@ def test_signing_certs():
|
|||
assert resp["CertificateId"]
|
||||
|
||||
# Upload a the cert with an invalid body:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.upload_signing_certificate(
|
||||
UserName="testing", CertificateBody="notacert"
|
||||
)
|
||||
assert ce.exception.response["Error"]["Code"] == "MalformedCertificate"
|
||||
|
||||
# Upload with an invalid user:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.upload_signing_certificate(
|
||||
UserName="notauser", CertificateBody=MOCK_CERT
|
||||
)
|
||||
|
|
@ -1844,12 +1838,12 @@ def test_signing_certs():
|
|||
UserName="testing", CertificateId=cert_id, Status="Inactive"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.update_signing_certificate(
|
||||
UserName="notauser", CertificateId=cert_id, Status="Inactive"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.update_signing_certificate(
|
||||
UserName="testing", CertificateId="x" * 32, Status="Inactive"
|
||||
)
|
||||
|
|
@ -1864,13 +1858,13 @@ def test_signing_certs():
|
|||
assert resp[0]["CertificateBody"] == MOCK_CERT
|
||||
assert resp[0]["Status"] == "Inactive" # Changed with the update call above.
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.list_signing_certificates(UserName="notauser")
|
||||
|
||||
# Delete:
|
||||
client.delete_signing_certificate(UserName="testing", CertificateId=cert_id)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.delete_signing_certificate(UserName="notauser", CertificateId=cert_id)
|
||||
|
||||
|
||||
|
|
@ -1921,7 +1915,7 @@ def test_delete_saml_provider():
|
|||
conn.create_user(UserName="testing")
|
||||
|
||||
cert_id = "123456789012345678901234"
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.delete_signing_certificate(UserName="testing", CertificateId=cert_id)
|
||||
|
||||
assert ce.exception.response["Error"][
|
||||
|
|
@ -1982,7 +1976,7 @@ def test_create_role_with_tags():
|
|||
|
||||
# Test creating tags with invalid values:
|
||||
# With more than 50 tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
too_many_tags = list(
|
||||
map(lambda x: {"Key": str(x), "Value": str(x)}, range(0, 51))
|
||||
)
|
||||
|
|
@ -1995,7 +1989,7 @@ def test_create_role_with_tags():
|
|||
)
|
||||
|
||||
# With a duplicate tag:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
|
|
@ -2007,7 +2001,7 @@ def test_create_role_with_tags():
|
|||
)
|
||||
|
||||
# Duplicate tag with different casing:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
|
|
@ -2019,7 +2013,7 @@ def test_create_role_with_tags():
|
|||
)
|
||||
|
||||
# With a really big key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
|
|
@ -2031,7 +2025,7 @@ def test_create_role_with_tags():
|
|||
)
|
||||
|
||||
# With a really big value:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
|
|
@ -2043,7 +2037,7 @@ def test_create_role_with_tags():
|
|||
)
|
||||
|
||||
# With an invalid character:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
|
|
@ -2125,7 +2119,7 @@ def test_tag_role():
|
|||
|
||||
# Test creating tags with invalid values:
|
||||
# With more than 50 tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
too_many_tags = list(
|
||||
map(lambda x: {"Key": str(x), "Value": str(x)}, range(0, 51))
|
||||
)
|
||||
|
|
@ -2136,7 +2130,7 @@ def test_tag_role():
|
|||
)
|
||||
|
||||
# With a duplicate tag:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(
|
||||
RoleName="my-role",
|
||||
Tags=[{"Key": "0", "Value": ""}, {"Key": "0", "Value": ""}],
|
||||
|
|
@ -2147,7 +2141,7 @@ def test_tag_role():
|
|||
)
|
||||
|
||||
# Duplicate tag with different casing:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(
|
||||
RoleName="my-role",
|
||||
Tags=[{"Key": "a", "Value": ""}, {"Key": "A", "Value": ""}],
|
||||
|
|
@ -2158,7 +2152,7 @@ def test_tag_role():
|
|||
)
|
||||
|
||||
# With a really big key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(RoleName="my-role", Tags=[{"Key": "0" * 129, "Value": ""}])
|
||||
assert (
|
||||
"Member must have length less than or equal to 128."
|
||||
|
|
@ -2166,7 +2160,7 @@ def test_tag_role():
|
|||
)
|
||||
|
||||
# With a really big value:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(RoleName="my-role", Tags=[{"Key": "0", "Value": "0" * 257}])
|
||||
assert (
|
||||
"Member must have length less than or equal to 256."
|
||||
|
|
@ -2174,7 +2168,7 @@ def test_tag_role():
|
|||
)
|
||||
|
||||
# With an invalid character:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(RoleName="my-role", Tags=[{"Key": "NOWAY!", "Value": ""}])
|
||||
assert (
|
||||
"Member must satisfy regular expression pattern: [\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]+"
|
||||
|
|
@ -2182,7 +2176,7 @@ def test_tag_role():
|
|||
)
|
||||
|
||||
# With a role that doesn't exist:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.tag_role(RoleName="notarole", Tags=[{"Key": "some", "Value": "value"}])
|
||||
|
||||
|
||||
|
|
@ -2214,7 +2208,7 @@ def test_untag_role():
|
|||
|
||||
# Test removing tags with invalid values:
|
||||
# With more than 50 tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.untag_role(RoleName="my-role", TagKeys=[str(x) for x in range(0, 51)])
|
||||
assert (
|
||||
"failed to satisfy constraint: Member must have length less than or equal to 50."
|
||||
|
|
@ -2223,7 +2217,7 @@ def test_untag_role():
|
|||
assert "tagKeys" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With a really big key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.untag_role(RoleName="my-role", TagKeys=["0" * 129])
|
||||
assert (
|
||||
"Member must have length less than or equal to 128."
|
||||
|
|
@ -2232,7 +2226,7 @@ def test_untag_role():
|
|||
assert "tagKeys" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With an invalid character:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.untag_role(RoleName="my-role", TagKeys=["NOWAY!"])
|
||||
assert (
|
||||
"Member must satisfy regular expression pattern: [\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]+"
|
||||
|
|
@ -2241,7 +2235,7 @@ def test_untag_role():
|
|||
assert "tagKeys" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With a role that doesn't exist:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.untag_role(RoleName="notarole", TagKeys=["somevalue"])
|
||||
|
||||
|
||||
|
|
@ -2249,7 +2243,7 @@ def test_untag_role():
|
|||
def test_update_role_description():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
|
|
@ -2264,7 +2258,7 @@ def test_update_role_description():
|
|||
def test_update_role():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
|
|
@ -2278,7 +2272,7 @@ def test_update_role():
|
|||
def test_update_role():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
|
|
@ -2292,7 +2286,7 @@ def test_update_role():
|
|||
def test_update_role_defaults():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
|
|
@ -2436,12 +2430,12 @@ def test_create_role_with_permissions_boundary():
|
|||
|
||||
invalid_boundary_arn = "arn:aws:iam::123456789:not_a_boundary"
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.put_role_permissions_boundary(
|
||||
RoleName="my-role", PermissionsBoundary=invalid_boundary_arn
|
||||
)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_role(
|
||||
RoleName="bad-boundary",
|
||||
AssumeRolePolicyDocument="some policy",
|
||||
|
|
@ -2461,7 +2455,7 @@ def test_create_role_with_same_name_should_fail():
|
|||
RoleName=test_role_name, AssumeRolePolicyDocument="policy", Description="test"
|
||||
)
|
||||
# Create the role again, and verify that it fails
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
iam.create_role(
|
||||
RoleName=test_role_name,
|
||||
AssumeRolePolicyDocument="policy",
|
||||
|
|
@ -2479,7 +2473,7 @@ def test_create_policy_with_same_name_should_fail():
|
|||
test_policy_name = str(uuid4())
|
||||
policy = iam.create_policy(PolicyName=test_policy_name, PolicyDocument=MOCK_POLICY)
|
||||
# Create the role again, and verify that it fails
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
iam.create_policy(PolicyName=test_policy_name, PolicyDocument=MOCK_POLICY)
|
||||
err.exception.response["Error"]["Code"].should.equal("EntityAlreadyExists")
|
||||
err.exception.response["Error"]["Message"].should.equal(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import boto3
|
|||
import yaml
|
||||
import sure # noqa
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from moto import mock_iam, mock_cloudformation, mock_s3, mock_sts
|
||||
|
|
@ -111,7 +111,7 @@ Resources:
|
|||
|
||||
cf_client.update_stack(StackName=stack_name, TemplateBody=template)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
iam_client.get_user(UserName=original_user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ Resources:
|
|||
second_user_name.should.equal(second_provisioned_user["PhysicalResourceId"])
|
||||
|
||||
iam_client.get_user(UserName=second_user_name)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
iam_client.get_user(UserName=first_user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ Resources:
|
|||
|
||||
cf_client.delete_stack(StackName=stack_name)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
user = iam_client.get_user(UserName=user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
|
|
@ -235,7 +235,7 @@ Resources:
|
|||
|
||||
cf_client.delete_stack(StackName=stack_name)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
user = iam_client.get_user(UserName=user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import boto
|
|||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from boto.exception import BotoServerError
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_iam, mock_iam_deprecated
|
||||
|
|
@ -29,7 +29,7 @@ MOCK_POLICY = """
|
|||
def test_create_group():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_group("my-group")
|
||||
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ def test_get_group():
|
|||
conn = boto.connect_iam()
|
||||
conn.create_group("my-group")
|
||||
conn.get_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_group("not-group")
|
||||
|
||||
|
||||
|
|
@ -77,10 +77,10 @@ def test_get_all_groups():
|
|||
@mock_iam_deprecated()
|
||||
def test_add_user_to_group():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
conn.create_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
conn.create_user("my-user")
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
|
|
@ -89,11 +89,11 @@ def test_add_user_to_group():
|
|||
@mock_iam_deprecated()
|
||||
def test_remove_user_from_group():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.remove_user_from_group("my-group", "my-user")
|
||||
conn.create_group("my-group")
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.remove_user_from_group("my-group", "my-user")
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
conn.remove_user_from_group("my-group", "my-user")
|
||||
|
|
@ -150,7 +150,7 @@ def test_attach_group_policies():
|
|||
def test_get_group_policy():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_group_policy("my-group", "my-policy")
|
||||
|
||||
conn.put_group_policy("my-group", "my-policy", MOCK_POLICY)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import json
|
|||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_iam
|
||||
|
||||
|
|
@ -1624,7 +1624,7 @@ def test_create_policy_with_valid_policy_documents():
|
|||
@mock_iam
|
||||
def check_create_policy_with_invalid_policy_document(test_case):
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.create_policy(
|
||||
PolicyName="TestCreatePolicy",
|
||||
PolicyDocument=json.dumps(test_case["document"]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue