Repository: getmoto/moto
Pull request #8132 (2024-09-19 19:24:52)

NetworkManager: Update resource states to 'AVAILABLE' from 'PENDING' after create response
For NetworkManager: Update resource states to 'AVAILABLE' from 'PENDING' after create response to more accurately represent the mocked resource

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/getmoto/moto/pull/8132?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.49%. Comparing base [(`b95bfe9`)](https://app.codecov.io/gh/getmoto/moto/commit/b95bfe95cc0fec17a3ca13dd8c420211826cb380?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) to head [(`73eccba`)](https://app.codecov.io/gh/getmoto/moto/commit/73eccbaf13832532e24f039661160b3971429935?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto).

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


```diff
@@           Coverage Diff           @@
##           master    #8132   +/-   ##
=======================================
  Coverage   94.49%   94.49%           
=======================================
  Files        1150     1150           
  Lines       99025    99038   +13     
=======================================
+ Hits        93571    93584   +13     
  Misses       5454     5454           
```

| [Flag](https://app.codecov.io/gh/getmoto/moto/pull/8132/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/8132/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `28.81% <5.55%> (-0.01%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/getmoto/moto/pull/8132/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getmoto) | `94.46% <100.00%> (+<0.01%)` | :arrow_up: |

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/8132?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/networkmanager/models.py b/moto/networkmanager/models.py
index 238b29c8a..a60a3886d 100644
--- a/moto/networkmanager/models.py
+++ b/moto/networkmanager/models.py
@@ -270,6 +270,11 @@ class NetworkManagerBackend(BaseBackend):
         except (KeyError, ValueError, AttributeError):
             raise ResourceNotFound(arn)
 
+    def update_resource_state(self, resource_arn: str, state: str) -> None:
+        # Acceptable states: PENDING, AVAILABLE, DELETING, UPDATING
+        resource = self._get_resource_from_arn(resource_arn)
+        resource.state = state
+
     def create_global_network(
         self,
         description: Optional[str],
diff --git a/moto/networkmanager/responses.py b/moto/networkmanager/responses.py
index d64cf8e1a..443db2e72 100644
--- a/moto/networkmanager/responses.py
+++ b/moto/networkmanager/responses.py
@@ -27,7 +27,11 @@ class NetworkManagerResponse(BaseResponse):
             description=description,
             tags=tags,
         )
-        return json.dumps(dict(GlobalNetwork=global_network.to_dict()))
+        resp_dict = dict(GlobalNetwork=global_network.to_dict())
+        self.networkmanager_backend.update_resource_state(
+            global_network.global_network_arn, "AVAILABLE"
+        )
+        return json.dumps(resp_dict)
 
     def create_core_network(self) -> str:
         params = json.loads(self.body)
@@ -43,7 +47,11 @@ class NetworkManagerResponse(BaseResponse):
             policy_document=policy_document,
             client_token=client_token,
         )
-        return json.dumps(dict(CoreNetwork=core_network.to_dict()))
+        resp_dict = dict(CoreNetwork=core_network.to_dict())
+        self.networkmanager_backend.update_resource_state(
+            core_network.core_network_arn, "AVAILABLE"
+        )
+        return json.dumps(resp_dict)
 
     def delete_core_network(self) -> str:
         core_network_id = unquote(self.path.split("/")[-1])
@@ -122,7 +130,9 @@ class NetworkManagerResponse(BaseResponse):
             location=location,
             tags=tags,
         )
-        return json.dumps(dict(Site=site.to_dict()))
+        resp_dict = dict(Site=site.to_dict())
+        self.networkmanager_backend.update_resource_state(site.site_arn, "AVAILABLE")
+        return json.dumps(resp_dict)
 
     def delete_site(self) -> str:
         global_network_id = unquote(self.path.split("/")[-3])
@@ -166,7 +176,9 @@ class NetworkManagerResponse(BaseResponse):
             site_id=site_id,
             tags=tags,
         )
-        return json.dumps(dict(Link=link.to_dict()))
+        resp_dict = dict(Link=link.to_dict())
+        self.networkmanager_backend.update_resource_state(link.link_arn, "AVAILABLE")
+        return json.dumps(resp_dict)
 
     def get_links(self) -> str:
         params = self._get_params()
@@ -222,7 +234,11 @@ class NetworkManagerResponse(BaseResponse):
             site_id=site_id,
             tags=tags,
         )
-        return json.dumps(dict(Device=device.to_dict()))
+        resp_dict = dict(Device=device.to_dict())
+        self.networkmanager_backend.update_resource_state(
+            device.device_arn, "AVAILABLE"
+        )
+        return json.dumps(resp_dict)
 
     def get_devices(self) -> str:
         params = self._get_params()


Test patch:
diff --git a/tests/test_events/test_events_integration.py b/tests/test_events/test_events_integration.py
index 074c5b76b..7e03c74e3 100644
--- a/tests/test_events/test_events_integration.py
+++ b/tests/test_events/test_events_integration.py
@@ -1,9 +1,11 @@
+import contextlib
 import json
 import os
 from datetime import datetime
 from unittest import SkipTest, mock
 
 import boto3
+import pytest
 
 from moto import mock_aws, settings
 from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
@@ -110,16 +112,23 @@ def test_send_to_sqs_fifo_queue():
 
     # when
     event_time = datetime(2021, 1, 1, 12, 23, 34)
-    client_events.put_events(
-        Entries=[
-            {
-                "Time": event_time,
-                "Source": "source",
-                "DetailType": "type",
-                "Detail": json.dumps({"key": "value"}),
-            }
-        ]
+    # Catch and validate a UserWarning when running locally.
+    context = (
+        pytest.warns(UserWarning, match="you must enable content-based deduplication")
+        if not settings.TEST_SERVER_MODE
+        else contextlib.nullcontext()
     )
+    with context:
+        client_events.put_events(
+            Entries=[
+                {
+                    "Time": event_time,
+                    "Source": "source",
+                    "DetailType": "type",
+                    "Detail": json.dumps({"key": "value"}),
+                }
+            ]
+        )
 
     # then
     response = client_sqs.receive_message(
diff --git a/tests/test_networkmanager/test_networkmanager.py b/tests/test_networkmanager/test_networkmanager.py
index 0a35d08c5..09bfc2663 100644
--- a/tests/test_networkmanager/test_networkmanager.py
+++ b/tests/test_networkmanager/test_networkmanager.py
@@ -36,6 +36,10 @@ def test_create_global_network():
     assert global_network["Tags"] == [{"Key": "Name", "Value": "TestNetwork"}]
     assert global_network["State"] == "PENDING"
 
+    global_network = client.describe_global_networks()["GlobalNetworks"][0]
+    assert global_network["GlobalNetworkId"] == resp["GlobalNetwork"]["GlobalNetworkId"]
+    assert global_network["State"] == "AVAILABLE"
+
 
 @mock_aws
 def test_create_core_network():