Repository: getmoto/moto
Pull request #7616 (2024-04-21 12:30:53)

EC2: describe_addresses_attributes()
Very bare-bones implementation, but should fix the CI

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/getmoto/moto/pull/7616?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 94.19%. Comparing base [(`9aef694`)](https://app.codecov.io/gh/getmoto/moto/commit/9aef6944da6a6f1b84be99cefb34f1724e6ca58f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) to head [(`5860071`)](https://app.codecov.io/gh/getmoto/moto/pull/7616?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).
> Report is 194 commits behind head on master.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #7616      +/-   ##
==========================================
- Coverage   95.88%   94.19%   -1.69%     
==========================================
  Files         843     1072     +229     
  Lines       82578    92168    +9590     
==========================================
+ Hits        79178    86820    +7642     
- Misses       3400     5348    +1948     
```

| [Flag](https://app.codecov.io/gh/getmoto/moto/pull/7616/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | Coverage Δ | |
|---|---|---|
| [servertests](https://app.codecov.io/gh/getmoto/moto/pull/7616/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `29.47% <33.33%> (-3.05%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/getmoto/moto/pull/7616/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `94.16% <100.00%> (-1.69%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto#carryforward-flags-in-the-pull-request-comment) to find out more.


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/getmoto/moto/pull/7616?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).


Patch:
diff --git a/moto/ec2/models/elastic_ip_addresses.py b/moto/ec2/models/elastic_ip_addresses.py
index e435e3c8e..fdc14d2d0 100644
--- a/moto/ec2/models/elastic_ip_addresses.py
+++ b/moto/ec2/models/elastic_ip_addresses.py
@@ -239,6 +239,11 @@ class ElasticAddressBackend:
 
         return matches
 
+    def describe_addresses_attribute(
+        self, allocation_ids: Optional[List[str]] = None
+    ) -> List[ElasticAddress]:
+        return self.describe_addresses(allocation_ids)
+
     def disassociate_address(
         self, address: Optional[str] = None, association_id: Optional[str] = None
     ) -> None:
diff --git a/moto/ec2/responses/elastic_ip_addresses.py b/moto/ec2/responses/elastic_ip_addresses.py
index c421fc8c9..ac9d1729b 100644
--- a/moto/ec2/responses/elastic_ip_addresses.py
+++ b/moto/ec2/responses/elastic_ip_addresses.py
@@ -82,6 +82,13 @@ class ElasticIPAddresses(EC2BaseResponse):
         template = self.response_template(DESCRIBE_ADDRESS_RESPONSE)
         return template.render(addresses=addresses)
 
+    def describe_addresses_attribute(self) -> str:
+        self.error_on_dryrun()
+        allocation_ids = self._get_multi_param("AllocationId")
+        addresses = self.ec2_backend.describe_addresses_attribute(allocation_ids)
+        template = self.response_template(DESCRIBE_ADDRESS_ATTRIBUTE_RESPONSE)
+        return template.render(addresses=addresses)
+
     def disassociate_address(self) -> str:
         if (
             "PublicIp" not in self.querystring
@@ -180,6 +187,26 @@ DESCRIBE_ADDRESS_RESPONSE = """<DescribeAddressesResponse xmlns="http://ec2.amaz
   </addressesSet>
 </DescribeAddressesResponse>"""
 
+DESCRIBE_ADDRESS_ATTRIBUTE_RESPONSE = """<DescribeAddressesAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
+  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
+  <addressSet>
+    {% for address in addresses %}
+        <item>
+          <publicIp>{{ address.public_ip }}</publicIp>
+          {% if address.allocation_id %}
+            <allocationId>{{ address.allocation_id }}</allocationId>
+          {% endif %}
+          {% if address.ptrRecord %}
+            <ptrRecord>{{ address.ptrRecord }}</ptrRecord>
+          {% endif %}
+          {% if address.ptrRecordUpdate %}
+            <ptrRecordUpdate>{{ address.ptrRecordUpdate }}</ptrRecordUpdate>
+          {% endif %}
+        </item>
+    {% endfor %}
+  </addressSet>
+</DescribeAddressesAttributeResponse>"""
+
 DISASSOCIATE_ADDRESS_RESPONSE = """<DisassociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
   <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
   <return>true</return>


Test patch:
diff --git a/tests/test_ec2/test_elastic_ip_addresses.py b/tests/test_ec2/test_elastic_ip_addresses.py
index c43884291..c891173af 100644
--- a/tests/test_ec2/test_elastic_ip_addresses.py
+++ b/tests/test_ec2/test_elastic_ip_addresses.py
@@ -708,3 +708,16 @@ def test_describe_addresses_with_vpc_associated_eni():
     assert address["PrivateIpAddress"] == eni.private_ip_address
     assert address["AssociationId"] == association_id
     assert address["NetworkInterfaceOwnerId"] == eni.owner_id
+
+
+@mock_aws
+def test_describe_addresses_attributes():
+    client = boto3.client("ec2", region_name="us-east-1")
+    eip = client.allocate_address(Domain="vpc")
+
+    addresses = client.describe_addresses_attribute(
+        AllocationIds=[eip["AllocationId"]], Attribute="domain-name"
+    )["Addresses"]
+    assert addresses == [
+        {"PublicIp": eip["PublicIp"], "AllocationId": eip["AllocationId"]}
+    ]