async def test_multicast_scan( udns_server: fake_udns.FakeUdns, multicast_scan: Scanner, ): udns_server.add_service( fake_udns.mrp_service("Apple TV", "Apple TV MRP", MRP_ID_1, address=IP_1)) udns_server.add_service( fake_udns.homesharing_service("abcd", "Apple TV HS 2", HSGID, address=IP_2)) udns_server.add_service( fake_udns.device_service("efgh", "Apple TV Device", address=IP_3)) atvs = await multicast_scan() assert len(atvs) == 3 # First device dev1 = _get_atv(atvs, IP_1) assert dev1 assert dev1.identifier == MRP_ID_1 # Second device dev2 = _get_atv(atvs, IP_2) assert dev2 assert dev2.identifier == "abcd" # Third device dev3 = _get_atv(atvs, IP_3) assert dev3 assert dev3.identifier == "efgh"
async def test_udns_scan_mrp(udns_server, udns_scan): udns_server.add_service(fake_udns.mrp_service("Apple TV", "Apple TV MRP", MRP_ID_1)) atvs = await udns_scan() assert len(atvs) == 1 assert_device(atvs[0], "Apple TV MRP", IP_LOCALHOST, MRP_ID_1, Protocol.MRP, 49152)
def setup_environment(self): airplay_port = self.server.port services = [] services.append( zeroconf_stub.homesharing_service(DMAP_ID, b"Apple TV 1", IP_1, b"aaaa")) services.append( zeroconf_stub.mrp_service( "DDDD", b"Apple TV 2", IP_2, MRP_ID, port=self.fake_atv.get_port(Protocol.MRP), )) services.append( zeroconf_stub.airplay_service("Apple TV 2", IP_2, AIRPLAY_ID, port=airplay_port)) zeroconf_stub.stub(pyatv, *services) self.fake_udns.add_service( fake_udns.mrp_service("DDDD", "Apple TV 2", MRP_ID, port=self.fake_atv.get_port(Protocol.MRP))) self.fake_udns.add_service( fake_udns.airplay_service("Apple TV 2", AIRPLAY_ID, port=airplay_port)) self.airplay_usecase.airplay_playback_playing() self.airplay_usecase.airplay_playback_idle()
def setup_environment(self): airplay_port = self.server.port self.fake_udns.add_service( fake_udns.homesharing_service(DMAP_ID, "Apple TV 1", "aaaa", address=IP_1)) self.fake_udns.add_service( fake_udns.mrp_service( "DDDD", "Apple TV 2", MRP_ID, address=IP_2, port=self.fake_atv.get_port(Protocol.MRP), )) self.fake_udns.add_service( fake_udns.airplay_service("Apple TV 2", AIRPLAY_ID, address=IP_2, port=airplay_port)) self.airplay_usecase.airplay_playback_playing() self.airplay_usecase.airplay_playback_idle()
def service1(model=None): return fake_udns.mrp_service( SERVICE_1_SERVICE_NAME, SERVICE_1_NAME, SERVICE_1_ID, addresses=[SERVICE_1_IP], model=model, )
def mrp_service_tvos_15(): return fake_udns.mrp_service( SERVICE_1_SERVICE_NAME, SERVICE_1_NAME, SERVICE_1_ID, addresses=[SERVICE_1_IP], version="19J346", )
async def test_scan_mrp(self): self.server.add_service( fake_udns.mrp_service('Apple TV', 'Apple TV MRP', MRP_ID_1)) atvs = await self.scan() self.assertEqual(len(atvs), 1) self.assertDevice(atvs[0], 'Apple TV MRP', IP_LOCALHOST, MRP_ID_1, Protocol.MRP, 49152)
async def test_scan_device_info(udns_server, udns_scan): udns_server.add_service(fake_udns.mrp_service("Apple TV", "Apple TV MRP", MRP_ID_1)) udns_server.add_service(fake_udns.airplay_service("Apple TV", AIRPLAY_ID)) atvs = await udns_scan() assert len(atvs) == 1 device_info = atvs[0].device_info assert device_info.mac == AIRPLAY_ID
async def test_unicast_scan_mrp(udns_server, unicast_scan): udns_server.add_service( fake_udns.mrp_service(MRP_SERVICE_NAME, MRP_NAME, MRP_ID, addresses=[IP_1], port=MRP_PORT)) atvs = await unicast_scan() assert len(atvs) == 1 assert_device(atvs[0], MRP_NAME, ip_address(IP_1), MRP_ID, Protocol.MRP, MRP_PORT)
async def test_multicast_scan_mrp_with_companion(udns_server, multicast_scan): udns_server.add_service( fake_udns.mrp_service(MRP_SERVICE_NAME, MRP_NAME, MRP_ID, addresses=[IP_1], port=MRP_PORT)) atvs = await multicast_scan(protocol=Protocol.MRP) assert len(atvs) == 1 assert_device(atvs[0], MRP_NAME, ip_address(IP_1), MRP_ID, Protocol.MRP, MRP_PORT)
async def test_multicast_scan_device_model(udns_server, multicast_scan): udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, address=IP_1, model="J105aAP")) atvs = await multicast_scan(protocol=Protocol.MRP) assert len(atvs) == 1 device_info = atvs[0].device_info assert device_info.model == DeviceModel.Gen4K
async def test_unicast_scan_device_model(udns_server, unicast_scan): udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, addresses=[IP_1], model="J105aAP")) atvs = await unicast_scan() assert len(atvs) == 1 device_info = atvs[0].device_info assert device_info.model == DeviceModel.Gen4K
async def test_multicast_scan_deep_sleeping_device(udns_server, multicast_scan): udns_server.sleep_proxy = True udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, addresses=[IP_1])) atvs = await multicast_scan() assert len(atvs) == 1 assert atvs[0].deep_sleep
async def test_multicast_scan_device_info(udns_server, multicast_scan): udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, addresses=[IP_1])) udns_server.add_service( fake_udns.airplay_service("Apple TV", AIRPLAY_ID, addresses=[IP_1])) atvs = await multicast_scan(protocol=Protocol.MRP) assert len(atvs) == 1 device_info = atvs[0].device_info assert device_info.mac == AIRPLAY_ID
async def test_multicast_scan_mrp(udns_server, multicast_scan): udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, addresses=[IP_1])) udns_server.add_service( fake_udns.device_service("efgh", "Apple TV Device", addresses=[IP_3])) atvs = await multicast_scan(protocol=Protocol.MRP) assert len(atvs) == 1 dev1 = _get_atv(atvs, IP_1) assert dev1 assert dev1.name == "Apple TV MRP 1" assert dev1.get_service(Protocol.MRP)
async def test_multicast_scan_for_particular_device(udns_server, multicast_scan): udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, addresses=[IP_1])) udns_server.add_service( fake_udns.homesharing_service("efgh", "Apple TV Device", HSGID, addresses=[IP_3])) atvs = await multicast_scan(identifier="efgh") assert len(atvs) == 1 assert atvs[0].name == "Apple TV Device" assert atvs[0].address == ip_address(IP_3)
async def test_multicast_scan_mrp_with_companion(udns_server, multicast_scan): udns_server.add_service( fake_udns.mrp_service("Apple TV 1", "Apple TV MRP 1", MRP_ID_1, addresses=[IP_1])) udns_server.add_service( fake_udns.companion_service("Companion", addresses=[IP_1], port=COMPANION_PORT)) atvs = await multicast_scan(protocol=Protocol.MRP) assert len(atvs) == 1 dev1 = _get_atv(atvs, IP_1) assert dev1 assert dev1.name == "Apple TV MRP 1" assert dev1.get_service(Protocol.MRP) companion = dev1.get_service(Protocol.Companion) assert companion assert companion.port == COMPANION_PORT
async def test_multicast_scan_mrp_with_companion(udns_server, multicast_scan: Scanner): udns_server.add_service( fake_udns.mrp_service(MRP_SERVICE_NAME, COMPANIOM_NAME, MRP_ID, addresses=[IP_1])) udns_server.add_service( fake_udns.companion_service(COMPANIOM_NAME, addresses=[IP_1], port=COMPANION_PORT)) atvs = await multicast_scan() assert len(atvs) == 1 dev = atvs[0] assert dev assert dev.name == COMPANIOM_NAME assert dev.get_service(Protocol.MRP) companion = dev.get_service(Protocol.Companion) assert companion assert companion.port == COMPANION_PORT
async def test_udns_missing_port(udns_server, udns_scan): udns_server.add_service(fake_udns.mrp_service("dummy", "dummy", "dummy", port=None)) atvs = await udns_scan() assert len(atvs) == 0
import pytest from pyatv.support import dns, mdns, net from tests import fake_udns from tests.support import dns_utils SERVICE_NAME = "Kitchen" MEDIAREMOTE_SERVICE = "_mediaremotetv._tcp.local" DEVICE_INFO_SERVICE = "_device-info._tcp._local" TEST_SERVICES = dict( [ fake_udns.mrp_service( SERVICE_NAME, SERVICE_NAME, "mrp_id", addresses=["127.0.0.1"], port=1234 ), ] ) def get_response_for_service( service: str, ) -> Tuple[dns.DnsMessage, Optional[fake_udns.FakeDnsService]]: req = mdns.create_request([service]) resp = fake_udns.create_response(req, TEST_SERVICES) return dns.DnsMessage().unpack(resp.pack()), TEST_SERVICES.get(service) def test_non_existing_service(): resp, _ = get_response_for_service("_missing")
async def test_missing_port(self): self.server.add_service( fake_udns.mrp_service('dummy', 'dummy', 'dummy', port=None)) atvs = await self.scan() self.assertEqual(len(atvs), 0)