Mock out network.util.async_get_source_ip in tests (#55592)
This commit is contained in:
parent
363320eedb
commit
7dbe8070f7
12 changed files with 159 additions and 80 deletions
|
@ -64,7 +64,7 @@ async def _async_run_mocked_scan(hass, mock_ssdp_response, mock_get_ssdp):
|
|||
return mock_init
|
||||
|
||||
|
||||
async def test_scan_match_st(hass, caplog):
|
||||
async def test_scan_match_st(hass, caplog, mock_get_source_ip):
|
||||
"""Test matching based on ST."""
|
||||
mock_ssdp_response = {
|
||||
"st": "mock-st",
|
||||
|
@ -91,7 +91,7 @@ async def test_scan_match_st(hass, caplog):
|
|||
assert "Failed to fetch ssdp data" not in caplog.text
|
||||
|
||||
|
||||
async def test_partial_response(hass, caplog):
|
||||
async def test_partial_response(hass, caplog, mock_get_source_ip):
|
||||
"""Test location and st missing."""
|
||||
mock_ssdp_response = {
|
||||
"usn": "mock-usn",
|
||||
|
@ -107,7 +107,9 @@ async def test_partial_response(hass, caplog):
|
|||
@pytest.mark.parametrize(
|
||||
"key", (ssdp.ATTR_UPNP_MANUFACTURER, ssdp.ATTR_UPNP_DEVICE_TYPE)
|
||||
)
|
||||
async def test_scan_match_upnp_devicedesc(hass, aioclient_mock, key):
|
||||
async def test_scan_match_upnp_devicedesc(
|
||||
hass, aioclient_mock, key, mock_get_source_ip
|
||||
):
|
||||
"""Test matching based on UPnP device description data."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -134,7 +136,7 @@ async def test_scan_match_upnp_devicedesc(hass, aioclient_mock, key):
|
|||
}
|
||||
|
||||
|
||||
async def test_scan_not_all_present(hass, aioclient_mock):
|
||||
async def test_scan_not_all_present(hass, aioclient_mock, mock_get_source_ip):
|
||||
"""Test match fails if some specified attributes are not present."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -163,7 +165,7 @@ async def test_scan_not_all_present(hass, aioclient_mock):
|
|||
assert not mock_init.mock_calls
|
||||
|
||||
|
||||
async def test_scan_not_all_match(hass, aioclient_mock):
|
||||
async def test_scan_not_all_match(hass, aioclient_mock, mock_get_source_ip):
|
||||
"""Test match fails if some specified attribute values differ."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -194,7 +196,9 @@ async def test_scan_not_all_match(hass, aioclient_mock):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("exc", [asyncio.TimeoutError, aiohttp.ClientError])
|
||||
async def test_scan_description_fetch_fail(hass, aioclient_mock, exc):
|
||||
async def test_scan_description_fetch_fail(
|
||||
hass, aioclient_mock, exc, mock_get_source_ip
|
||||
):
|
||||
"""Test failing to fetch description."""
|
||||
aioclient_mock.get("http://1.1.1.1", exc=exc)
|
||||
mock_ssdp_response = {
|
||||
|
@ -224,7 +228,7 @@ async def test_scan_description_fetch_fail(hass, aioclient_mock, exc):
|
|||
]
|
||||
|
||||
|
||||
async def test_scan_description_parse_fail(hass, aioclient_mock):
|
||||
async def test_scan_description_parse_fail(hass, aioclient_mock, mock_get_source_ip):
|
||||
"""Test invalid XML."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -250,7 +254,7 @@ async def test_scan_description_parse_fail(hass, aioclient_mock):
|
|||
assert not mock_init.mock_calls
|
||||
|
||||
|
||||
async def test_invalid_characters(hass, aioclient_mock):
|
||||
async def test_invalid_characters(hass, aioclient_mock, mock_get_source_ip):
|
||||
"""Test that we replace bad characters with placeholders."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -295,7 +299,7 @@ async def test_invalid_characters(hass, aioclient_mock):
|
|||
@patch("homeassistant.components.ssdp.SSDPListener.async_search")
|
||||
@patch("homeassistant.components.ssdp.SSDPListener.async_stop")
|
||||
async def test_start_stop_scanner(
|
||||
async_stop_mock, async_search_mock, async_start_mock, hass
|
||||
async_stop_mock, async_search_mock, async_start_mock, hass, mock_get_source_ip
|
||||
):
|
||||
"""Test we start and stop the scanner."""
|
||||
assert await async_setup_component(hass, ssdp.DOMAIN, {ssdp.DOMAIN: {}})
|
||||
|
@ -318,7 +322,9 @@ async def test_start_stop_scanner(
|
|||
assert async_stop_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_unexpected_exception_while_fetching(hass, aioclient_mock, caplog):
|
||||
async def test_unexpected_exception_while_fetching(
|
||||
hass, aioclient_mock, caplog, mock_get_source_ip
|
||||
):
|
||||
"""Test unexpected exception while fetching."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -355,7 +361,9 @@ async def test_unexpected_exception_while_fetching(hass, aioclient_mock, caplog)
|
|||
assert "Failed to fetch ssdp data from: http://1.1.1.1" in caplog.text
|
||||
|
||||
|
||||
async def test_scan_with_registered_callback(hass, aioclient_mock, caplog):
|
||||
async def test_scan_with_registered_callback(
|
||||
hass, aioclient_mock, caplog, mock_get_source_ip
|
||||
):
|
||||
"""Test matching based on callback."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -490,7 +498,9 @@ async def test_scan_with_registered_callback(hass, aioclient_mock, caplog):
|
|||
assert "Failed to callback info" in caplog.text
|
||||
|
||||
|
||||
async def test_unsolicited_ssdp_registered_callback(hass, aioclient_mock, caplog):
|
||||
async def test_unsolicited_ssdp_registered_callback(
|
||||
hass, aioclient_mock, caplog, mock_get_source_ip
|
||||
):
|
||||
"""Test matching based on callback can handle unsolicited ssdp traffic without st."""
|
||||
aioclient_mock.get(
|
||||
"http://10.6.9.12:1400/xml/device_description.xml",
|
||||
|
@ -578,7 +588,7 @@ async def test_unsolicited_ssdp_registered_callback(hass, aioclient_mock, caplog
|
|||
assert "Failed to callback info" not in caplog.text
|
||||
|
||||
|
||||
async def test_scan_second_hit(hass, aioclient_mock, caplog):
|
||||
async def test_scan_second_hit(hass, aioclient_mock, caplog, mock_get_source_ip):
|
||||
"""Test matching on second scan."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1",
|
||||
|
@ -752,7 +762,7 @@ _ADAPTERS_WITH_MANUAL_CONFIG = [
|
|||
]
|
||||
|
||||
|
||||
async def test_async_detect_interfaces_setting_empty_route(hass):
|
||||
async def test_async_detect_interfaces_setting_empty_route(hass, mock_get_source_ip):
|
||||
"""Test without default interface config and the route returns nothing."""
|
||||
mock_get_ssdp = {
|
||||
"mock-domain": [
|
||||
|
@ -803,7 +813,7 @@ async def test_async_detect_interfaces_setting_empty_route(hass):
|
|||
}
|
||||
|
||||
|
||||
async def test_bind_failure_skips_adapter(hass, caplog):
|
||||
async def test_bind_failure_skips_adapter(hass, caplog, mock_get_source_ip):
|
||||
"""Test that an adapter with a bind failure is skipped."""
|
||||
mock_get_ssdp = {
|
||||
"mock-domain": [
|
||||
|
@ -872,7 +882,7 @@ async def test_bind_failure_skips_adapter(hass, caplog):
|
|||
}
|
||||
|
||||
|
||||
async def test_ipv4_does_additional_search_for_sonos(hass, caplog):
|
||||
async def test_ipv4_does_additional_search_for_sonos(hass, caplog, mock_get_source_ip):
|
||||
"""Test that only ipv4 does an additional search for Sonos."""
|
||||
mock_get_ssdp = {
|
||||
"mock-domain": [
|
||||
|
@ -928,7 +938,9 @@ async def test_ipv4_does_additional_search_for_sonos(hass, caplog):
|
|||
}
|
||||
|
||||
|
||||
async def test_location_change_evicts_prior_location_from_cache(hass, aioclient_mock):
|
||||
async def test_location_change_evicts_prior_location_from_cache(
|
||||
hass, aioclient_mock, mock_get_source_ip
|
||||
):
|
||||
"""Test that a location change for a UDN will evict the prior location from the cache."""
|
||||
mock_get_ssdp = {
|
||||
"hue": [{"manufacturer": "Signify", "modelName": "Philips hue bridge 2015"}]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue