예제 #1
0
def test_linked_service_to_HAP():
    """Test created HAP representation of a service."""
    uuid = uuid1()
    pyhap_char_to_HAP = "pyhap.characteristic.Characteristic.to_HAP"

    service = Service(uuid, "Test Service")
    linked_service = Service(uuid1(), "Test Linked Service")
    service.add_linked_service(linked_service)
    service.characteristics = get_chars()
    with patch(pyhap_char_to_HAP) as mock_char_HAP, patch.object(
        service, "broker"
    ) as mock_broker, patch.object(linked_service, "broker") as mock_linked_broker:
        mock_iid = mock_broker.iid_manager.get_iid
        mock_iid.return_value = 2
        mock_linked_iid = mock_linked_broker.iid_manager.get_iid
        mock_linked_iid.return_value = 3
        mock_char_HAP.side_effect = ("Char 1", "Char 2")
        hap_repr = service.to_HAP()
        mock_iid.assert_called_with(service)

    assert hap_repr == {
        "iid": 2,
        "type": str(uuid).upper(),
        "characteristics": ["Char 1", "Char 2"],
        "linked": [mock_linked_iid()],
    }
예제 #2
0
def test_linked_service_to_HAP():
    """Test created HAP representation of a service."""
    uuid = uuid1()
    pyhap_char_to_HAP = 'pyhap.characteristic.Characteristic.to_HAP'

    service = Service(uuid, 'Test Service')
    linked_service = Service(uuid1(), 'Test Linked Service')
    service.add_linked_service(linked_service)
    service.characteristics = get_chars()
    with patch(pyhap_char_to_HAP) as mock_char_HAP, \
            patch.object(service, 'broker') as mock_broker, \
            patch.object(linked_service, 'broker') as mock_linked_broker:
        mock_iid = mock_broker.iid_manager.get_iid
        mock_iid.return_value = 2
        mock_linked_iid = mock_linked_broker.iid_manager.get_iid
        mock_linked_iid.return_value = 3
        mock_char_HAP.side_effect = ('Char 1', 'Char 2')
        hap_repr = service.to_HAP()
        mock_iid.assert_called_with(service)

    assert hap_repr == {
        'iid': 2,
        'type': str(uuid).upper(),
        'characteristics': ['Char 1', 'Char 2'],
        'linked': [mock_linked_iid()],
    }
예제 #3
0
def test_add_linked_service():
    """Test adding linked service to a service."""
    service = Service(uuid1(), "Test Service")
    assert len(service.linked_services) == 0

    linked_service = Service(uuid1(), "Test Linked Service")
    service.add_linked_service(linked_service)

    assert len(service.linked_services) == 1
    assert service.linked_services[0] == linked_service