def test_service_merge_properties(props1, props2, expected): service1 = ManualService("id1", Protocol.DMAP, 0, props1) service2 = ManualService("id2", Protocol.DMAP, 0, props2) service1.merge(service2) assert not DeepDiff(service1.properties, expected)
def test_service_merge_credentials(creds1, creds2, expected): service1 = ManualService("id1", Protocol.DMAP, 0, {}) service2 = ManualService("id2", Protocol.DMAP, 0, {}) service1.credentials = creds1 service2.credentials = creds2 service1.merge(service2) assert service1.credentials == expected
def test_service_merge_password(password1, password2, expected): service1 = ManualService("id1", Protocol.DMAP, 0, {}) service2 = ManualService("id2", Protocol.DMAP, 0, {}) service1.password = password1 service2.password = password2 service1.merge(service2) assert service1.password == expected
async def setUpAsync(self): await super().setUpAsync() self.service = ManualService( None, Protocol.Companion, self.fake_atv.get_port(Protocol.Companion), {} ) self.conf = AppleTV(IPv4Address("127.0.0.1"), "Test device") self.conf.add_service( ManualService( "mrp_id", Protocol.MRP, self.fake_atv.get_port(Protocol.MRP), {} ) ) self.conf.add_service(self.service)
def test_to_str(config): config.add_service( ManualService(IDENTIFIER_1, Protocol.DMAP, 3689, {}, "LOGIN_ID")) config.add_service(ManualService(IDENTIFIER_2, Protocol.MRP, PORT_2, {})) # Check for some keywords to not lock up format too much output = str(config) assert ADDRESS_1 in output assert NAME in output assert "LOGIN_ID" in output assert str(PORT_2) in output assert "3689" in output assert "Deep Sleep: True" in output
def companion_conf_fixture(companion_device): airplay = ManualService("airplayid", Protocol.AirPlay, 0, {}) service = ManualService( None, Protocol.Companion, companion_device.get_port(Protocol.Companion), {}, credentials=CLIENT_CREDENTIALS, ) conf = AppleTV("127.0.0.1", "Apple TV") conf.add_service(service) conf.add_service(airplay) yield conf
async def setUpAsync(self): await super().setUpAsync() self.conf = AppleTV(IPv4Address("127.0.0.1"), "Test device") self.conf.add_service( ManualService("mrp_id", Protocol.MRP, self.fake_atv.get_port(Protocol.MRP), {})) airplay_service = ManualService( "airplay_id", Protocol.AirPlay, self.server.port, properties={"features": "0x1"}, # AirPlayVideoV1 supported ) airplay_service.credentials = DEVICE_CREDENTIALS self.conf.add_service(airplay_service) self.atv = await self.get_connected_device()
async def mock_pairing(event_loop): obj = MagicMock() service = ManualService(None, Protocol.DMAP, 0, {}) config = 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, addresses=None): options = {"zeroconf": zeroconf} if pairing_guid: options["pairing_guid"] = pairing_guid if name: options["name"] = name if addresses: options["addresses"] = addresses obj.pairing = pairing.DmapPairingHandler(config, service, 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()
def setUp(self): AioHTTPTestCase.setUp(self) self.service = ManualService(CLIENT_IDENTIFIER, Protocol.MRP, self.fake_atv.get_port(Protocol.MRP), {}) self.conf = AppleTV("127.0.0.1", "Apple TV") self.conf.add_service(self.service)
def _manual_device(args): config = AppleTV(IPv4Address(args.address), args.name) service = ManualService(args.id, args.protocol, args.port, {}) service.credentials = getattr(args, f"{args.protocol.name.lower()}_credentials") service.password = args.raop_password config.add_service(service) return config
def raop_conf_fixture(raop_device, raop_properties): service = ManualService("raop_id", Protocol.RAOP, raop_device.get_port(Protocol.RAOP), raop_properties) conf = AppleTV("127.0.0.1", "Apple TV") conf.add_service(service) yield conf
async def mrp_protocol(event_loop, mrp_atv): port = mrp_atv.get_port(Protocol.MRP) service = ManualService("mrp_id", Protocol.MRP, port, {}) connection = MrpConnection("127.0.0.1", port, event_loop) protocol = MrpProtocol(connection, SRPAuthHandler(), service) yield protocol protocol.stop()
def test_raop_password_in_str(config): config.add_service( ManualService(IDENTIFIER_1, Protocol.RAOP, 1234, {}, password=PASSWORD_1)) assert PASSWORD_1 in str(config)
async def test_connect_only_companion(event_loop): service = ManualService(None, Protocol.Companion, 0, {}) # connect never happens conf = AppleTV("127.0.0.1", "Apple TV") conf.add_service(service) with pytest.raises(exceptions.DeviceIdMissingError): await pyatv.connect(conf, loop=event_loop)
async def get_connected_device(self, hsgid): self.dmap_service = ManualService("dmapid", Protocol.DMAP, self.server.port, {}) self.dmap_service.credentials = hsgid self.airplay_service = ManualService( "airplay_id", Protocol.AirPlay, self.server.port, properties={"features": "0x1"}, # AirPlayVideoV1 supported ) self.airplay_service.credentials = DEVICE_CREDENTIALS self.conf = AppleTV( ipaddress.IPv4Address("127.0.0.1"), "Apple TV", properties={"_appletv-v2._tcp.local": {}}, ) self.conf.add_service(self.dmap_service) self.conf.add_service(self.airplay_service) return await connect(self.conf, self.loop)
async def test_conf_is_a_copy(self): protocol = self.conf.main_service().protocol # Update credentials in the config passed to connect self.conf.get_service(protocol).merge( ManualService("test", protocol, 0, {}, credentials="1234")) # This should not result in a change to the service within the connected object # TODO: This test should not be part of a protocol test, rather a generic test # in core. Move this once core and protocols have been separated further. service = self.atv.service assert service.protocol == protocol assert service.credentials != "1234"
ADDRESS_2 = "192.168.0.1" NAME = "Alice" PORT_1 = 1234 PORT_2 = 5678 PORT_3 = 1111 PORT_4 = 5555 IDENTIFIER_1 = "id1" IDENTIFIER_2 = "id2" IDENTIFIER_3 = "id3" IDENTIFIER_4 = "id4" CREDENTIALS_1 = "cred1" PASSWORD_1 = "password1" TEST_PROPERTIES = {"_test._tcp.local": {"foo": "bar"}} DMAP_SERVICE = ManualService(IDENTIFIER_1, Protocol.DMAP, PORT_1, {}) MRP_SERVICE = ManualService(IDENTIFIER_2, Protocol.MRP, PORT_2, TEST_PROPERTIES) AIRPLAY_SERVICE = ManualService(IDENTIFIER_3, Protocol.AirPlay, PORT_1, {}) COMPANION_SERVICE = ManualService(None, Protocol.Companion, PORT_3, {}) RAOP_SERVICE = ManualService(IDENTIFIER_4, Protocol.RAOP, PORT_4, {}) AIRPORT_SERVICE = ManualService(IDENTIFIER_1, Protocol.RAOP, PORT_1, {}) @pytest.fixture def config(): yield AppleTV(ADDRESS_1, NAME, deep_sleep=True) def test_address_and_name(config): assert config.address == ADDRESS_1
def test_str_service_disabled(config): config.add_service( ManualService(IDENTIFIER_2, Protocol.MRP, PORT_2, {}, enabled=False)) assert "(Disabled)" in str(config)
def test_equality(config): assert config == config atv2 = AppleTV(ADDRESS_1, NAME) atv2.add_service(ManualService(IDENTIFIER_1, Protocol.AirPlay, PORT_1, {})) assert config != atv2
def test_identifier_missing_for_service(config): config.add_service(DMAP_SERVICE) config.add_service(ManualService(None, Protocol.MRP, 0, {})) assert config.identifier == DMAP_SERVICE.identifier
async def test_connect_missing_device_id(self): conf = AppleTV("1.2.3.4", "Apple TV") conf.add_service(ManualService(None, Protocol.Companion, 1234, {})) with self.assertRaises(exceptions.DeviceIdMissingError): await pyatv.connect(conf, self.loop)
def test_feature_play_url(flags, expected_state): service = ManualService("id", Protocol.AirPlay, 0, {"features": flags}) features = AirPlayFeatures(service) assert features.get_feature(FeatureName.PlayUrl).state == expected_state
def airplay_conf_fixture(airplay_device): service = ManualService("airplay_id", Protocol.AirPlay, airplay_device.get_port(Protocol.AirPlay), {}) conf = AppleTV("127.0.0.1", "Apple TV") conf.add_service(service) yield conf