Beispiel #1
0
def test_dispatch():
    client = mk_mock_client({r".*checkin.*": [CHECKIN_EPISODE, 201]})

    with pytest.raises(ArgumentError):
        client.checkin.check_into()

    with pytest.raises(ArgumentError):
        client.checkin.check_into(episode="eid", movie="eid")

    client.checkin.check_into(episode="eid")

    client = mk_mock_client({r".*checkin.*": [CHECKIN_MOVIE, 201]})
    client.checkin.check_into(movie="eid")
Beispiel #2
0
def test_use_cached():
    client = mk_mock_client({".*": [[], 200]})

    client.networks.get_networks()
    client.networks.get_networks()

    assert len(client.http._requests.req_stack) == 1
Beispiel #3
0
def test_get_lists():
    client = mk_mock_client({r".*people.*": [[LIST], 200]})

    lists = list(client.people.get_lists(person=123))

    assert len(lists) == 1
    assert lists[0].name == LIST["name"]
Beispiel #4
0
def test_take():
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    client = mk_mock_client({"pag_on": [data, 200]}, paginated=["pag_on"])
    executor = Executor(client)
    p_pag = Path("pag_on", [int], pagination=True)

    it = executor.run(path=p_pag, per_page=2)
    assert it.has_next()
    assert isinstance(next(it), int)
    assert next(it) == 2
    assert it.has_next()

    assert it.take(3) == [3, 4, 5]
    assert it.has_next()

    with pytest.raises(ArgumentError):
        it.take(-5)

    assert it.take(0) == []
    assert it.take() == [6, 7]  # per_page setting
    assert it.has_next()

    assert it.take_all() == [8, 9, 10]
    assert not it.has_next()

    with pytest.raises(StopIteration):
        next(it)

    assert it.take(2) == it.take_all() == []
Beispiel #5
0
def test_movie_arg_validation():
    client = mk_mock_client({r".*checkin.*": [CHECKIN_MOVIE, 201]}, user=None)

    with pytest.raises(NotAuthenticated):
        client.checkin.check_into()

    with pytest.raises(NotAuthenticated):
        client.checkin.check_into_movie(movie="mid")

    client.set_user(USER)

    with pytest.raises(TypeError):
        client.checkin.check_into_movie()

    with pytest.raises(ArgumentError):
        client.checkin.check_into_movie(movie="eid", sharing=True)

    client.checkin.check_into_movie(movie="eid", sharing={"twitter": True})
    client.checkin.check_into_movie(movie="eid",
                                    sharing=Sharing(medium=True,
                                                    twitter=False))

    with pytest.raises(ArgumentError):
        client.checkin.check_into_movie(movie="eid", message=55)

    movie = parse_tree(MOVIE1, Movie)
    client.checkin.check_into_movie(movie=movie)
Beispiel #6
0
def test_episode_arg_validation():
    client = mk_mock_client({r".*checkin.*": [CHECKIN_EPISODE, 201]},
                            user=None)

    with pytest.raises(NotAuthenticated):
        client.checkin.check_into()

    with pytest.raises(NotAuthenticated):
        client.checkin.check_into_episode(episode="eid")

    client.set_user(USER)

    with pytest.raises(TypeError):
        client.checkin.check_into_episode()

    with pytest.raises(ArgumentError):
        client.checkin.check_into_episode(episode="eid", sharing=True)

    client.checkin.check_into_episode(episode="eid", sharing={"twitter": True})
    client.checkin.check_into_episode(episode="eid",
                                      sharing=Sharing(medium=True,
                                                      twitter=False))

    with pytest.raises(ArgumentError):
        client.checkin.check_into_episode(episode="eid", show=True)

    client.checkin.check_into_episode(episode="eid",
                                      show={"ids": {
                                          "trakt": "123"
                                      }})

    episode, show = parse_tree(EPISODE, Episode), parse_tree(SHOW, Show)
    client.checkin.check_into_episode(episode=episode, show=show)
Beispiel #7
0
def test_cache_timeout():
    client = mk_mock_client({".*": [[], 200]}, cache={"timeout": -1})

    client.networks.get_networks()
    client.networks.get_networks()

    assert len(client.http._requests.req_stack) == 2
Beispiel #8
0
def test_start_scrobble_episode():
    client = mk_mock_client({".*scrobble.*": [RESP_EPISODE, 201]})

    episode = parse_tree(EPISODE, Episode)
    show = parse_tree(SHOW, Show)
    resp = client.scrobble.start_scrobble(episode=episode, show=show, progress=5)

    assert resp.show.title == SHOW["title"]
