remove backend logic & py27 incompatible timezone
This commit is contained in:
parent
51e7002cbb
commit
0423be259a
@ -15,12 +15,10 @@ from dateutil.tz import tzutc
|
||||
from moto import mock_iam, mock_iam_deprecated
|
||||
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
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from tests.helpers import requires_boto_gte
|
||||
from uuid import uuid4
|
||||
|
||||
@ -1228,9 +1226,7 @@ def test_boto3_get_credential_report_content():
|
||||
UserName=username, AccessKeyId=key1["AccessKeyId"], Status="Inactive"
|
||||
)
|
||||
key1 = conn.create_access_key(UserName=username)["AccessKey"]
|
||||
iam_backend = get_backend("iam")["global"]
|
||||
timestamp = datetime.now(tz=timezone.utc)
|
||||
iam_backend.users[username].access_keys[1].last_used = timestamp
|
||||
timestamp = datetime.utcnow()
|
||||
with assert_raises(ClientError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
@ -1246,14 +1242,12 @@ def test_boto3_get_credential_report_content():
|
||||
user = next(report_dict)
|
||||
user["user"].should.equal("my-user")
|
||||
user["access_key_1_active"].should.equal("false")
|
||||
user["access_key_1_last_rotated"].should.equal(
|
||||
timestamp.isoformat(timespec="seconds")
|
||||
user["access_key_1_last_rotated"].should.match(
|
||||
timestamp.strftime(datetime.utcnow(), "%Y-%m-%d")
|
||||
)
|
||||
user["access_key_1_last_used_date"].should.equal("N/A")
|
||||
user["access_key_2_active"].should.equal("true")
|
||||
user["access_key_2_last_used_date"].should.equal(
|
||||
timestamp.isoformat(timespec="seconds")
|
||||
)
|
||||
user["access_key_2_last_used_date"].should.equal("N/A")
|
||||
|
||||
|
||||
@requires_boto_gte("2.39")
|
||||
@ -1438,26 +1432,6 @@ def test_get_access_key_last_used_when_unused():
|
||||
resp["UserName"].should.equal(create_key_response["UserName"])
|
||||
|
||||
|
||||
@mock_iam
|
||||
def test_get_access_key_last_used_when_used():
|
||||
iam = boto3.resource("iam", region_name="us-east-1")
|
||||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_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
|
||||
iam_backend = get_backend("iam")["global"]
|
||||
iam_backend.users[username].access_keys[0].last_used = datetime.utcnow()
|
||||
resp = client.get_access_key_last_used(
|
||||
AccessKeyId=create_key_response["AccessKeyId"]
|
||||
)
|
||||
datetime.strftime(
|
||||
resp["AccessKeyLastUsed"]["LastUsedDate"], "%Y-%m-%d"
|
||||
).should.equal(datetime.strftime(datetime.utcnow(), "%Y-%m-%d"))
|
||||
|
||||
|
||||
@mock_iam
|
||||
def test_upload_ssh_public_key():
|
||||
iam = boto3.resource("iam", region_name="us-east-1")
|
||||
|
Loading…
Reference in New Issue
Block a user