I have the following code for ssh using instance id.
filename.py -
def command(self,args):
ec2connect = boto3.client('ec2-instance-connect')
ec2connect.send_ssh_public_key(
InstanceId=args.instance_id,
InstanceOSUser=user_name,
SSHPublicKey=ssh_key_string,
AvailabilityZone=instance['Placement']['AvailabilityZone'])
out("connecting")
os.execl("user/bin/ssh","ssh","-l", username, ip_address)
def out(message):
print(message)
I am trying to test it by mocking my command function, I have tried @mock.patch(filename.command.botocore.session.Session.create_client)
and then asserting the message "connecting" to see if this ssh functionality is working. However I keep getting assertion failed. I am wondering if my mock patch is wrong and if there is a better way to mock ec2instanceconnect.