How describe a network interface attribute for a mock_ec2 in test_elastic_network_interfaces_get_by_description function?
@mock_ec2 def test_elastic_network_interfaces_get_by_description():
ec2 = boto3.resource("ec2", region_name="us-east-1")
ec2_client= ec2.meta.client
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
vpc.reload()
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock="10.0.0.0/24",
AvailabilityZone="us-east-1a")
desc = str(uuid4())
eni1 = ec2.create_network_interface(
SubnetId=subnet.id, PrivateIpAddress="10.0.10.5", Description=desc )
# The status of the new interface should be 'available'
waiter = ec2_client.get_waiter("network_interface_available")
waiter.wait(NetworkInterfaceIds=[eni1.id])
eni1.modify_attribute(SourceDestCheck={'Value': False})
eni1.reload()
response = eni1.describe_attribute(Attribute='description')
python 3.7
mock 4.0.3
moto 2.1.0
sure 2.0.0
aiobotocore 1.4.2
boto3 1.18.2
botocore 1.20.106
coverage 5.5
What is needed to implement or fix to run or pass the test?
If after update or scaffold-script of moto library the method is not implemented in a library yet and continue an error like this :
NotImplementedError: ElasticNetworkInterfaces(AmazonVPC).describe_network_interface_attribute is not yet implemented
An easy solution for the test is a monkeypatch function that lets simulates the method not implemented.
def client_mock(Attribute='description'): return { 'Attachment': { 'AttachTime': 34545, 'DeleteOnTermination': False, 'DeviceIndex': 123, 'NetworkCardIndex': 123, 'InstanceId': 'eni1.instanceid', }, 'Description': { 'Value': 'Vpc network inteface' }, 'Groups': [ { 'GroupName': 'name group', 'GroupId': 'grupoid' }, ], 'NetworkInterfaceId': 'eni.id', 'SourceDestCheck': { 'Value': False } }
and put it with attributes on the pass at respective the function or method
monkeypatch.setattr(eni1, "describe_attribute", client_mock)
If you know a better solution, please post it!