def test_get_top():
    responses.add(responses.GET,
                  '{}games/top'.format(BASE_URL),
                  body=json.dumps(example_top_games_response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('abcd')

    games = client.games.get_top()

    assert len(responses.calls) == 1
    assert len(games) == 1
    assert isinstance(games[0], TopGame)
    game = games[0].game
    assert isinstance(game, Game)
    assert game.id == example_top_games_response['top'][0]['game']['_id']
def test_get_top():
    params = {'limit': 1, 'period': 'month'}

    responses.add(
        responses.GET,
        '%sclips/top' % BASE_URL,
        body=json.dumps(example_clips),
        status=200,
        content_type='application/json'
    )

    client = TwitchClient('client id')
    clips = client.clips.get_top(**params)

    assert len(clips) == len(example_clips)
    assert isinstance(clips[0], Clip)
    assert clips[0].broadcast_id == example_clips['clips'][0]['broadcast_id']
def test_get_by_id():
    video_id = 'v106400740'
    responses.add(responses.GET,
                  '%svideos/%s' % (BASE_URL, video_id),
                  body=json.dumps(example_video_response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    video = client.videos.get_by_id(video_id)

    assert len(responses.calls) == 1
    assert isinstance(video, Video)
    assert video.id == example_video_response['_id']
    assert video.description == example_video_response['description']
    assert video.fps['1080p'] == example_video_response['fps']['1080p']
Example #4
0
def test_get():
    responses.add(
        responses.GET,
        "{}user".format(BASE_URL),
        body=json.dumps(example_user),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    user = client.users.get()

    assert len(responses.calls) == 1
    assert isinstance(user, User)
    assert user.id == example_user["_id"]
    assert user.name == example_user["name"]
def test_get_post():
    channel_id = '1234'
    post_id = example_post['id']
    responses.add(responses.GET,
                  '{}feed/{}/posts/{}'.format(BASE_URL, channel_id, post_id),
                  body=json.dumps(example_post),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    post = client.channel_feed.get_post(channel_id, post_id)

    assert len(responses.calls) == 1
    assert isinstance(post, Post)
    assert post.id == example_post['id']
    assert post.body == example_post['body']
def test_create_post():
    channel_id = '1234'
    response = {'post': example_post, 'tweet': None}
    responses.add(responses.POST,
                  '{}feed/{}/posts'.format(BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth token')

    post = client.channel_feed.create_post(channel_id, 'abcd')

    assert len(responses.calls) == 1
    assert isinstance(post, Post)
    assert post.id == example_post['id']
    assert post.body == example_post['body']
Example #7
0
def test_create_post_comment():
    channel_id = '1234'
    post_id = example_post['id']
    responses.add(responses.POST,
                  '{}feed/{}/posts/{}/comments'.format(BASE_URL, channel_id, post_id),
                  body=json.dumps(example_comment),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth token')

    comment = client.channel_feed.create_post_comment(channel_id, post_id, 'abcd')

    assert len(responses.calls) == 1
    assert isinstance(comment, Comment)
    assert comment.id == example_comment['id']
    assert comment.body == example_comment['body']
Example #8
0
def test_start_commercial():
    channel_id = example_channel["_id"]
    response = {"duration": 30, "message": "", "retryafter": 480}
    responses.add(
        responses.POST,
        "{}channels/{}/commercial".format(BASE_URL, channel_id),
        body=json.dumps(response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    commercial = client.channels.start_commercial(channel_id)

    assert len(responses.calls) == 1
    assert isinstance(commercial, dict)
    assert commercial["duration"] == response["duration"]
def test_get_metadata():
    collection_id = "abcd"
    responses.add(
        responses.GET,
        "{}collections/{}".format(BASE_URL, collection_id),
        body=json.dumps(example_collection),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    collection = client.collections.get_metadata(collection_id)

    assert len(responses.calls) == 1
    assert isinstance(collection, Collection)
    assert collection.id == example_collection["_id"]
    assert collection.items_count == example_collection["items_count"]
def test_add_item():
    collection_id = "abcd"
    responses.add(
        responses.PUT,
        "{}collections/{}/items".format(BASE_URL, collection_id),
        body=json.dumps(example_item),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth client")

    item = client.collections.add_item(collection_id, "1234", "video")

    assert len(responses.calls) == 1
    assert isinstance(item, Item)
    assert item.id == example_item["_id"]
    assert item.title == example_item["title"]
def test_get():
    team_name = "spongebob"
    responses.add(
        responses.GET,
        "{}teams/{}".format(BASE_URL, team_name),
        body=json.dumps(example_team_response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    team = client.teams.get(team_name)

    assert len(responses.calls) == 1
    assert isinstance(team, Team)
    assert team.id == example_team_response["_id"]
    assert team.name == example_team_response["name"]
Example #12
0
def test_delete_reaction_to_post():
    channel_id = '1234'
    post_id = example_post['id']
    body = {'deleted': True}
    responses.add(responses.DELETE,
                  '%sfeed/%s/posts/%s/reactions' %
                  (BASE_URL, channel_id, post_id),
                  body=json.dumps(body),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth token')

    response = client.channel_feed.delete_reaction_to_post(
        channel_id, post_id, '1234')

    assert len(responses.calls) == 1
    assert response['deleted']
def test_games():
    response = {'_total': 2147, 'games': [example_game]}
    responses.add(responses.GET,
                  '%ssearch/games' % BASE_URL,
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    games = client.search.games('mah query')

    assert len(responses.calls) == 1
    assert len(games) == 1
    game = games[0]
    assert isinstance(game, Game)
    assert game.id == example_game['_id']
    assert game.name == example_game['name']
Example #14
0
def test_get_by_id():
    community_id = "abcd"
    responses.add(
        responses.GET,
        "{}communities/{}".format(BASE_URL, community_id),
        body=json.dumps(example_community),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    community = client.communities.get_by_id(community_id)

    assert len(responses.calls) == 1
    assert isinstance(community, Community)
    assert community.id == example_community["_id"]
    assert community.name == example_community["name"]
Example #15
0
def test_download_vod():
    video_id = 'v106400740'
    vod_id = '106400740'
    responses.add(responses.GET,
                  '{}vods/{}/access_token'.format('https://api.twitch.tv/api/', vod_id),
                  body=json.dumps(example_download_vod_token_response),
                  status=200,
                  content_type='application/json')
    responses.add(responses.GET,
                  '{}vod/{}'.format(VOD_FETCH_URL, vod_id),
                  body=b'',
                  status=200,
                  content_type='application/x-mpegURL')
    client = TwitchClient('client id')
    vod = client.videos.download_vod(video_id)

    assert len(responses.calls) == 2
    assert vod == b''
def test_get_permissions():
    community_id = 'abcd'
    response = {'ban': True, 'timeout': True, 'edit': True}

    responses.add(responses.GET,
                  '{}communities/{}/permissions'.format(
                      BASE_URL, community_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth token')

    permissions = client.communities.get_permissions(community_id)

    assert len(responses.calls) == 1
    assert isinstance(permissions, dict)
    assert permissions['ban'] is True
def test_get_emotes():
    user_id = 1234
    response = {"emoticon_sets": {"17937": [{"code": "Kappa", "id": 25}]}}
    responses.add(
        responses.GET,
        "{}users/{}/emotes".format(BASE_URL, user_id),
        body=json.dumps(response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    emotes = client.users.get_emotes(user_id)

    assert len(responses.calls) == 1
    assert isinstance(emotes, dict)
    assert emotes["17937"] == response["emoticon_sets"]["17937"]
def test_channels():
    response = {'_total': 2147, 'channels': [example_channel]}
    responses.add(responses.GET,
                  '%ssearch/channels' % BASE_URL,
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    channels = client.search.channels('mah query')

    assert len(responses.calls) == 1
    assert len(channels) == 1
    channel = channels[0]
    assert isinstance(channel, Channel)
    assert channel.id == example_channel['_id']
    assert channel.name == example_channel['name']
def test_delete_post():
    channel_id = "1234"
    post_id = example_post["id"]
    responses.add(
        responses.DELETE,
        "{}feed/{}/posts/{}".format(BASE_URL, channel_id, post_id),
        body=json.dumps(example_post),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    post = client.channel_feed.delete_post(channel_id, post_id)

    assert len(responses.calls) == 1
    assert isinstance(post, Post)
    assert post.id == example_post["id"]
def test_get_summary():
    response = {"channels": 1417, "viewers": 19973}
    responses.add(
        responses.GET,
        "{}streams/summary".format(BASE_URL),
        body=json.dumps(response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    summary = client.streams.get_summary()

    assert len(responses.calls) == 1
    assert isinstance(summary, dict)
    assert summary["channels"] == response["channels"]
    assert summary["viewers"] == response["viewers"]
def test_delete_reaction_to_post():
    channel_id = "1234"
    post_id = example_post["id"]
    body = {"deleted": True}
    responses.add(
        responses.DELETE,
        "{}feed/{}/posts/{}/reactions".format(BASE_URL, channel_id, post_id),
        body=json.dumps(body),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    response = client.channel_feed.delete_reaction_to_post(channel_id, post_id, "1234")

    assert len(responses.calls) == 1
    assert response["deleted"]
Example #22
0
def test_update():
    channel_id = example_channel['_id']
    responses.add(responses.PUT,
                  '{}channels/{}'.format(BASE_URL, channel_id),
                  body=json.dumps(example_channel),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth token')
    status = 'Spongebob Squarepants'
    channel = client.channels.update(channel_id, status=status)

    assert len(responses.calls) == 1
    expected_body = json.dumps({'channel': {'status': status}}).encode('utf-8')
    assert responses.calls[0].request.body == expected_body
    assert isinstance(channel, Channel)
    assert channel.id == channel_id
    assert channel.name == example_channel['name']
def test_create():
    channel_id = "abcd"
    responses.add(
        responses.POST,
        "{}channels/{}/collections".format(BASE_URL, channel_id),
        body=json.dumps(example_collection),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth client")

    collection = client.collections.create(channel_id, "this is title")

    assert len(responses.calls) == 1
    assert isinstance(collection, Collection)
    assert collection.id == example_collection["_id"]
    assert collection.items_count == example_collection["items_count"]
Example #24
0
def test_get_all_emoticons():
    response = {"emoticons": [example_emote]}
    responses.add(
        responses.GET,
        "{}chat/emoticons".format(BASE_URL),
        body=json.dumps(response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    emoticon_sets = client.chat.get_all_emoticons()

    assert len(responses.calls) == 1
    assert isinstance(emoticon_sets, dict)
    assert emoticon_sets["emoticons"] == response["emoticons"]
    assert emoticon_sets["emoticons"][0] == example_emote
Example #25
0
def test_get_by_id():
    channel_id = example_channel["_id"]
    responses.add(
        responses.GET,
        "{}channels/{}".format(BASE_URL, channel_id),
        body=json.dumps(example_channel),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    channel = client.channels.get_by_id(channel_id)

    assert len(responses.calls) == 1
    assert isinstance(channel, Channel)
    assert channel.id == channel_id
    assert channel.name == example_channel["name"]
Example #26
0
def test_translate_usernames_to_ids():
    response = {'users': [example_user]}
    responses.add(responses.GET,
                  '{}users'.format(BASE_URL),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth token')

    users = client.users.translate_usernames_to_ids(['lirik'])

    assert len(responses.calls) == 1
    assert len(users) == 1
    user = users[0]
    assert isinstance(user, User)
    assert user.id == example_user['_id']
    assert user.name == example_user['name']
Example #27
0
def test_get_top():
    responses.add(
        responses.GET,
        "{}games/top".format(BASE_URL),
        body=json.dumps(example_top_games_response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("abcd")

    games = client.games.get_top()

    assert len(responses.calls) == 1
    assert len(games) == 1
    assert isinstance(games[0], TopGame)
    game = games[0].game
    assert isinstance(game, Game)
    assert game.id == example_top_games_response["top"][0]["game"]["_id"]
Example #28
0
def test_get_by_id():
    video_id = "v106400740"
    responses.add(
        responses.GET,
        "{}videos/{}".format(BASE_URL, video_id),
        body=json.dumps(example_video_response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    video = client.videos.get_by_id(video_id)

    assert len(responses.calls) == 1
    assert isinstance(video, Video)
    assert video.id == example_video_response["_id"]
    assert video.description == example_video_response["description"]
    assert video.fps["1080p"] == example_video_response["fps"]["1080p"]
Example #29
0
def test_get_top():
    responses.add(
        responses.GET,
        "{}ingests".format(BASE_URL),
        body=json.dumps(example_response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("abcd")

    ingests = client.ingests.get_server_list()

    assert len(responses.calls) == 1
    assert len(ingests) == 1
    ingest = ingests[0]
    assert isinstance(ingest, Ingest)
    assert ingest.id == example_response["ingests"][0]["_id"]
    assert ingest.name == example_response["ingests"][0]["name"]
def test_get_all():
    responses.add(
        responses.GET,
        "{}teams".format(BASE_URL),
        body=json.dumps(example_all_response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    teams = client.teams.get_all()

    assert len(responses.calls) == 1
    assert len(teams) == 1
    team = teams[0]
    assert isinstance(team, Team)
    assert team.id == example_team_response["_id"]
    assert team.name == example_team_response["name"]