Exemplo n.º 1
0
 def get_service(self, name):
     """Return new service object."""
     service_dict = self.serv_types[name].copy()
     if 'RequiredCharacteristics' not in service_dict or \
             'UUID' not in service_dict:
         raise KeyError('Could not load service {}!'.format(name))
     return Service.from_dict(name, service_dict, self)
Exemplo n.º 2
0
def test_from_dict():
    """Test creating a service from a dictionary."""
    uuid = uuid1()
    chars = get_chars()
    mock_char_loader = Mock()
    mock_char_loader.get_char.side_effect = chars

    json_dict = {
        'UUID': str(uuid),
        'RequiredCharacteristics': {
            'Char 1',
            'Char 2',
        }
    }

    service = Service.from_dict('Test Service', json_dict, mock_char_loader)
    assert service.display_name == 'Test Service'
    assert service.type_id == uuid
    assert service.characteristics == chars

    mock_char_loader.get_char.assert_has_calls(
        [call('Char 1'), call('Char 2')], any_order=True)
Exemplo n.º 3
0
def test_from_dict():
    """Test creating a service from a dictionary."""
    uuid = uuid1()
    chars = get_chars()
    mock_char_loader = Mock()
    mock_char_loader.get_char.side_effect = chars

    json_dict = {
        "UUID": str(uuid),
        "RequiredCharacteristics": {
            "Char 1",
            "Char 2",
        },
    }

    service = Service.from_dict("Test Service", json_dict, mock_char_loader)
    assert service.display_name == "Test Service"
    assert service.type_id == uuid
    assert service.characteristics == chars

    mock_char_loader.get_char.assert_has_calls(
        [call("Char 1"), call("Char 2")], any_order=True
    )