Beispiel #9
0
def test_last_episode():
    client = mk_mock_client({".*shows.*": next_last_ep_responses()})

    no_ep = client.shows.get_last_episode(show=123, extended=True)
    ep = client.shows.get_last_episode(show=123, extended=True)

    assert no_ep is None
    assert ep.overview == EXTENDED_EPISODE["overview"]
Beispiel #10
0
def test_lists():
    resp = [TRENDING_LISTS, 200, {"X-Pagination-Page-Count": 1}]
    client = mk_mock_client({r".*lists/(trending|popular).*": resp})

    tre = list(client.lists.get_trending())
    pop = list(client.lists.get_popular())
    assert tre[0].like_count == pop[0].like_count == TRENDING_LISTS[0][
        "like_count"]
Beispiel #11
0
def comments_client():
    return mk_mock_client({
        r".*comments/.*/item.*": [ATTACHED_SHOW, 200],
        r".*comments/.*/likes.*": [[LIKED_USER], 200, PAG_H],
        r".*comments/trending.*": [TRENDING_COMMENTS, 200, PAG_H],
        r".*comments/recent.*": [TRENDING_COMMENTS, 200, PAG_H],
        r".*comments/updates.*": [TRENDING_COMMENTS, 200, PAG_H],
    })
Beispiel #12
0
def test_dvd():
    client = mk_mock_client(
        {r".*calendars/(my|all)/dvd.*": [MOVIE_PREMIERES, 200]})

    dvd = client.calendars.get_dvd_releases()
    my_dvd = client.calendars.get_my_dvd_releases()

    assert dvd == my_dvd
Beispiel #13
0
def test_update_comment():
    client = mk_mock_client({".*comments.*": [COMMENT, 200]})

    with pytest.raises(ArgumentError):
        client.comments.update_comment(id=123, comment="a b")

    comment = client.comments.update_comment(id=123, comment="a b c d e f")

    assert comment.replies == COMMENT["replies"]
Beispiel #14
0
def test_get_person():
    client = mk_mock_client({r".*people.*": [PERSON, 200]})
    person = parse_tree(PERSON, Person)

    with pytest.raises(ArgumentError):
        client.people.get_person(person=0.5)

    assert client.people.get_person(person=person.ids.trakt).name == PERSON["name"]
    assert client.people.get_person(person=person).name == PERSON["name"]
Beispiel #15
0
def test_chaining():
    data = list(range(300))
    client = mk_mock_client({"pag_on": [data, 200]}, paginated=["pag_on"])
    executor = Executor(client)
    p_pag = Path("pag_on", [int], pagination=True)

    assert executor.run(path=p_pag, per_page=2).take_all() == data
    assert executor.run(path=p_pag,
                        per_page=2).prefetch_all().take_all() == data
Beispiel #16
0
def test_countries():
    client = mk_mock_client({r".*countries.*": [COUNTRIES, 200]})

    with pytest.raises(ArgumentError):
        client.countries.get_countries(type="qwerty")

    countries = client.countries.get_countries(type="shows")

    assert countries[0].code == COUNTRIES[0]["code"]
Beispiel #17
0
def test_certifications():
    client = mk_mock_client({r".*certifications.*": [CERTIFICATIONS, 200]})

    with pytest.raises(ArgumentError):
        client.certifications.get_certifications(type="qwerty")

    certifications = client.certifications.get_certifications(type="shows")

    assert certifications[0].slug == CERTIFICATIONS["us"][0]["slug"]
Beispiel #18
0
def test_movies():
    client = mk_mock_client(
        {r".*calendars/(my|all)/movies.*": [MOVIE_PREMIERES, 200]})

    movies = client.calendars.get_movies()
    my_movies = client.calendars.get_my_movies()

    assert movies == my_movies
    assert len(movies) == 2
    assert movies[0].released == date(2014, 8, 1)
Beispiel #19
0
def test_text_query():
    client = mk_mock_client({".*search.*": [TEXT_RESULTS, 200, PAG_H]})
    results = list(
        client.search.text_query(
            query="abc", type=["movie", "show"], fields=["title", "overview"]
        )
    )

    assert len(results) == 2
    assert results[1].type == TEXT_RESULTS[1]["type"]
Beispiel #20
0
def test_post_comment():
    client = mk_mock_client({".*comments.*": [COMMENT, 201]})
    text = "a b c d e f"  # at least 5 words
    sharing = Sharing(twitter=True)
    comment = client.comments.post_comment(item=123,
                                           comment=text,
                                           spoiler=True,
                                           sharing=sharing)

    assert comment.id == COMMENT["id"]
Beispiel #21
0
def test_delete_checkins():
    client = mk_mock_client({r".*checkin.*": [{}, 204]}, user=None)

    with pytest.raises(NotAuthenticated):
        client.checkin.delete_active_checkins()

    client.set_user(USER)

    client.checkin.delete_active_checkins()
    assert get_last_req(client.http)["method"] == "DELETE"
def test_add_quargs():
    client = mk_mock_client({".*": [[], 200]})
    path = Path("a", [None], qargs=["arg"])

    executor = Executor(client)

    _ = executor.run(path=path, arg="abc")

    req = client.http._requests.req_map["a"][0]

    assert req["path"].endswith(r"/a?arg=abc")
Beispiel #23
0
def test_prefetch_off():
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    client = mk_mock_client({"pag_on": [data, 200]}, paginated=["pag_on"])
    executor = Executor(client)
    p_pag = Path("pag_on", [int], pagination=True)

    assert get_last_req(client.http) is None
    req = executor.run(path=p_pag, page=2, per_page=3)
    assert get_last_req(client.http) is None
    list(req)
    assert get_last_req(client.http) is not None
Beispiel #24
0
def test_stop_scrobble_movie():
    client = mk_mock_client({".*scrobble.*": [RESP_MOVIE, 201]})

    with pytest.raises(ArgumentError):
        client.scrobble.stop_scrobble(progress=5)

    with pytest.raises(ArgumentError):
        client.scrobble.stop_scrobble(progress=5, episode=123, movie=123)

    resp = client.scrobble.stop_scrobble(movie=123, progress=5)
    assert resp.movie.title == MOVIE1["title"]
Beispiel #25
0
def seasons_client():
    PAG_H = {"X-Pagination-Page-Count": 1}
    return mk_mock_client(
        {
            r".*seasons/.*/comments.*": [COMMENTS, 200, PAG_H],
            r".*seasons/.*/lists.*": [[LIST], 200, PAG_H],
            r".*seasons/.*/ratings.*": [RATINGS, 200],
            r".*seasons/.*/stats.*": [SHOW_STATS, 200],
            r".*seasons/.*/watching.*": [[USER], 200],
        }
    )
def test_recommendations_shows():
    client = mk_mock_client({r".*shows\?ignore_collected=true": [[SHOW], 200]},
                            user=None)

    with pytest.raises(NotAuthenticated):
        client.recommendations.get_show_recommendations()

    client.set_user(USER)
    shows = client.recommendations.get_show_recommendations(
        ignore_collected=True)

    assert len(shows) == 1
Beispiel #27
0
def episodes_client():
    PAG_H = {"X-Pagination-Page-Count": 1}
    return mk_mock_client(
        {
            r".*episodes/.*/translations.*": [TRANSLATIONS, 200],
            r".*episodes/.*/comments.*": [COMMENTS, 200, PAG_H],
            r".*episodes/.*/lists.*": [[LIST], 200, PAG_H],
            r".*episodes/.*/ratings.*": [RATINGS, 200],
            r".*episodes/.*/stats.*": [SHOW_STATS, 200],
            r".*episodes/.*/watching.*": [[USER], 200],
        }
    )
Beispiel #28
0
def test_shows():
    client = mk_mock_client({r".*calendars/.*/shows.*": [SHOWS, 200]},
                            user=None)

    with pytest.raises(NotAuthenticated):
        client.calendars.get_my_shows()

    shows = client.calendars.get_shows()
    client.set_user(USER)
    my_shows = client.calendars.get_my_shows(start_date="2014-09-01", days=7)

    assert my_shows == shows
Beispiel #29
0
def test_executor():
    response = [{"name": "Australia", "code": "au"}]
    client = mk_mock_client({".*": [response, 200]})

    assert len(client.request("countries", type="shows")) == len(response)
    assert len(client.request("countries.get_countries",
                              type="shows")) == len(response)

    countries = client.request("get_countries", type="shows")
    assert [asdict(s) for s in countries] == response

    with pytest.raises(ClientError):
        client.request("count", type="shows")
def test_hide_show():
    m_id = SHOW["ids"]["trakt"]
    client = mk_mock_client({rf".*shows/{m_id}": [{}, 204]}, user=None)

    show = parse_tree(SHOW, tree_structure=Show)

    with pytest.raises(NotAuthenticated):
        client.recommendations.hide_show(show=show)

    client.set_user(USER)

    client.recommendations.hide_show(show=show)

    assert get_last_req(client.http)["method"] == "DELETE"