so i decided this SPECIFIC test was not actually useful (scrapped it) so ignore the uselessness of the test. i guess my confusion is regarding fixtures in general. when i call client.attach_volume.assert_called_with()
against my moto client fixture i get error: AttributeError: 'function' object has no attribute 'assert_called_with'
conftest.py
@pytest.fixture(scope='function')
def client(aws_credentials):
with mock_ec2():
yield boto3.client('ec2', region_name=REGION)
lambda_function.py
def attach_ebs_volume(client, instance_id, region):
while utils.get_instance_state(client, instance_id) != "running":
print("waiting for instance to start")
time.sleep(5)
#TODO: timeout
for tag in utils.get_instance_tags(client, instance_id):
if tag['Key'] == "volume":
vol_tag = tag['Value']
volume_id = utils.get_ebs_by_name_tag(client, vol_tag)
client.attach_volume(
Device="/dev/xvdz",
InstanceId=instance_id,
VolumeId=volume_id
)
output from pytest:
@mock.patch('utils.get_instance_state')
@mock.patch('utils.get_instance_tags')
def test_attach_ebs_volume(mock_get_instance_tags, mock_get_instance_state, client):
volume_id = client.create_volume(Size=7, AvailabilityZone=REGION, TagSpecifications=VOLUME_TAGS)['VolumeId']
instance_id = client.run_instances(ImageId='ami-123', MinCount=1, MaxCount=1, TagSpecifications=INSTANCE_TAGS)['Instances'][0]['InstanceId']
mock_get_instance_state.return_value = 'running'
mock_get_instance_tags.return_value = RETURN_TAGS
r = lambda_function.attach_ebs_volume(client,
instance_id=instance_id,
region=REGION
)
> client.attach_volume.assert_called_with(Device="/dev/xvdz",
InstanceId=instance_id,
VolumeId=volume_id)
E AttributeError: 'function' object has no attribute 'assert_called_with'
i was trying to test that client.attach_volume
gets the right values. again, this is not actually that useful of a test but the functionality probably will in future tests
orgs.create_account()
. Are any of the following solutions feasible:orgs.create_account()
, then overwrite the ID of the account generated to match specorgs.create_account()
in a way that forces the generated ID to be set to the spec IDhey y'all, I need to mock an Organization that contains an account with a specific AWS ID, not the randomized value moto creates with
orgs.create_account()
. Are any of the following solutions feasible:
- call
orgs.create_account()
, then overwrite the ID of the account generated to match spec- call
orgs.create_account()
in a way that forces the generated ID to be set to the spec ID- mock an account join handshake procedure
Thanks!
I think option 1 should work. I don't think option 2 is possible. No idea about option 3
hello! This is my first time here :wave:
Has anyone else noticed that test_streaming_upload_from_file_to_presigned_url
is generating an error when it was fine yesterday? I can't find any existing open issues related to it, so I have raised an issue (spulec/moto#3080) and fixed it in a draft PR.
Advice would be appreciated :pray:
Hello. First time caller here.
I'm using moto to mock out SES and I want to verify that I've made a call to "send_raw_email". Poking around the code I've noticed that I can get the send messages from the "ses_backends". This solves my problem, but I'm just wondering if this is considered "best practice". How did others do this?
moto
doesn't support the more recent versions of boto
?