Exemplo n.º 1
0
def test_cache():
    http_cache = {}

    # Mock response
    body = read('fixtures/detail_a.xml', mode='r')

    responses.add_callback(
        responses.GET, 'http://mock:32400/',
        callback=lambda request: (200, {}, body),
        content_type='application/xml'
    )

    with Plex.configuration.cache(http=http_cache):
        # Check initial version retrieval
        assert Plex.version() == "0.9.9.16.555-50cd0c3"

        # Change body, ensure cached version is returned
        body = read('fixtures/detail_b.xml', mode='r')

        assert Plex.version() == "0.9.9.16.555-50cd0c3"

        # Clear cache, ensure version has changed
        http_cache.clear()

        assert Plex.version() == "0.9.9.14.531-7eef8c6"
Exemplo n.º 2
0
def lookup_callback(request):
    url = urlparse(request.url)

    try:
        return 200, {}, read('fixtures%s.json' % url.path)
    except:
        return 200, {}, '[]'
Exemplo n.º 3
0
def query_callback(request):
    url = urlparse(request.url)
    query = dict(parse_qsl(url.query))

    if not query.get('query'):
        return 400, {}, '[]'

    # Build path
    if query.get('year'):
        path = 'fixtures%s/%s/%s.json' % (
            url.path,
            query['year'],
            query['query']
        )
    else:
        path = 'fixtures%s/%s.json' % (
            url.path,
            query['query']
        )

    # Return response
    try:
        return 200, {}, read(path)
    except:
        return 200, {}, '[]'
