Use SsdpServiceInfo for ssdp tests (part 2) (#60322)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-25 16:45:35 +01:00 committed by GitHub
parent 3399c90936
commit 2468724378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 68 deletions

View File

@ -101,7 +101,7 @@ class _SsdpServiceDescription:
ssdp_usn: str ssdp_usn: str
ssdp_st: str ssdp_st: str
ssdp_location: str ssdp_location: str | None = None
ssdp_nt: str | None = None ssdp_nt: str | None = None
ssdp_udn: str | None = None ssdp_udn: str | None = None
ssdp_ext: str | None = None ssdp_ext: str | None = None

View File

@ -5,7 +5,7 @@ import pytest
import respx import respx
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components import dhcp, zeroconf from homeassistant.components import dhcp, ssdp, zeroconf
from homeassistant.components.axis import config_flow from homeassistant.components.axis import config_flow
from homeassistant.components.axis.const import ( from homeassistant.components.axis.const import (
CONF_EVENTS, CONF_EVENTS,
@ -263,32 +263,36 @@ async def test_reauth_flow_update_configuration(hass):
), ),
( (
SOURCE_SSDP, SOURCE_SSDP,
{ ssdp.SsdpServiceInfo(
"st": "urn:axis-com:service:BasicService:1", ssdp_usn="mock_usn",
"usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1", ssdp_st="mock_st",
"ext": "", upnp={
"server": "Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP devices/1.8.7", "st": "urn:axis-com:service:BasicService:1",
"deviceType": "urn:schemas-upnp-org:device:Basic:1", "usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1",
"friendlyName": f"AXIS M1065-LW - {MAC}", "ext": "",
"manufacturer": "AXIS", "server": "Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP devices/1.8.7",
"manufacturerURL": "http://www.axis.com/", "deviceType": "urn:schemas-upnp-org:device:Basic:1",
"modelDescription": "AXIS M1065-LW Network Camera", "friendlyName": f"AXIS M1065-LW - {MAC}",
"modelName": "AXIS M1065-LW", "manufacturer": "AXIS",
"modelNumber": "M1065-LW", "manufacturerURL": "http://www.axis.com/",
"modelURL": "http://www.axis.com/", "modelDescription": "AXIS M1065-LW Network Camera",
"serialNumber": MAC, "modelName": "AXIS M1065-LW",
"UDN": f"uuid:Upnp-BasicDevice-1_0-{MAC}", "modelNumber": "M1065-LW",
"serviceList": { "modelURL": "http://www.axis.com/",
"service": { "serialNumber": MAC,
"serviceType": "urn:axis-com:service:BasicService:1", "UDN": f"uuid:Upnp-BasicDevice-1_0-{MAC}",
"serviceId": "urn:axis-com:serviceId:BasicServiceId", "serviceList": {
"controlURL": "/upnp/control/BasicServiceId", "service": {
"eventSubURL": "/upnp/event/BasicServiceId", "serviceType": "urn:axis-com:service:BasicService:1",
"SCPDURL": "/scpd_basic.xml", "serviceId": "urn:axis-com:serviceId:BasicServiceId",
} "controlURL": "/upnp/control/BasicServiceId",
"eventSubURL": "/upnp/event/BasicServiceId",
"SCPDURL": "/scpd_basic.xml",
}
},
"presentationURL": f"http://{DEFAULT_HOST}:80/",
}, },
"presentationURL": f"http://{DEFAULT_HOST}:80/", ),
},
), ),
( (
SOURCE_ZEROCONF, SOURCE_ZEROCONF,
@ -354,11 +358,15 @@ async def test_discovery_flow(hass, source: str, discovery_info: dict):
), ),
( (
SOURCE_SSDP, SOURCE_SSDP,
{ ssdp.SsdpServiceInfo(
"friendlyName": f"AXIS M1065-LW - {MAC}", ssdp_usn="mock_usn",
"serialNumber": MAC, ssdp_st="mock_st",
"presentationURL": f"http://{DEFAULT_HOST}:80/", upnp={
}, "friendlyName": f"AXIS M1065-LW - {MAC}",
"serialNumber": MAC,
"presentationURL": f"http://{DEFAULT_HOST}:80/",
},
),
), ),
( (
SOURCE_ZEROCONF, SOURCE_ZEROCONF,
@ -403,11 +411,15 @@ async def test_discovered_device_already_configured(
), ),
( (
SOURCE_SSDP, SOURCE_SSDP,
{ ssdp.SsdpServiceInfo(
"friendlyName": f"AXIS M1065-LW - {MAC}", ssdp_usn="mock_usn",
"serialNumber": MAC, ssdp_st="mock_st",
"presentationURL": "http://2.3.4.5:8080/", upnp={
}, "friendlyName": f"AXIS M1065-LW - {MAC}",
"serialNumber": MAC,
"presentationURL": "http://2.3.4.5:8080/",
},
),
8080, 8080,
), ),
( (
@ -474,11 +486,15 @@ async def test_discovery_flow_updated_configuration(
), ),
( (
SOURCE_SSDP, SOURCE_SSDP,
{ ssdp.SsdpServiceInfo(
"friendlyName": "", ssdp_usn="mock_usn",
"serialNumber": "01234567890", ssdp_st="mock_st",
"presentationURL": "", upnp={
}, "friendlyName": "",
"serialNumber": "01234567890",
"presentationURL": "",
},
),
), ),
( (
SOURCE_ZEROCONF, SOURCE_ZEROCONF,
@ -518,11 +534,15 @@ async def test_discovery_flow_ignore_non_axis_device(
), ),
( (
SOURCE_SSDP, SOURCE_SSDP,
{ ssdp.SsdpServiceInfo(
"friendlyName": f"AXIS M1065-LW - {MAC}", ssdp_usn="mock_usn",
"serialNumber": MAC, ssdp_st="mock_st",
"presentationURL": "http://169.254.3.4:80/", upnp={
}, "friendlyName": f"AXIS M1065-LW - {MAC}",
"serialNumber": MAC,
"presentationURL": "http://169.254.3.4:80/",
},
),
), ),
( (
SOURCE_ZEROCONF, SOURCE_ZEROCONF,

View File

@ -7,7 +7,7 @@ from aionanoleaf import InvalidToken, NanoleafException, Unauthorized, Unavailab
import pytest import pytest
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import zeroconf from homeassistant.components import ssdp, zeroconf
from homeassistant.components.nanoleaf.const import DOMAIN from homeassistant.components.nanoleaf.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_TOKEN from homeassistant.const import CONF_HOST, CONF_TOKEN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -462,11 +462,15 @@ async def test_ssdp_discovery(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_SSDP}, context={"source": config_entries.SOURCE_SSDP},
data={ data=ssdp.SsdpServiceInfo(
"_host": TEST_HOST, ssdp_usn="mock_usn",
"nl-devicename": TEST_NAME, ssdp_st="mock_st",
"nl-deviceid": TEST_DEVICE_ID, upnp={
}, "_host": TEST_HOST,
"nl-devicename": TEST_NAME,
"nl-deviceid": TEST_DEVICE_ID,
},
),
) )
assert result["type"] == "form" assert result["type"] == "form"

View File

@ -4,7 +4,7 @@ from unittest.mock import patch
from pyoctoprintapi import ApiError, DiscoverySettings from pyoctoprintapi import ApiError, DiscoverySettings
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
from homeassistant.components import zeroconf from homeassistant.components import ssdp, zeroconf
from homeassistant.components.octoprint.const import DOMAIN from homeassistant.components.octoprint.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -235,11 +235,15 @@ async def test_show_ssdp_form(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_SSDP}, context={"source": config_entries.SOURCE_SSDP},
data={ data=ssdp.SsdpServiceInfo(
"presentationURL": "http://192.168.1.123:80/discovery/device.xml", ssdp_usn="mock_usn",
"port": 80, ssdp_st="mock_st",
"UDN": "uuid:83747482", upnp={
}, "presentationURL": "http://192.168.1.123:80/discovery/device.xml",
"port": 80,
"UDN": "uuid:83747482",
},
),
) )
assert result["type"] == "form" assert result["type"] == "form"
assert not result["errors"] assert not result["errors"]
@ -512,11 +516,15 @@ async def test_duplicate_ssdp_ignored(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_SSDP}, context={"source": config_entries.SOURCE_SSDP},
data={ data=ssdp.SsdpServiceInfo(
"presentationURL": "http://192.168.1.123:80/discovery/device.xml", ssdp_usn="mock_usn",
"port": 80, ssdp_st="mock_st",
"UDN": "uuid:83747482", upnp={
}, "presentationURL": "http://192.168.1.123:80/discovery/device.xml",
"port": 80,
"UDN": "uuid:83747482",
},
),
) )
assert result["type"] == "abort" assert result["type"] == "abort"
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"

