Exemple #1
0
def test_lookup_container(backend, container, items):
    with mock.patch.object(backend, "client") as m:
        m.properties.return_value = Future.fromvalue(container)
        m.search.return_value = Future.fromvalue([items, False])
        assert backend.library.lookup(container["URI"]) == [
            models.Track(name="Track #1", uri="dleyna://media/11"),
            models.Track(name="Track #2", uri="dleyna://media/12"),
        ]
def test_lookup_container(backend, container, items):
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(container)
        m.search.return_value = Future.fromvalue(items)
        assert backend.library.lookup(container['URI']) == [
            models.Track(name='Track #1', uri='dleyna://media/11'),
            models.Track(name='Track #2', uri='dleyna://media/12')
        ]
def test_lookup_container(backend, container, items):
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(container)
        m.search.return_value = Future.fromvalue([items, False])
        assert backend.library.lookup(container['URI']) == [
            models.Track(name='Track #1', uri='dleyna://media/11'),
            models.Track(name='Track #2', uri='dleyna://media/12')
        ]
Exemple #4
0
def test_images(backend, server, items):
    with mock.patch.object(backend, "client") as m:
        m.servers.return_value = Future.fromvalue([server])
        m.server.return_value = Future.fromvalue(server)
        m.search.return_value = Future.fromvalue([items, False])
        assert backend.library.get_images(item["URI"] for item in items) == {
            items[0]["URI"]: (models.Image(uri=items[0]["AlbumArtURL"]), ),
            items[1]["URI"]: tuple(),
        }
def test_images(backend, server, items):
    with mock.patch.object(backend, 'client') as m:
        m.servers.return_value = Future.fromvalue([server])
        m.server.return_value = Future.fromvalue(server)
        m.search.return_value = Future.fromvalue(items)
        assert backend.library.get_images(item['URI'] for item in items) == {
            items[0]['URI']: (models.Image(uri=items[0]['AlbumArtURL']),),
            items[1]['URI']: tuple()
        }
def test_browse_items(backend, container, items):
    # FIXME: how to patch multiple object methods...
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(container)
        m.browse.return_value = Future.fromvalue(items)
        assert backend.library.browse(container['URI']) == [
            Ref.track(name='Track #1', uri='dleyna://media/1'),
            Ref.track(name='Track #2', uri='dleyna://media/2')
        ]
Exemple #7
0
def test_browse_items(backend, container, items):
    # FIXME: how to patch multiple object methods...
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(container)
        m.browse.side_effect = [
            Future.fromvalue([items[0:2], True]),
            Future.fromvalue([items[2:3], True]),
            Future.fromvalue([[], False])
        ]
        assert backend.library.browse(container['URI']) == [
            Ref.track(name='Track #1', uri='dleyna://media/1'),
            Ref.track(name='Track #2', uri='dleyna://media/2'),
            Ref.track(name='Track #3', uri='dleyna://media/3'),
        ]
Exemple #8
0
def test_browse_items(backend, container, items):
    # FIXME: how to patch multiple object methods...
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(container)
        m.browse.side_effect = [
            Future.fromvalue([items[0:2], True]),
            Future.fromvalue([items[2:3], True]),
            Future.fromvalue([[], False])
        ]
        assert backend.library.browse(container['URI']) == [
            Ref.track(name='Track #1', uri='dleyna://media/1'),
            Ref.track(name='Track #2', uri='dleyna://media/2'),
            Ref.track(name='Track #3', uri='dleyna://media/3'),
        ]
Exemple #9
0
def test_browse_items(backend, container, items):
    # FIXME: how to patch multiple object methods...
    with mock.patch.object(backend, "client") as m:
        m.properties.return_value = Future.fromvalue(container)
        m.browse.side_effect = [
            Future.fromvalue([items[0:2], True]),
            Future.fromvalue([items[2:3], True]),
            Future.fromvalue([[], False]),
        ]
        assert backend.library.browse(container["URI"]) == [
            Ref.track(name="Track #1", uri="dleyna://media/1"),
            Ref.track(name="Track #2", uri="dleyna://media/2"),
            Ref.track(name="Track #3", uri="dleyna://media/3"),
        ]
