python类calls()的实例源码

test_channels.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_get_subscribers():
    channel_id = example_channel['_id']
    response = {
        '_total': 1,
        'subscriptions': [example_subscription]
    }
    responses.add(responses.GET,
                  '%schannels/%s/subscriptions' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    subscribers = client.channels.get_subscribers(channel_id)

    assert len(responses.calls) == 1
    assert len(subscribers) == 1
    subscribe = subscribers[0]
    assert isinstance(subscribe, Subscription)
    assert subscribe.id == example_subscription['_id']
    assert isinstance(subscribe.user, User)
    assert subscribe.user.id == example_user['_id']
    assert subscribe.user.name == example_user['name']
test_channels.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_get_videos():
    channel_id = example_channel['_id']
    response = {
        'videos': [example_video]
    }
    responses.add(responses.GET,
                  '%schannels/%s/videos' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    videos = client.channels.get_videos(channel_id)

    assert len(responses.calls) == 1
    assert len(videos) == 1
    assert isinstance(videos[0], Video)
    video = videos[0]
    assert isinstance(video, Video)
    assert video.id == example_video['_id']
    assert video.description == example_video['description']
    assert video.fps['1080p'] == example_video['fps']['1080p']
test_channels.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_start_commercial():
    channel_id = example_channel['_id']
    response = {
        'duration': 30,
        'message': '',
        'retryafter': 480
    }
    responses.add(responses.POST,
                  '%schannels/%s/commercial' % (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']
test_channels.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 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']
test_channels.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_get_community():
    channel_id = example_channel['_id']
    responses.add(responses.GET,
                  '%schannels/%s/community' % (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']
test_streams.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_get_stream_by_user():
    channel_id = 7236692
    responses.add(responses.GET,
                  '%sstreams/%s' % (BASE_URL, channel_id),
                  body=json.dumps(example_stream_response),
                  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 isinstance(stream, Stream)
    assert stream.id == example_stream_response['stream']['_id']
    assert stream.game == example_stream_response['stream']['game']

    assert isinstance(stream.channel, Channel)
    assert stream.channel.id == example_stream_response['stream']['channel']['_id']
    assert stream.channel.name == example_stream_response['stream']['channel']['name']
test_streams.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_get_live_streams():
    responses.add(responses.GET,
                  '%sstreams' % BASE_URL,
                  body=json.dumps(example_streams_response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    streams = client.streams.get_live_streams()

    assert len(responses.calls) == 1
    assert len(streams) == 1
    stream = streams[0]
    assert isinstance(stream, Stream)
    assert stream.id == example_stream_response['stream']['_id']
    assert stream.game == example_stream_response['stream']['game']

    assert isinstance(stream.channel, Channel)
    assert stream.channel.id == example_stream_response['stream']['channel']['_id']
    assert stream.channel.name == example_stream_response['stream']['channel']['name']
test_streams.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_get_summary():
    response = {
        'channels': 1417,
        'viewers': 19973
    }
    responses.add(responses.GET,
                  '%sstreams/summary' % 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']
test_streams.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_get_featured():
    responses.add(responses.GET,
                  '%sstreams/featured' % BASE_URL,
                  body=json.dumps(example_featured_response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    featured = client.streams.get_featured()

    assert len(responses.calls) == 1
    assert len(featured) == 1
    feature = featured[0]
    assert isinstance(feature, Featured)
    assert feature.title == example_featured_response['featured'][0]['title']
    stream = feature.stream
    assert isinstance(stream, Stream)
    assert stream.id == example_stream_response['stream']['_id']
    assert stream.game == example_stream_response['stream']['game']
test_streams.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_get_followed():
    responses.add(responses.GET,
                  '%sstreams/followed' % BASE_URL,
                  body=json.dumps(example_streams_response),
                  status=200,
                  content_type='application/json')

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

    streams = client.streams.get_followed()

    assert len(responses.calls) == 1
    assert len(streams) == 1
    stream = streams[0]
    assert isinstance(stream, Stream)
    assert stream.id == example_stream_response['stream']['_id']
    assert stream.game == example_stream_response['stream']['game']

    assert isinstance(stream.channel, Channel)
    assert stream.channel.id == example_stream_response['stream']['channel']['_id']
    assert stream.channel.name == example_stream_response['stream']['channel']['name']
test_streams.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_get_streams_in_community():
    community_id = 'abcd'
    responses.add(responses.GET,
                  '%sstreams' % (BASE_URL),
                  body=json.dumps(example_streams_response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    streams = client.streams.get_streams_in_community(community_id)

    assert len(responses.calls) == 1
    assert len(streams) == 1
    stream = streams[0]
    assert isinstance(stream, Stream)
    assert stream.id == example_stream_response['stream']['_id']
    assert stream.game == example_stream_response['stream']['game']

    assert isinstance(stream.channel, Channel)
    assert stream.channel.id == example_stream_response['stream']['channel']['_id']
    assert stream.channel.name == example_stream_response['stream']['channel']['name']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_get_by_id():
    user_id = 1234
    responses.add(responses.GET,
                  '%susers/%s' % (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']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_get_emotes():
    user_id = 1234
    response = {
        'emoticon_sets': {
            '17937': [
                {
                    'code': 'Kappa',
                    'id': 25
                },
            ],
        }
    }
    responses.add(responses.GET,
                  '%susers/%s/emotes' % (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']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_check_subscribed_to_channel():
    user_id = 1234
    channel_id = 12345
    response = {
        '_id': 'c660cb408bc3b542f5bdbba52f3e638e652756b4',
        'created_at': '2016-12-12T15:52:52Z',
        'channel': example_channel,
    }
    responses.add(responses.GET,
                  '%susers/%s/subscriptions/%s' % (BASE_URL, user_id, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    subscription = client.users.check_subscribed_to_channel(user_id, channel_id)

    assert len(responses.calls) == 1
    assert isinstance(subscription, Subscription)
    assert subscription.id == response['_id']
    assert isinstance(subscription.channel, Channel)
    assert subscription.channel.id == example_channel['_id']
    assert subscription.channel.name == example_channel['name']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_get_follows():
    user_id = 1234
    response = {
        '_total': 27,
        'follows': [example_follow]
    }
    responses.add(responses.GET,
                  '%susers/%s/follows/channels' % (BASE_URL, user_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    follows = client.users.get_follows(user_id)

    assert len(responses.calls) == 1
    assert len(follows) == 1
    follow = follows[0]
    assert isinstance(follow, Follow)
    assert follow.notifications == example_follow['notifications']
    assert isinstance(follow.channel, Channel)
    assert follow.channel.id == example_channel['_id']
    assert follow.channel.name == example_channel['name']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_check_follows_channel():
    user_id = 1234
    channel_id = 12345
    responses.add(responses.GET,
                  '%susers/%s/follows/channels/%s' % (BASE_URL, user_id, channel_id),
                  body=json.dumps(example_follow),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    follow = client.users.check_follows_channel(user_id, channel_id)

    assert len(responses.calls) == 1
    assert isinstance(follow, Follow)
    assert follow.notifications == example_follow['notifications']
    assert isinstance(follow.channel, Channel)
    assert follow.channel.id == example_channel['_id']
    assert follow.channel.name == example_channel['name']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_get_user_block_list():
    user_id = 1234
    response = {
        '_total': 4,
        'blocks': [example_block]
    }
    responses.add(responses.GET,
                  '%susers/%s/blocks' % (BASE_URL, user_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    block_list = client.users.get_user_block_list(user_id)

    assert len(responses.calls) == 1
    assert len(block_list) == 1
    block = block_list[0]
    assert isinstance(block, UserBlock)
    assert block.id == example_block['_id']
    assert isinstance(block.user, User)
    assert block.user.id == example_user['_id']
    assert block.user.name == example_user['name']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_block_user():
    user_id = 1234
    blocked_user_id = 12345
    responses.add(responses.PUT,
                  '%susers/%s/blocks/%s' % (BASE_URL, user_id, blocked_user_id),
                  body=json.dumps(example_block),
                  status=200,
                  content_type='application/json')

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

    block = client.users.block_user(user_id, blocked_user_id)

    assert len(responses.calls) == 1
    assert isinstance(block, UserBlock)
    assert block.id == example_block['_id']
    assert isinstance(block.user, User)
    assert block.user.id == example_user['_id']
    assert block.user.name == example_user['name']
test_users.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_translate_usernames_to_ids():
    response = {
        'users': [example_user]
    }
    responses.add(responses.GET,
                  '%susers' % (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']
test_communities.py 文件源码 项目:python-twitch-client 作者: tsifrer 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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']


问题


面经


文章

微信
公众号

扫码关注公众号