View File

@ -4,7 +4,7 @@ from unittest.mock import patch
import pytest import pytest
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import dhcp, zeroconf from homeassistant.components import dhcp, ssdp, zeroconf
from homeassistant.components.yeelight.config_flow import MODEL_UNKNOWN, CannotConnect from homeassistant.components.yeelight.config_flow import MODEL_UNKNOWN, CannotConnect
from homeassistant.components.yeelight.const import ( from homeassistant.components.yeelight.const import (
CONF_DETECTED_MODEL, CONF_DETECTED_MODEL,
@ -52,6 +52,12 @@ DEFAULT_CONFIG = {
CONF_NIGHTLIGHT_SWITCH: DEFAULT_NIGHTLIGHT_SWITCH, CONF_NIGHTLIGHT_SWITCH: DEFAULT_NIGHTLIGHT_SWITCH,
} }
SSDP_INFO = ssdp.SsdpServiceInfo(
ssdp_usn="mock_usn",
ssdp_st="mock_st",
upnp=CAPABILITIES,
)
async def test_discovery(hass: HomeAssistant): async def test_discovery(hass: HomeAssistant):
"""Test setting up discovery.""" """Test setting up discovery."""
@ -627,7 +633,7 @@ async def test_discovered_ssdp(hass):
f"{MODULE_CONFIG_FLOW}.AsyncBulb", return_value=mocked_bulb f"{MODULE_CONFIG_FLOW}.AsyncBulb", return_value=mocked_bulb
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=CAPABILITIES DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=SSDP_INFO
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -656,7 +662,7 @@ async def test_discovered_ssdp(hass):
f"{MODULE_CONFIG_FLOW}.AsyncBulb", return_value=mocked_bulb f"{MODULE_CONFIG_FLOW}.AsyncBulb", return_value=mocked_bulb
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=CAPABILITIES DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=SSDP_INFO
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -719,7 +725,7 @@ async def test_discovered_zeroconf(hass):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_SSDP}, context={"source": config_entries.SOURCE_SSDP},
data=CAPABILITIES, data=SSDP_INFO,
) )
await hass.async_block_till_done() await hass.async_block_till_done()