def test_discover_devices_update_device_with_updated_fields(): now = datetime.utcnow() devices = [{ "id": "1", "name": "first", DISCOVERY_TIMESTAMP_FIELD: str(now - timedelta(minutes=2)), }] discovered_devices = [{ "id": "1", "name": "first updated", }, { "id": "2", "name": "second", }] expected = [{ "id": "1", "name": "first updated", DISCOVERY_TIMESTAMP_FIELD: str(now), }, { "id": "2", "name": "second", DISCOVERY_TIMESTAMP_FIELD: str(now), }] with patch("senic_hub.backend.device_discovery.discover") as discover_mock: discover_mock.return_value = discovered_devices assert discover_devices(devices, now) == expected
def test_discover_philips_hue_device(philips_hue_bridge_description): responses.add(responses.GET, 'http://127.0.0.1:80/description.xml', body=philips_hue_bridge_description, status=200) expected = { "id": "ph1", "name": "Philips Hue bridge", "authenticationRequired": True, "type": "philips_hue", "ip": "127.0.0.1", "extra": {}, } assert discover_devices(MockPhilipsDiscovery) == [expected]
def test_discover_devices_device_that_wasnt_discovered_again_is_not_removed_from_the_devices_list( ): now = datetime.utcnow() devices = [{ "id": "1", "name": "first", DISCOVERY_TIMESTAMP_FIELD: str(now), }, { "id": "2", "name": "second", DISCOVERY_TIMESTAMP_FIELD: str(now), }] discovered_devices = [{ "id": "1", "name": "first", }] expected = devices with patch("senic_hub.backend.device_discovery.discover") as discover_mock: discover_mock.return_value = discovered_devices assert discover_devices(devices, now) == expected
def test_discover_devices_for_the_first_time_return_all_devices(): devices = [] discovered_devices = [{ "id": "1", "name": "first", }, { "id": "2", "name": "second", }] now = datetime.utcnow() expected = [{ "id": "1", "name": "first", DISCOVERY_TIMESTAMP_FIELD: str(now), }, { "id": "2", "name": "second", DISCOVERY_TIMESTAMP_FIELD: str(now), }] with patch("senic_hub.backend.device_discovery.discover") as discover_mock: discover_mock.return_value = discovered_devices assert discover_devices(devices, now) == expected