Exemple #10
0
def test_browse_root(backend, servers):
    with mock.patch.object(backend, "client") as m:
        m.servers.return_value = Future.fromvalue(servers)
        assert backend.library.browse(backend.library.root_directory.uri) == [
            Ref.directory(name="Media Server #1", uri="dleyna://media1"),
            Ref.directory(name="Media Server #2", uri="dleyna://media2"),
        ]
def test_browse_root(backend, servers):
    with mock.patch.object(backend, 'client') as m:
        m.servers.return_value = Future.fromvalue(servers)
        assert backend.library.browse(backend.library.root_directory.uri) == [
            Ref.directory(name='Media Server #1', uri='dleyna://media1'),
            Ref.directory(name='Media Server #2', uri='dleyna://media2'),
        ]
Exemple #12
0
def test_browse_root(backend, servers):
    with mock.patch.object(backend, 'client') as m:
        m.servers.return_value = Future.fromvalue(servers)
        assert backend.library.browse(backend.library.root_directory.uri) == [
            Ref.directory(name='Media Server #1', uri='dleyna://media1'),
            Ref.directory(name='Media Server #2', uri='dleyna://media2'),
        ]
Exemple #13
0
def test_search(backend, server, result):
    with mock.patch.object(backend, 'client') as m:
        m.servers.return_value = Future.fromvalue([server])
        m.server.return_value = Future.fromvalue(server)
        m.search.side_effect = [
            Future.fromvalue([result[0:2], True]),
            Future.fromvalue([result[2:3], False])
        ]
        # valid search
        assert backend.library.search({'any': ['foo']}) == models.SearchResult(
            albums=[
                models.Album(name='Album #1', uri='dleyna://media/1')
            ],
            tracks=[
                models.Track(name='Track #1', uri='dleyna://media/11'),
                models.Track(name='Track #2', uri='dleyna://media/12')
            ]
        )
        # unsupported search field yields no result
        assert backend.library.search({'composer': ['foo']}) is None
        # search field not supported by device yields no result
        assert backend.library.search({'genre': ['foo']}) is None
def test_translate_uri(backend, item):
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(item)
        assert backend.playback.translate_uri(item['URI']) == item['URLs'][0]
def test_translate_unknown_uri(backend):
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.exception(LookupError('Not Found'))
        assert backend.playback.translate_uri('') is None
Exemple #16
0
def test_lookup_item(backend, items):
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(items[0])
        assert backend.library.lookup(items[0]['URI']) == [
            models.Track(name='Track #1', uri='dleyna://media/11')
        ]
def test_translate_uri(backend, item):
    with mock.patch.object(backend, "client") as m:
        m.properties.return_value = Future.fromvalue(item)
        assert backend.playback.translate_uri(item["URI"]) == item["URLs"][0]
def test_translate_unknown_uri(backend):
    with mock.patch.object(backend, "client") as m:
        m.properties.return_value = Future.exception(LookupError("Not Found"))
        assert backend.playback.translate_uri("") is None
def test_lookup_item(backend, items):
    with mock.patch.object(backend, 'client') as m:
        m.properties.return_value = Future.fromvalue(items[0])
        assert backend.library.lookup(items[0]['URI']) == [
            models.Track(name='Track #1', uri='dleyna://media/11')
        ]
Exemple #20
0
def test_lookup_item(backend, items):
    with mock.patch.object(backend, "client") as m:
        m.properties.return_value = Future.fromvalue(items[0])
        assert backend.library.lookup(items[0]["URI"]) == [
            models.Track(name="Track #1", uri="dleyna://media/11")
        ]