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()
async def test_zeroconf_scan(event_loop): zeroconf_stub.stub( pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2, MRP_SERVICE_1, AIRPLAY_SERVICE_1, ) atvs = await pyatv.scan(event_loop, timeout=0) assert len(atvs) == 3 # First device dev1 = _get_atv(atvs, IP_1) assert dev1 assert dev1.identifier == "AAAA" # Second device dev2 = _get_atv(atvs, IP_2) assert dev2 assert dev2.identifier == "BBBB" # Third device dev3 = _get_atv(atvs, IP_4) assert dev3 assert dev3.identifier == MRP_ID_1
async def test_scan(self): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2, MRP_SERVICE_1, AIRPLAY_SERVICE_1) atvs = await pyatv.scan(self.loop, timeout=0) self.assertEqual(len(atvs), 4) # First device dev1 = _get_atv(atvs, IP_1) self.assertIsNotNone(dev1) self.assertEqual(dev1.identifier, 'AAAA') # Second device dev2 = _get_atv(atvs, IP_2) self.assertIsNotNone(dev2) self.assertEqual(dev2.identifier, 'BBBB') # Third device dev3 = _get_atv(atvs, IP_4) self.assertIsNotNone(dev3) self.assertEqual(dev3.identifier, MRP_ID_1) # Fourth device dev4 = _get_atv(atvs, IP_6) self.assertIsNotNone(dev4) self.assertEqual(dev4.identifier, AIRPLAY_ID)
async def test_scan_for_particular_device(self): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2) atvs = await pyatv.scan(self.loop, timeout=0, identifier='BBBB') self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 2') self.assertEqual(atvs[0].address, ipaddress.ip_address(IP_2))
async def test_zeroconf_scan_for_particular_device(event_loop): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2) atvs = await pyatv.scan(event_loop, timeout=0, identifier="BBBB") assert len(atvs) == 1 assert atvs[0].name == "Apple TV 2" assert atvs[0].address == ipaddress.ip_address(IP_2)
async def test_zeroconf_scan_device_info(event_loop): zeroconf_stub.stub(pyatv, MRP_SERVICE_1, AIRPLAY_SERVICE_2) atvs = await pyatv.scan(event_loop, timeout=0, protocol=Protocol.MRP) assert len(atvs) == 1 device_info = atvs[0].device_info assert device_info.mac == AIRPLAY_ID
def test_scan_abort_on_first_found(self): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2) atvs = yield from pyatv.scan_for_apple_tvs(self.loop, timeout=0, abort_on_found=True) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 1')
def test_scan_home_sharing_overrules(self): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1, HOMESHARING_SERVICE_3) atvs = yield from pyatv.scan_for_apple_tvs(self.loop, timeout=0) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 3') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.3')) self.assertEqual(atvs[0].login_id, 'cccc') self.assertEqual(atvs[0].port, 3689)
async def test_zeroconf_scan_no_home_sharing(event_loop): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1) atvs = await pyatv.scan(event_loop, timeout=0) assert len(atvs) == 1 assert atvs[0].name == "Apple TV 3" assert atvs[0].address == ipaddress.ip_address(IP_3) atv = atvs[0] assert atv.get_service(Protocol.DMAP).port == 3689
async def test_scan_for_particular_device(self): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2) atvs = await pyatv.scan_for_apple_tvs(self.loop, timeout=0, only_usable=False, device_ip='10.0.0.2') self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 2') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.2'))
async def test_scan_no_home_sharing(self): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1) atvs = await pyatv.scan(self.loop, timeout=0) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 3') self.assertEqual(atvs[0].address, ipaddress.ip_address(IP_3)) atv = atvs[0] self.assertEqual(atv.get_service(Protocol.DMAP).port, 3689)
async def test_scan_home_sharing_merge(self): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1, HOMESHARING_SERVICE_3) atvs = await pyatv.scan(self.loop, timeout=0) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 3') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.3')) service = atvs[0].main_service() self.assertEqual(service.credentials, 'cccc') self.assertEqual(service.port, 3689)
def test_scan_all_devices(self): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1) atvs = yield from pyatv.scan_for_apple_tvs(self.loop, timeout=0, only_home_sharing=False) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 3') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.3')) self.assertEqual(atvs[0].login_id, None) self.assertEqual(atvs[0].port, 3689)
async def test_zeroconf_scan_home_sharing_merge(event_loop): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1, HOMESHARING_SERVICE_3) atvs = await pyatv.scan(event_loop, timeout=0) assert len(atvs) == 1 assert atvs[0].name == "Apple TV 3" assert atvs[0].address == ipaddress.ip_address("10.0.0.3") service = atvs[0].main_service() assert service.credentials == "cccc" assert service.port == 3689
async def test_scan_airplay_device(self): zeroconf_stub.stub(pyatv, AIRPLAY_SERVICE_1) atvs = await pyatv.scan(self.loop, timeout=0) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 6') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.6')) services = atvs[0].services self.assertEqual(len(services), 1) service = services[0] self.assertEqual(service.port, 7000)
async def test_scan_mrp(self): zeroconf_stub.stub(pyatv, MRP_SERVICE_1, MRP_SERVICE_2) atvs = await pyatv.scan_for_apple_tvs(self.loop, only_usable=False, timeout=0) self.assertEqual(len(atvs), 2) dev1 = AppleTV(ipaddress.ip_address('10.0.0.4'), 'Apple TV 4') self.assertIn(dev1, atvs) dev2 = AppleTV(ipaddress.ip_address('10.0.0.5'), 'Apple TV 5') self.assertIn(dev2, atvs)
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.port)) services.append(zeroconf_stub.airplay_service( 'Apple TV 2', IP_2, AIRPLAY_ID, port=airplay_port)) zeroconf_stub.stub(pyatv, *services) self.usecase.airplay_playback_playing() self.usecase.airplay_playback_idle()
async def test_scan_all_devices(self): zeroconf_stub.stub(pyatv, DEVICE_SERVICE_1) atvs = await pyatv.scan_for_apple_tvs(self.loop, timeout=0, only_usable=False) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 3') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.3')) services = atvs[0].services() self.assertEqual(len(services), 1) service = services[0] self.assertEqual(service.port, 3689)
def test_scan_for_apple_tvs(self): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2) atvs = yield from pyatv.scan_for_apple_tvs(self.loop, timeout=0) self.assertEqual(len(atvs), 2) # First device dev1 = AppleTVDevice('Apple TV 1', ipaddress.ip_address('10.0.0.1'), 'aaaa') self.assertIn(dev1, atvs) # Second device dev2 = AppleTVDevice('Apple TV 2', ipaddress.ip_address('10.0.0.2'), 'bbbb') self.assertIn(dev2, atvs)
def test_scan_airplay_device(self): zeroconf_stub.stub(pyatv, AIRPLAY_SERVICE_1) atvs = yield from pyatv.scan_for_apple_tvs(self.loop, timeout=0, only_usable=False) self.assertEqual(len(atvs), 1) self.assertEqual(atvs[0].name, 'Apple TV 6') self.assertEqual(atvs[0].address, ipaddress.ip_address('10.0.0.6')) services = atvs[0].services() self.assertEqual(len(services), 1) service = services[0] self.assertEqual(service.port, 7000)
async def test_zeroconf_scan_mrp(event_loop): zeroconf_stub.stub(pyatv, MRP_SERVICE_1, MRP_SERVICE_2, DEVICE_SERVICE_1) atvs = await pyatv.scan(event_loop, timeout=0, protocol=Protocol.MRP) assert len(atvs) == 2 dev1 = _get_atv(atvs, IP_4) assert dev1 assert dev1.name == "Apple TV 4" assert dev1.get_service(Protocol.MRP) dev2 = _get_atv(atvs, IP_5) assert dev2 assert dev2.name == "Apple TV 5" assert dev2.get_service(Protocol.MRP)
async def mock_pairing(event_loop): obj = MagicMock() service = conf.DmapService(None, None) config = conf.AppleTV("Apple TV", "127.0.0.1") config.add_service(service) zeroconf = zeroconf_stub.stub(pairing) async def _start(pin_code=PIN_CODE, pairing_guid=PAIRING_GUID, name=REMOTE_NAME): options = {"zeroconf": zeroconf} if pairing_guid: options["pairing_guid"] = pairing_guid if name: options["name"] = name obj.pairing = pairing.DmapPairingHandler(config, await http.create_session(), event_loop, **options) await obj.pairing.begin() obj.pairing.pin(pin_code) return obj.pairing, zeroconf, service yield _start await obj.pairing.finish() await obj.pairing.close()
async def test_scan_mrp(self): zeroconf_stub.stub(pyatv, MRP_SERVICE_1, MRP_SERVICE_2, DEVICE_SERVICE_1) atvs = await pyatv.scan(self.loop, timeout=0, protocol=Protocol.MRP) self.assertEqual(len(atvs), 2) dev1 = _get_atv(atvs, IP_4) self.assertIsNotNone(dev1) self.assertEqual(dev1.name, 'Apple TV 4') self.assertIsNotNone(dev1.get_service(Protocol.MRP)) dev2 = _get_atv(atvs, IP_5) self.assertIsNotNone(dev2) self.assertEqual(dev2.name, 'Apple TV 5') self.assertIsNotNone(dev2.get_service(Protocol.MRP))
def setUp(self): self.zeroconf = zeroconf_stub.stub(pairing) self.pairing = pairing.PairingHandler( self.loop, REMOTE_NAME, PIN_CODE, pairing_guid=pairing.DEFAULT_PAIRING_GUID)
async def setUp(self): self.zeroconf = zeroconf_stub.stub(pairing) self.pairing = pairing.DmapPairingHandler(self.loop) # TODO: currently stubs internal method, should provide stub # for netifaces later pairing._get_private_ip_addresses = \ lambda: [ipaddress.ip_address('10.0.0.1')]
async def test_scan_for_apple_tvs(self): zeroconf_stub.stub(pyatv, HOMESHARING_SERVICE_1, HOMESHARING_SERVICE_2, MRP_SERVICE_1, AIRPLAY_SERVICE_1) atvs = await pyatv.scan_for_apple_tvs(self.loop, timeout=0) self.assertEqual(len(atvs), 3) # First device dev1 = AppleTV(ipaddress.ip_address('10.0.0.1'), 'Apple TV 1') self.assertIn(dev1, atvs) # Second device dev2 = AppleTV(ipaddress.ip_address('10.0.0.2'), 'Apple TV 2') self.assertIn(dev2, atvs) # Third device dev3 = AppleTV(ipaddress.ip_address('10.0.0.4'), 'Apple TV 4') self.assertIn(dev3, atvs)
async def setUp(self): self.service = conf.DmapService(None, None) self.config = conf.AppleTV('Apple TV', '127.0.0.1') self.config.add_service(self.service) self.zeroconf = zeroconf_stub.stub(pairing) self.pairing = None # TODO: currently stubs internal method, should provide stub # for netifaces later pairing._get_private_ip_addresses = \ lambda: [ipaddress.ip_address('10.0.0.1')]
def setUp(self): AioHTTPTestCase.setUp(self) self.pairing = None self.service = DmapService("dmap_id", PAIRING_GUID, port=self.server.port) self.conf = AppleTV("127.0.0.1", "Apple TV") self.conf.add_service(self.service) self.zeroconf = zeroconf_stub.stub(pyatv.dmap.pairing)
def test_pairing_with_device(self): zeroconf = zeroconf_stub.stub(pairing) self.usecase.pairing_response(REMOTE_NAME, PAIRINGCODE) handler = pyatv.pair_with_apple_tv( self.loop, PIN_CODE, REMOTE_NAME, pairing_guid=pairing.DEFAULT_PAIRING_GUID) yield from handler.start(zeroconf) yield from self.usecase.act_on_bonjour_services(zeroconf) yield from handler.stop() self.assertTrue(handler.has_paired, msg='did not pair with device')
def setUp(self): self.zeroconf = zeroconf_stub.stub(pairing) self.pairing = pairing.PairingHandler( self.loop, REMOTE_NAME, PIN_CODE, pairing_guid=pairing.DEFAULT_PAIRING_GUID) # TODO: currently stubs internal method, should provide stub # for netifaces later pairing._get_private_ip_addresses = \ lambda: [ipaddress.ip_address('10.0.0.1')]