-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does altering the backend pass between fixtures and tests #6859
Comments
Hi @WesleyHindle, I would argue that this the expected behaviour, actually. Two important notes:
So the timeline is:
|
Thank you the reply. Interesting to know that Am I wrong to assume by So if I want to keep some separation between fixtures and tests (and have a LastUsedDate set in the past) I'd have to do something like... @pytest.fixture
@freeze_time(date_181_days_ago)
def test_create_role_with_invalid_date(iam_client, sts):
role_name = "role_name_invalid_date"
user_name = "test.user"
response = iam_client.create_role(
RoleName=role_name,
AssumeRolePolicyDocument="example policy"
)
role_arn = response["Role"]["Arn"]
iam_client.create_user(UserName=user_name)
iam_client.attach_user_policy(
UserName=user_name,
PolicyArn="arn:aws:iam::aws:policy/AmazonS3FullAccess"
)
assumed_role = sts.assume_role(
RoleArn = role_arn,
RoleSessionName = "temp_session"
)
assumed_role_creds = assumed_role["Credentials"]
return assumed_role_creds, role_name
def test_get_all_roles(test_create_role_with_invalid_date):
iam_backend, role_name = test_create_role_with_invalid_date
iam_backend = get_backend("iam")[DEFAULT_ACCOUNT_ID]["global"]
iam_backend.get_role(role_name).last_used = date_181_days_ago
iam_backend = boto3.client(
"iam",
aws_access_key_id = assumed_role_creds["AccessKeyId"],
aws_secret_access_key = assumed_role_creds["SecretAccessKey"],
aws_session_token = assumed_role_creds["SessionToken"]
)
r = iam_backend.get_role(RoleName=role_name)
print("----------------Output from actual test-----------------")
print(r)
assert r["LastUsedDate"] == whatever the date was 181 days ago? |
No, you can re-use the same role to call any number of methods.
|
This question has been answered, as far as I can tell, so I'll close this. Let us know if you have any other questions. |
Relates to #5927 and #6809
moto 4.2.3
I'm wanting to setup a fake role which is used in a fixture, with a fake last used date. I then want to return this value for use in an actual test, so I can separate the setup from the test.
So far I have
So the print from the fixture outputs the correct faked date, when the print from the test outputs the wrong (current) date.
Is this a quirk of moto, or I've used the backend stuff incorrectly between functuions?
The text was updated successfully, but these errors were encountered: