Explorar el Código

tests(config_flow): patch to avoid network access

Since the device setup now tries to fetch data before proceding with
entity creation, a network call is made within the scope of these tests.
Patch that call away.
Jason Rumney hace 7 meses
padre
commit
bff5067890
Se han modificado 1 ficheros con 15 adiciones y 3 borrados
  1. 15 3
      tests/test_config_flow.py

+ 15 - 3
tests/test_config_flow.py

@@ -49,8 +49,18 @@ def bypass_setup():
         yield
 
 
+@pytest.fixture
+def bypass_data_fetch():
+    """Prevent actual data fetching from the device."""
+    with patch(
+        "tinytuya.Device.status",
+        return_value={"1": True},
+    ):
+        yield
+
+
 @pytest.mark.asyncio
-async def test_init_entry(hass):
+async def test_init_entry(hass, bypass_data_fetch):
     """Test initialisation of the config flow."""
     entry = MockConfigEntry(
         domain=DOMAIN,
@@ -532,7 +542,7 @@ async def test_flow_choose_entities_creates_config_entry(hass, bypass_setup):
 
 
 @pytest.mark.asyncio
-async def test_options_flow_init(hass):
+async def test_options_flow_init(hass, bypass_data_fetch):
     """Test config flow options."""
     config_entry = MockConfigEntry(
         domain=DOMAIN,
@@ -618,7 +628,9 @@ async def test_options_flow_modifies_config(mock_test, hass, bypass_setup):
 
 @pytest.mark.asyncio
 @patch("custom_components.tuya_local.config_flow.async_test_connection")
-async def test_options_flow_fails_when_connection_fails(mock_test, hass):
+async def test_options_flow_fails_when_connection_fails(
+    mock_test, hass, bypass_data_fetch
+):
     mock_test.return_value = None
 
     config_entry = MockConfigEntry(