Exemplo n.º 4
0
def test_episode():
    responses.add(
        responses.GET, 'http://mock:32400/library/metadata/31',
        body=read('fixtures/library/metadata/episode.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library'].metadata(31)
    assert container is not None

    items = list(container)
    assert len(items) == 1

    episode = items[0]

    # - index
    assert episode.index == 1
    assert episode.season.index == 6

    # - title
    assert episode.title == "London (1)"
    assert episode.show.title == "Parks and Recreation"

    # - writer
    assert "Michael Schur" in [wr.tag for wr in episode.writers]

    # - director
    assert episode.director.tag == "Dean Holland"

    # - guid
    assert episode.guid == "com.plexapp.agents.thetvdb://84912/6/1?lang=en"
Exemplo n.º 5
0
def test_metadata():
    responses.add(
        responses.GET, 'http://mock:32400/library/metadata/31',
        body=read('fixtures/library/metadata/episode.xml'), status=200,
        content_type='application/xml'
    )

    # Retrieve mock [Episode] object
    container = Plex['library'].metadata(31)
    assert container is not None

    items = list(container)
    assert len(items) == 1

    # Encode item
    encoded = Serializer.encode(items[0])
    assert encoded

    # Decode item
    decoded = Serializer.decode(encoded, Plex.client)
    assert decoded

    # Basic property check
    assert decoded.title == items[0].title
    assert decoded.guid == items[0].guid
Exemplo n.º 6
0
def test_metadata():
    responses.add(responses.GET,
                  'http://mock:32400/library/metadata/31',
                  body=read('fixtures/library/metadata/episode.xml'),
                  status=200,
                  content_type='application/xml')

    # Retrieve mock [Episode] object
    container = Plex['library'].metadata(31)
    assert container is not None

    items = list(container)
    assert len(items) == 1

    # Encode item
    encoded = Serializer.encode(items[0])
    assert encoded

    # Decode item
    decoded = Serializer.decode(encoded, Plex.client)
    assert decoded

    # Basic property check
    assert decoded.title == items[0].title
    assert decoded.guid == items[0].guid
Exemplo n.º 7
0
def test_likes():
    responses.add(
        responses.GET, 'http://mock/users/likes',
        body=read('fixtures/users/likes.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    likes = Trakt['users'].likes()
    assert likes is not None

    likes = list(likes)
    assert len(likes) is 3

    assert likes[0].keys == [
        ('trakt', 1519)
    ]

    assert likes[1].keys == [
        ('trakt', '1238362'),
        ('slug', 'star-wars-machete')
    ]

    assert likes[2].keys == [
        ('trakt', '840781'),
        ('slug', 'star-wars-timeline')
    ]
Exemplo n.º 8
0
def test_seasons():
    responses.add(
        responses.GET, 'http://mock/shows/tt0944947/seasons',
        body=read('fixtures/shows/tt0944947/seasons.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    seasons = Trakt['shows'].seasons('tt0944947')

    assert len(seasons) == 6

    assert seasons[0].pk == 0
    assert seasons[0].keys == [
        0,
        ('tvdb', '137481'),
        ('tmdb', '3627'),
        ('trakt', '3962')
    ]

    assert seasons[5].pk == 5
    assert seasons[5].keys == [
        5,
        ('tmdb', '62090'),
        ('trakt', '3967')
    ]
Exemplo n.º 9
0
def test_season():
    responses.add(
        responses.GET, 'http://mock/shows/game-of-thrones/seasons/1',
        body=read('fixtures/shows/game-of-thrones/seasons/1.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    episodes = Trakt['shows'].season('game-of-thrones', 1)

    assert len(episodes) == 10

    assert episodes[0].title == 'Winter Is Coming'
    assert episodes[0].pk == (1, 1)
    assert episodes[0].keys == [
        (1, 1),
        ('tvdb', '3254641'),
        ('tmdb', '63056'),
        ('imdb', 'tt1480055'),
        ('tvrage', '1065008299'),
        ('trakt', '73640')
    ]

    assert episodes[9].title == 'Fire and Blood'
    assert episodes[9].pk == (1, 10)
    assert episodes[9].keys == [
        (1, 10),
        ('tvdb', '4063491'),
        ('tmdb', '63065'),
        ('imdb', 'tt1851397'),
        ('tvrage', '1065039307'),
        ('trakt', '73649')
    ]
Exemplo n.º 10
0
def test_movie():
    responses.add(
        responses.GET, 'http://mock/movies/trending',
        body=read('fixtures/movies/trending.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    movies = Trakt['movies'].trending()

    assert len(movies) == 10

    assert [(m.watchers, m.title, m.year) for m in movies] == [
        (24, "Cinderella", 2015),
        (15, "Pleasure or Pain", 2013),
        (14, "Get Hard", 2015),
        (12, "Mad Max: Fury Road", 2015),
        (11, "Maggie", 2015),
        (10, "The Gunman", 2015),
        (9, "Ex Machina", 2015),
        (8, "The SpongeBob Movie: Sponge Out of Water", 2015),
        (7, "Chappie", 2015),
        (6, "While We're Young", 2015)
    ]
Exemplo n.º 11
0
def test_show():
    responses.add(
        responses.GET, 'http://mock/shows/trending',
        body=read('fixtures/shows/trending.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    shows = Trakt['shows'].trending()

    assert len(shows) == 10

    assert [(m.watchers, m.title, m.year) for m in shows] == [
        (45, "Orange Is the New Black", 2013),
        (42, "Game of Thrones", 2011),
        (35, "True Detective", 2014),
        (21, "Pretty Little Liars", 2010),
        (21, "Sense8", 2015),
        (21, "The Last Ship", 2014),
        (17, "Arrow", 2012),
        (14, "The Big Bang Theory", 2007),
        (13, "Tyrant", 2014),
        (12, "Grey's Anatomy", 2005)
    ]
Exemplo n.º 12
0
    def callback(request):
        uri = urlparse(request.url)
        parameters = dict(parse_qsl(uri.query))

        if parameters.get('extended') != 'episodes':
            return 400, {}, None

        return 200, {}, read('fixtures/shows/tt0944947/seasons_extended.json')
Exemplo n.º 13
0
    def callback(request):
        uri = urlparse(request.url)
        parameters = dict(parse_qsl(uri.query))

        if parameters.get('extended') != 'episodes':
            return 400, {}, None

        return 200, {}, read('fixtures/shows/tt0944947/seasons_extended.json')
Exemplo n.º 14
0
def test_recently_added():
    responses.add(
        responses.GET, 'http://mock:32400/library/recentlyAdded',
        body=read('fixtures/library/recently_added.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library'].recently_added()
    assert container is not None

    items = list(container)
    assert len(items) == 3

    # Validate 'movie'
    assert items[0].type == 'movie'
    assert items[0].title == "TRON: Legacy"
    assert items[0].year == 2010

    assert items[0].director.tag == "Joseph Kosinski"
    assert items[0].country.tag == "USA"

    assert [genre.tag for genre in items[0].genres] == [
        "Action",
        "Adventure"
    ]

    assert [writer.tag for writer in items[0].writers] == [
        "Adam Horowitz",
        "Richard Jefferies"
    ]

    assert [role.tag for role in items[0].roles] == [
        "Garrett Hedlund",
        "Jeff Bridges",
        "Olivia Wilde"
    ]

    # Validate 'season'
    assert items[1].type == 'season'
    assert items[1].title == "Specials"
    assert items[1].index == 0

    assert items[1].show.title == "Gold Rush"
    assert items[1].show.index == 1

    # Validate 'album'
    assert items[2].type == 'album'
    assert items[2].title == "Angel Milk"
    assert items[2].index == 1

    assert items[2].artist.title == six.u('T\xe9l\xe9popmusik')

    assert [genre.tag for genre in items[2].genres] == [
        "Electronic",
        "Electronica"
    ]
Exemplo n.º 15
0
def test_version():
    responses.add(responses.GET,
                  'http://mock:32400',
                  body=read('fixtures/detail_a.xml'),
                  status=200,
                  content_type='application/xml')

    version = Plex.version()

    assert version == "0.9.9.16.555-50cd0c3"
Exemplo n.º 16
0
def test_version():
    responses.add(
        responses.GET, 'http://mock:32400',
        body=read('fixtures/detail_a.xml'), status=200,
        content_type='application/xml'
    )

    version = Plex.version()

    assert version == "0.9.9.16.555-50cd0c3"
Exemplo n.º 17
0
def test_booleans():
    responses.add(
        responses.GET, 'http://mock:32400',
        body=read('fixtures/detail_a.xml'), status=200,
        content_type='application/xml'
    )

    detail = Plex.detail()
    assert detail is not None

    assert detail.multiuser is True
    assert detail.sync is False
Exemplo n.º 18
0
def test_interface_proxy():
    responses.add(
        responses.GET, 'http://mock:32400/library/metadata/1/allLeaves',
        body=read('fixtures/library/all_leaves/show.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library/metadata/1'].all_leaves()
    assert container is not None

    items = list(container)
    assert len(items) == 6
Exemplo n.º 19
0
def test_interface_proxy():
    responses.add(responses.GET,
                  'http://mock:32400/library/metadata/1/allLeaves',
                  body=read('fixtures/library/all_leaves/show.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex['library/metadata/1'].all_leaves()
    assert container is not None

    items = list(container)
    assert len(items) == 6
Exemplo n.º 20
0
def test_get_single():
    responses.add(responses.GET,
                  'http://mock:32400/:/prefs',
                  body=read('fixtures/prefs.xml'),
                  status=200,
                  content_type='application/xml')

    item = Plex[':/prefs'].get('FriendlyName')
    assert item is not None

    # Validate preferences
    assert item.id == "FriendlyName"
    assert item.group == 'general'
Exemplo n.º 21
0
def test_get_single():
    responses.add(
        responses.GET, 'http://mock:32400/:/prefs',
        body=read('fixtures/prefs.xml'), status=200,
        content_type='application/xml'
    )

    item = Plex[':/prefs'].get('FriendlyName')
    assert item is not None

    # Validate preferences
    assert item.id == "FriendlyName"
    assert item.group == 'general'
Exemplo n.º 22
0
def test_detail():
    responses.add(responses.GET,
                  'http://mock:32400',
                  body=read('fixtures/detail_malformed.xml'),
                  status=200,
                  content_type='application/xml')

    detail = Plex.detail()

    if PARSER == 'etree.HTMLParser':
        assert detail is not None
        assert detail.platform_version == six.u('6.2 (Build 9200)\xff\xff')
    else:
        assert detail is None
Exemplo n.º 23
0
def test_show_progress_collection():
    responses.add(
        responses.GET, 'http://mock/shows/tt0944947/progress/collection',
        body=read('fixtures/shows/tt0944947/progress/collection.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    response = Trakt.http.get('/shows/tt0944947/progress/collection')
    data = response.json()

    assert data['aired'] == 10
    assert data['completed'] == 6
Exemplo n.º 24
0
def test_shows_updates():
    responses.add(responses.GET,
                  'http://mock/shows/updates',
                  body=read('fixtures/shows/updates.json'),
                  status=200,
                  content_type='application/json')

    Trakt.base_url = 'http://mock'

    response = Trakt.http.get('/shows/updates')
    data = response.json()

    assert data[0]['show']['title'] == 'Breaking Bad'
    assert data[1]['show']['title'] == 'The Walking Dead'
Exemplo n.º 25
0
def test_shows_updates():
    responses.add(
        responses.GET, 'http://mock/shows/updates',
        body=read('fixtures/shows/updates.json'), status=200,
        content_type='application/json'
    )

    Trakt.base_url = 'http://mock'

    response = Trakt.http.get('/shows/updates')
    data = response.json()

    assert data[0]['show']['title'] == 'Breaking Bad'
    assert data[1]['show']['title'] == 'The Walking Dead'
Exemplo n.º 26
0
def test_detail():
    responses.add(responses.GET,
                  'http://mock:32400',
                  body=read('fixtures/detail_a.xml'),
                  status=200,
                  content_type='application/xml')

    detail = Plex.detail()
    assert detail is not None

    assert detail.friendly_name == "Mock Server"

    assert detail.platform == "Windows"
    assert detail.platform_version == "6.2 (Build 9200)"
Exemplo n.º 27
0
def test_clients_filter():
    responses.add(
        responses.GET, 'http://mock:32400/clients',
        body=read('fixtures/clients.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex.clients()
    assert container is not None

    items = list(container.filter(["a7d1b50a-42d1-40b5-9db6-6b0afd013438"]))
    assert len(items) == 1

    assert items[0].machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438"
Exemplo n.º 28
0
def test_detail():
    responses.add(
        responses.GET, 'http://mock:32400',
        body=read('fixtures/detail_a.xml'), status=200,
        content_type='application/xml'
    )

    detail = Plex.detail()
    assert detail is not None

    assert detail.friendly_name == "Mock Server"

    assert detail.platform == "Windows"
    assert detail.platform_version == "6.2 (Build 9200)"
Exemplo n.º 29
0
def test_detail():
    responses.add(
        responses.GET, 'http://mock:32400',
        body=read('fixtures/detail_malformed.xml'), status=200,
        content_type='application/xml'
    )

    detail = Plex.detail()

    if PARSER == 'etree.HTMLParser':
        assert detail is not None
        assert detail.platform_version == six.u('6.2 (Build 9200)\xff\xff')
    else:
        assert detail is None
Exemplo n.º 30
0
def test_sessions_filter():
    responses.add(
        responses.GET, 'http://mock:32400/status/sessions',
        body=read('fixtures/status/sessions.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['status'].sessions()
    assert container is not None

    items = list(container.filter(keys=[3, 5]))
    assert len(items) == 2

    assert items[0].session.key == 3
    assert items[1].session.key == 5
Exemplo n.º 31
0
def test_show_progress_collection():
    responses.add(
        responses.GET,
        'http://mock/shows/tt0944947/progress/collection',
        body=read('fixtures/shows/tt0944947/progress/collection.json'),
        status=200,
        content_type='application/json')

    Trakt.base_url = 'http://mock'

    response = Trakt.http.get('/shows/tt0944947/progress/collection')
    data = response.json()

    assert data['aired'] == 10
    assert data['completed'] == 6
Exemplo n.º 32
0
def test_sessions_filter():
    responses.add(responses.GET,
                  'http://mock:32400/status/sessions',
                  body=read('fixtures/status/sessions.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex['status'].sessions()
    assert container is not None

    items = list(container.filter(keys=[3, 5]))
    assert len(items) == 2

    assert items[0].session.key == 3
    assert items[1].session.key == 5
Exemplo n.º 33
0
def test_clients_filter():
    responses.add(responses.GET,
                  'http://mock:32400/clients',
                  body=read('fixtures/clients.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex.clients()
    assert container is not None

    items = list(container.filter(["a7d1b50a-42d1-40b5-9db6-6b0afd013438"]))
    assert len(items) == 1

    assert items[
        0].machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438"
Exemplo n.º 34
0
def test_cache():
    http_cache = {}

    # Mock response
    body = read('fixtures/detail_a.xml', mode='r')

    responses.add_callback(responses.GET,
                           'http://mock:32400/',
                           callback=lambda request: (200, {}, body),
                           content_type='application/xml')

    with Plex.configuration.cache(http=http_cache):
        # Check initial version retrieval
        assert Plex.version() == "0.9.9.16.555-50cd0c3"

        # Change body, ensure cached version is returned
        body = read('fixtures/detail_b.xml', mode='r')

        assert Plex.version() == "0.9.9.16.555-50cd0c3"

        # Clear cache, ensure version has changed
        http_cache.clear()

        assert Plex.version() == "0.9.9.14.531-7eef8c6"
Exemplo n.º 35
0
    def on_request(request):
        url = urlparse(request.url)
        parameters = dict(parse_qsl(url.query))

        page = try_convert(parameters.get('page'), int) or 1
        limit = try_convert(parameters.get('limit'), int)

        if limit is not None and limit != 2:
            # Invalid limit provided
            return 400, {}, ''

        return 200, {
            'X-Pagination-Limit':       '2',
            'X-Pagination-Item-Count':  '6',
            'X-Pagination-Page-Count':  '3'
        }, read('fixtures/users/me/lists_p%d.json' % page)
Exemplo n.º 36
0
def test_sections_filter():
    responses.add(
        responses.GET, 'http://mock:32400/library/sections',
        body=read('fixtures/library/sections.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library'].sections()
    assert container is not None

    # Test 'types' filter
    items = list(container.filter(types=['show']))
    assert len(items) == 1

    assert items[0].type == 'show'
    assert items[0].agent == 'com.plexapp.agents.thetvdb'
Exemplo n.º 37
0
    def on_request(request):
        url = urlparse(request.url)
        parameters = dict(parse_qsl(url.query))

        page = try_convert(parameters.get('page'), int) or 1
        limit = try_convert(parameters.get('limit'), int)

        if limit is not None and limit != 2:
            # Invalid limit provided
            return 400, {}, ''

        return 200, {
            'X-Pagination-Limit': '2',
            'X-Pagination-Item-Count': '6',
            'X-Pagination-Page-Count': '3'
        }, read('fixtures/users/me/lists_p%d.json' % page)
Exemplo n.º 38
0
def test_episode_proxy():
    responses.add(
        responses.GET,
        'http://mock/shows/game-of-thrones/seasons/1/episodes/1',
        body=read('fixtures/shows/game-of-thrones/seasons/1/episodes/1.json'),
        status=200,
        content_type='application/json')

    Trakt.base_url = 'http://mock'

    episode = Trakt['shows/game-of-thrones'].episode(1, 1)

    assert episode.title == 'Winter Is Coming'
    assert episode.pk == (1, 1)
    assert episode.keys == [(1, 1), ('tvdb', '3254641'), ('tmdb', '63056'),
                            ('imdb', 'tt1480055'), ('tvrage', '1065008299'),
                            ('trakt', '73640')]
Exemplo n.º 39
0
def test_recently_added():
    responses.add(responses.GET,
                  'http://mock:32400/library/recentlyAdded',
                  body=read('fixtures/library/recently_added.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex['library'].recently_added()
    assert container is not None

    items = list(container)
    assert len(items) == 3

    # Validate 'movie'
    assert items[0].type == 'movie'
    assert items[0].title == "TRON: Legacy"
    assert items[0].year == 2010

    assert items[0].director.tag == "Joseph Kosinski"
    assert items[0].country.tag == "USA"

    assert [genre.tag for genre in items[0].genres] == ["Action", "Adventure"]

    assert [writer.tag for writer in items[0].writers
            ] == ["Adam Horowitz", "Richard Jefferies"]

    assert [role.tag for role in items[0].roles
            ] == ["Garrett Hedlund", "Jeff Bridges", "Olivia Wilde"]

    # Validate 'season'
    assert items[1].type == 'season'
    assert items[1].title == "Specials"
    assert items[1].index == 0

    assert items[1].show.title == "Gold Rush"
    assert items[1].show.index == 1

    # Validate 'album'
    assert items[2].type == 'album'
    assert items[2].title == "Angel Milk"
    assert items[2].index == 1

    assert items[2].artist.title == six.u('T\xe9l\xe9popmusik')

    assert [genre.tag
            for genre in items[2].genres] == ["Electronic", "Electronica"]
Exemplo n.º 40
0
def test_section_all():
    responses.add(
        responses.GET, 'http://mock:32400/library/sections/1/all',
        body=read('fixtures/library/sections/1/all.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library/sections/1'].all()
    assert container is not None

    items = list(container)
    assert len(items) == 2

    assert items[0].title == "Gold Rush"
    assert items[0].type == 'show'

    assert items[1].title == "Parks and Recreation"
    assert items[1].type == 'show'
Exemplo n.º 41
0
def test_movie():
    responses.add(responses.GET,
                  'http://mock/movies/tron-legacy-2010',
                  body=read('fixtures/movies/tron-legacy-2010.json'),
                  status=200,
                  content_type='application/json')

    Trakt.base_url = 'http://mock'

    movie = Trakt['movies'].get('tron-legacy-2010')

    assert movie.title == 'TRON: Legacy'
    assert movie.year == 2010

    assert movie.pk == ('imdb', 'tt1104001')

    assert movie.keys == [('imdb', 'tt1104001'), ('tmdb', '20526'),
                          ('slug', 'tron-legacy-2010'), ('trakt', '12601')]
Exemplo n.º 42
0
def test_show():
    responses.add(responses.GET,
                  'http://mock/shows/1390',
                  body=read('fixtures/shows/1390.json'),
                  status=200,
                  content_type='application/json')

    Trakt.base_url = 'http://mock'

    show = Trakt['shows'].get(1390)

    assert show.title == 'Game of Thrones'
    assert show.year == 2011

    assert show.pk == ('tvdb', '121361')
    assert show.keys == [('tvdb', '121361'), ('tmdb', '1399'),
                         ('imdb', 'tt0944947'), ('tvrage', '24493'),
                         ('slug', 'game-of-thrones'), ('trakt', '1390')]
Exemplo n.º 43
0
def test_clients():
    responses.add(
        responses.GET, 'http://mock:32400/clients',
        body=read('fixtures/clients.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex.clients()
    assert container is not None

    items = list(container)
    assert len(items) == 1

    assert items[0].name == "One"
    assert items[0].address == "192.168.1.100"
    assert items[0].version == "1.2.2.331-2d6426d7"

    assert items[0].protocol_capabilities == "navigation,playback,timeline,mirror,playqueues"
Exemplo n.º 44
0
def test_sessions_get():
    responses.add(
        responses.GET, 'http://mock:32400/status/sessions',
        body=read('fixtures/status/sessions.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['status'].sessions()
    assert container is not None

    # Try retrieve item that exists
    item = container.get(5)
    assert item is not None

    assert item.session.key == 5

    # Try retrieve item that doesn't exist
    item = container.get(123)
    assert item is None
Exemplo n.º 45
0
def test_show_all_leaves():
    responses.add(
        responses.GET, 'http://mock:32400/library/metadata/1/allLeaves',
        body=read('fixtures/library/all_leaves/show.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library/metadata'].all_leaves(1)
    assert container is not None

    items = list(container)
    assert len(items) == 6

    # Ensure season/episode indexes are correct
    assert [(episode.season.index, episode.index) for episode in items] == [
        (10, 1), (10, 2),
        (11, 1), (11, 2),
        (12, 1), (12, 2)
    ]
Exemplo n.º 46
0
def test_sessions_get():
    responses.add(responses.GET,
                  'http://mock:32400/status/sessions',
                  body=read('fixtures/status/sessions.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex['status'].sessions()
    assert container is not None

    # Try retrieve item that exists
    item = container.get(5)
    assert item is not None

    assert item.session.key == 5

    # Try retrieve item that doesn't exist
    item = container.get(123)
    assert item is None
Exemplo n.º 47
0
def test_sections():
    responses.add(
        responses.GET, 'http://mock:32400/library/sections',
        body=read('fixtures/library/sections.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library'].sections()
    assert container is not None

    items = list(container)
    assert len(items) == 2

    # Validate sections
    assert items[0].type == 'show'
    assert items[0].agent == 'com.plexapp.agents.thetvdb'

    assert items[1].type == 'movie'
    assert items[1].agent == 'com.plexapp.agents.themoviedb'
Exemplo n.º 48
0
def test_clients_get():
    responses.add(
        responses.GET, 'http://mock:32400/clients',
        body=read('fixtures/clients.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex.clients()
    assert container is not None

    # Try retrieve item that exists
    item = container.get("a7d1b50a-42d1-40b5-9db6-6b0afd013438")
    assert item is not None

    assert item.machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438"

    # Try retrieve item that doesn't exist
    item = container.get("invalid-identifier")
    assert item is None
Exemplo n.º 49
0
def test_clients():
    responses.add(responses.GET,
                  'http://mock:32400/clients',
                  body=read('fixtures/clients.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex.clients()
    assert container is not None

    items = list(container)
    assert len(items) == 1

    assert items[0].name == "One"
    assert items[0].address == "192.168.1.100"
    assert items[0].version == "1.2.2.331-2d6426d7"

    assert items[
        0].protocol_capabilities == "navigation,playback,timeline,mirror,playqueues"
Exemplo n.º 50
0
def test_clients_get():
    responses.add(responses.GET,
                  'http://mock:32400/clients',
                  body=read('fixtures/clients.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex.clients()
    assert container is not None

    # Try retrieve item that exists
    item = container.get("a7d1b50a-42d1-40b5-9db6-6b0afd013438")
    assert item is not None

    assert item.machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438"

    # Try retrieve item that doesn't exist
    item = container.get("invalid-identifier")
    assert item is None
Exemplo n.º 51
0
def test_movie():
    responses.add(responses.GET,
                  'http://mock/movies/trending',
                  body=read('fixtures/movies/trending.json'),
                  status=200,
                  content_type='application/json')

    Trakt.base_url = 'http://mock'

    movies = Trakt['movies'].trending()

    assert len(movies) == 10

    assert [(m.watchers, m.title, m.year) for m in movies
            ] == [(24, "Cinderella", 2015), (15, "Pleasure or Pain", 2013),
                  (14, "Get Hard", 2015), (12, "Mad Max: Fury Road", 2015),
                  (11, "Maggie", 2015), (10, "The Gunman", 2015),
                  (9, "Ex Machina", 2015),
                  (8, "The SpongeBob Movie: Sponge Out of Water", 2015),
                  (7, "Chappie", 2015), (6, "While We're Young", 2015)]
Exemplo n.º 52
0
def test_servers():
    responses.add(
        responses.GET, 'http://mock:32400/servers',
        body=read('fixtures/servers.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex.servers()
    assert container is not None

    items = list(container)
    assert len(items) == 2

    assert items[0].name == "One"
    assert items[0].address == "192.168.1.100"
    assert items[0].version == "0.9.9.16.555-50cd0c3"

    assert items[1].name == "Two"
    assert items[1].address == "192.168.1.101"
    assert items[1].version == "0.9.9.14.531-7eef8c6"
Exemplo n.º 53
0
def test_servers():
    responses.add(responses.GET,
                  'http://mock:32400/servers',
                  body=read('fixtures/servers.xml'),
                  status=200,
                  content_type='application/xml')

    container = Plex.servers()
    assert container is not None

    items = list(container)
    assert len(items) == 2

    assert items[0].name == "One"
    assert items[0].address == "192.168.1.100"
    assert items[0].version == "0.9.9.16.555-50cd0c3"

    assert items[1].name == "Two"
    assert items[1].address == "192.168.1.101"
    assert items[1].version == "0.9.9.14.531-7eef8c6"
Exemplo n.º 54
0
def test_sessions():
    responses.add(
        responses.GET, 'http://mock:32400/status/sessions',
        body=read('fixtures/status/sessions.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['status'].sessions()
    assert container is not None

    items = list(container)
    assert len(items) == 3

    # Validate 'episode'
    assert items[0].title == "Blind Date"
    assert items[0].type == 'episode'

    assert items[0].show.title == "30 Rock"

    assert items[0].session.key == 3
    assert items[2].session.player.title == "One"
    assert items[2].session.user.title == "someone"

    # Validate 'movie'
    assert items[1].title == "The Hobbit The Desolation of Smaug"
    assert items[1].type == 'movie'

    assert items[1].session.key == 5
    assert items[2].session.player.title == "One"
    assert items[2].session.user.title == "someone"

    # Validate 'track'
    assert items[2].title == "Don't look back"
    assert items[2].type == 'track'

    assert items[2].album.title == "Angel Milk"
    assert items[2].artist.title == six.u('T\xe9l\xe9popmusik')

    assert items[2].session.key == 4
    assert items[2].session.player.title == "One"
    assert items[2].session.user.title == "someone"