def test_merging_devices_keeps_hue_username(): now = datetime.utcnow() known_devices = [{ "id": "1", "type": "philips_hue", 'discovered': str(now), 'extra': { 'username': '******', }, }, { "id": "2", "type": "philips_hue", 'discovered': str(now), 'extra': { 'username': '******', }, }] discovered_devices = [{ "id": "1", "type": "philips_hue", }, { "id": "2", "type": "philips_hue", 'extra': {}, }] expected = known_devices assert merge_devices(known_devices, discovered_devices, now) == expected
def test_discover_devices_device_that_wasnt_discovered_again_is_not_removed_from_the_devices_list(): now = datetime.utcnow() known_devices = [{ "id": "1", "name": "first", 'discovered': str(now), }, { "id": "2", "name": "second", 'discovered': str(now), }] discovered_devices = [{ "id": "1", "name": "first", }] expected = known_devices assert merge_devices(known_devices, discovered_devices, now) == expected
def test_discover_devices_for_the_first_time_return_all_devices(): known_devices = [] discovered_devices = [{ "id": "1", "name": "first", }, { "id": "2", "name": "second", }] now = datetime.utcnow() expected = [{ "id": "1", "name": "first", 'discovered': str(now), }, { "id": "2", "name": "second", 'discovered': str(now), }] assert merge_devices(known_devices, discovered_devices, now) == expected
def test_discover_devices_update_device_with_updated_fields(): now = datetime.utcnow() known_devices = [{ "id": "1", "name": "first", 'discovered': str(now - timedelta(minutes=2)), }] discovered_devices = [{ "id": "1", "name": "first updated", }, { "id": "2", "name": "second", }] expected = [{ "id": "1", "name": "first updated", 'discovered': str(now), }, { "id": "2", "name": "second", 'discovered': str(now), }] assert merge_devices(known_devices, discovered_devices, now) == expected