Exemplo n.º 1
0
def test_unblock_user():
    user_id = 1234
    blocked_user_id = 12345
    responses.add(responses.DELETE,
                  '{}users/{}/blocks/{}'.format(BASE_URL, user_id,
                                                blocked_user_id),
                  body=json.dumps(example_block),
                  status=200,
                  content_type='application/json')

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

    client.users.unblock_user(user_id, blocked_user_id)

    assert len(responses.calls) == 1
def test_get_by_id():
    community_id = 'abcd'
    responses.add(responses.GET,
                  '%scommunities/%s' % (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']
Exemplo n.º 3
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']
Exemplo n.º 4
0
def test_get_community():
    channel_id = example_channel['_id']
    responses.add(responses.GET,
                  '{}channels/{}/community'.format(BASE_URL, channel_id),
                  body=json.dumps(example_community),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    community = client.channels.get_community(channel_id)

    assert len(responses.calls) == 1
    assert isinstance(community, Community)
    assert community.id == example_community['_id']
    assert community.name == example_community['name']
Exemplo n.º 5
0
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']
Exemplo n.º 6
0
def test_reset_stream_key():
    channel_id = example_channel['_id']
    responses.add(responses.DELETE,
                  '%schannels/%s/stream_key' % (BASE_URL, channel_id),
                  body=json.dumps(example_channel),
                  status=200,
                  content_type='application/json')

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

    channel = client.channels.reset_stream_key(channel_id)

    assert len(responses.calls) == 1
    assert isinstance(channel, Channel)
    assert channel.id == example_channel['_id']
    assert channel.name == example_channel['name']
Exemplo n.º 7
0
def test_get_stream_by_user_returns_none_if_stream_is_offline():
    channel_id = 7236692
    responses.add(
        responses.GET,
        "{}streams/{}".format(BASE_URL, channel_id),
        body=json.dumps({"stream": None}),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    stream = client.streams.get_stream_by_user(channel_id)

    assert len(responses.calls) == 1
    assert stream is None
Exemplo n.º 8
0
def test_delete_moderator():
    community_id = "abcd"
    user_id = 12345
    responses.add(
        responses.DELETE,
        "{}communities/{}/moderators/{}".format(BASE_URL, community_id,
                                                user_id),
        status=204,
        content_type="application/json",
    )

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

    client.communities.delete_moderator(community_id, user_id)

    assert len(responses.calls) == 1
def test_move_item():
    collection_id = "abcd"
    collection_item_id = "1234"
    responses.add(
        responses.PUT,
        "{}collections/{}/items/{}".format(BASE_URL, collection_id,
                                           collection_item_id),
        status=204,
        content_type="application/json",
    )

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

    client.collections.move_item(collection_id, collection_item_id, 3)

    assert len(responses.calls) == 1
Exemplo n.º 10
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
Exemplo n.º 11
0
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']
Exemplo n.º 12
0
def test_get_by_slug():
    slug = 'OpenUglySnoodVoteNay'

    responses.add(
        responses.GET,
        '{}clips/{}'.format(BASE_URL, slug),
        body=json.dumps(example_clip),
        status=200,
        content_type='application/json'
    )

    client = TwitchClient('client id')
    clip = client.clips.get_by_slug(slug)

    assert isinstance(clip, Clip)
    assert clip.broadcast_id == example_clip['broadcast_id']
Exemplo n.º 13
0
def test_get_by_id():
    user_id = 1234
    responses.add(responses.GET,
                  '{}users/{}'.format(BASE_URL, user_id),
                  body=json.dumps(example_user),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    user = client.users.get_by_id(user_id)

    assert len(responses.calls) == 1
    assert isinstance(user, User)
    assert user.id == example_user['_id']
    assert user.name == example_user['name']
def test_channels_does_not_raise_if_no_channels_were_found():
    response = {"channels": None}
    responses.add(
        responses.GET,
        "{}search/channels".format(BASE_URL),
        body=json.dumps(response),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    channels = client.search.channels("mah bad query")

    assert len(responses.calls) == 1
    assert len(channels) == 0
Exemplo n.º 15
0
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']
Exemplo n.º 16
0
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']
Exemplo n.º 17
0
def test_delete_post():
    channel_id = '1234'
    post_id = example_post['id']
    responses.add(responses.DELETE,
                  '%sfeed/%s/posts/%s' % (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']
Exemplo n.º 18
0
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']
Exemplo n.º 19
0
def test_set_community():
    channel_id = example_channel["_id"]
    community_id = example_community["_id"]
    responses.add(
        responses.PUT,
        "{}channels/{}/community/{}".format(BASE_URL, channel_id,
                                            community_id),
        status=204,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    client.channels.set_community(channel_id, community_id)

    assert len(responses.calls) == 1
Exemplo n.º 20
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']
Exemplo n.º 21
0
def test_get_emoticons_by_set():
    response = {'emoticon_sets': {'19151': [example_emote]}}
    responses.add(responses.GET,
                  '%schat/emoticon_images' % BASE_URL,
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    emoticon_sets = client.chat.get_emoticons_by_set()

    assert len(responses.calls) == 1
    assert isinstance(emoticon_sets, dict)
    assert emoticon_sets['emoticon_sets'] == response['emoticon_sets']
    assert emoticon_sets['emoticon_sets']['19151'][0] == example_emote
Exemplo n.º 22
0
def test_create_post():
    channel_id = '1234'
    response = {'post': example_post, 'tweet': None}
    responses.add(responses.POST,
                  '%sfeed/%s/posts' % (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']
Exemplo n.º 23
0
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']
Exemplo n.º 24
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']
Exemplo n.º 25
0
def test_get_top():
    params = {'limit': 1, 'period': 'month'}

    responses.add(
        responses.GET,
        '{}clips/top'.format(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']
Exemplo n.º 26
0
def test_get_by_name():
    responses.add(
        responses.GET,
        "{}communities".format(BASE_URL),
        body=json.dumps(example_community),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    community = client.communities.get_by_name("spongebob")

    assert len(responses.calls) == 1
    assert isinstance(community, Community)
    assert community.id == example_community["_id"]
    assert community.name == example_community["name"]
def test_get_permissions():
    community_id = 'abcd'
    response = {'ban': True, 'timeout': True, 'edit': True}

    responses.add(responses.GET,
                  '%scommunities/%s/permissions' % (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
Exemplo n.º 28
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']
Exemplo n.º 29
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']
Exemplo n.º 30
0
def test_get():
    responses.add(
        responses.GET,
        "{}channel".format(BASE_URL),
        body=json.dumps(example_channel),
        status=200,
        content_type="application/json",
    )

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

    channel = client.channels.get()

    assert len(responses.calls) == 1
    assert isinstance(channel, Channel)
    assert channel.id == example_channel["_id"]
    assert channel.name == example_channel["name"]