Python responses 模块,calls() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用responses.calls()

项目:flash_services    作者:textbook    | 项目源码 | 文件源码
def test_get_velocity_success(service):
    responses.add(
        responses.GET,
        'https://www.pivotaltracker.com/services/v5/projects/123/iterations'
        '/456?fields=%3Adefault%2Cvelocity%2Cstories',
        json={
            'velocity': 10,
            'stories': [
                {'current_state': 'foo', 'estimate': 5},
                {'current_state': 'foo'},
            ],
        }
    )

    result = service.details(456)

    assert result == {'velocity': 10, 'stories': {'foo': 5}}
    assert responses.calls[0].request.headers['X-TrackerToken'] == 'foobar'
项目:flash_services    作者:textbook    | 项目源码 | 文件源码
def test_update_success(debug, service):
    service.current_iteration = 1
    service.project_version = 2
    service._cached = {'foo': 'bar'}
    responses.add(
        responses.GET,
        'https://www.pivotaltracker.com/services/v5/projects/123',
        json={'foo': 'bar', 'current_iteration_number': 0},
        adding_headers={'X-Tracker-Project-Version': '1'},
    )

    result = service.update()

    debug.assert_called_once_with('fetching Tracker project data')
    assert result == {'foo': 'bar'}
    assert responses.calls[0].request.headers['X-TrackerToken'] == 'foobar'
项目:flash_services    作者:textbook    | 项目源码 | 文件源码
def test_update_success(debug, service):
    responses.add(
        responses.GET,
        'https://api.github.com/repos/foo/bar/commits?access_token=foobar',
        json=[{'commit': {
            'author': {'name': 'alice'},
            'committer': {'name': 'bob', 'date': TWO_DAYS_AGO},
            'message': 'commit message',
        }}],
    )

    result = service.update()

    debug.assert_called_once_with('fetching GitHub project data')
    assert result == {'commits': [{
        'message': 'commit message',
        'author': 'alice [bob]',
        'committed': 'two days ago'
    }], 'name': 'foo/bar'}
    assert responses.calls[0].request.headers['User-Agent'] == 'bar'
项目:flash_services    作者:textbook    | 项目源码 | 文件源码
def test_update_enterprise_success(debug):
    responses.add(
        responses.GET,
        'http://dummy.url/repos/foo/bar/commits?access_token=foobar',
        json=[{'commit': {
            'author': {'name': 'alice'},
            'committer': {'name': 'bob', 'date': TWO_DAYS_AGO},
            'message': 'commit message',
        }}],
    )

    service = GitHubEnterprise(api_token='foobar', account='foo', repo='bar',
                               root='http://dummy.url')

    result = service.update()

    debug.assert_called_once_with('fetching GitHub project data')
    assert result == {'commits': [{
        'message': 'commit message',
        'author': 'alice [bob]',
        'committed': 'two days ago'
    }], 'name': 'foo/bar'}
    assert responses.calls[0].request.headers['User-Agent'] == 'bar'
项目:travieso    作者:wizeline    | 项目源码 | 文件源码
def test_notify_gihub(faker):
    repo = {'owner_name': faker.domain_word(), 'name': faker.domain_word()}
    commit = uuid4().hex
    state = random.choice(['success', 'failure', 'error', 'pending']),
    job_task = faker.domain_word()
    job_id = random.randint(1, 10000)

    request_json = {
        'state': state,
        'target_url': 'https://travis-ci/{0}/{1}/jobs/{2}'.format(repo['owner_name'], repo['name'], job_id),
        'description': get_description_from_task(job_task),
        'context': job_task
    }

    responses.add(
        responses.POST,
        'https://api.github.com/repos/{0}/{1}/statuses/{2}'.format(repo['owner_name'], repo['name'], commit),
        json=request_json)

    notify_github(repo, commit, state, job_task, job_id)

    assert len(responses.calls) == 1
项目:allennlp    作者:allenai    | 项目源码 | 文件源码
def test_cached_path(self):
        url = 'http://fake.datastore.com/glove.txt.gz'
        set_up_glove(url, self.glove_bytes)

        # non-existent file
        with pytest.raises(FileNotFoundError):
            filename = cached_path("tests/fixtures/does_not_exist/fake_file.tar.gz")

        # unparsable URI
        with pytest.raises(ValueError):
            filename = cached_path("fakescheme://path/to/fake/file.tar.gz")

        # existing file as path
        assert cached_path(self.glove_file) == self.glove_file

        # caches urls
        filename = cached_path(url, cache_dir=self.TEST_DIR)

        assert len(responses.calls) == 2
        assert filename == os.path.join(self.TEST_DIR, url_to_filename(url, etag="0"))

        with open(filename, 'rb') as cached_file:
            assert cached_file.read() == self.glove_bytes
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_badges_by_channel():
    channel_id = 7236692
    response = {
        'admin': {
            'alpha': 'https://static-cdn.jtvnw.net/chat-badges/admin-alpha.png',
            'image': 'https://static-cdn.jtvnw.net/chat-badges/admin.png',
            'svg': 'https://static-cdn.jtvnw.net/chat-badges/admin.svg'
        }
    }
    responses.add(responses.GET,
                  '%schat/%s/badges' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    badges = client.chat.get_badges_by_channel(channel_id)

    assert len(responses.calls) == 1
    assert isinstance(badges, dict)
    assert badges['admin'] == response['admin']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_all_emoticons():
    response = {
        'emoticons': [example_emote]
    }
    responses.add(responses.GET,
                  '%schat/emoticons' % 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
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_metadata():
    collection_id = 'abcd'
    responses.add(responses.GET,
                  '%scollections/%s' % (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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get():
    collection_id = 'abcd'
    response = {
        '_id': 'myIbIFkZphQSbQ',
        'items': [example_item]
    }
    responses.add(responses.GET,
                  '%scollections/%s/items' % (BASE_URL, collection_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    items = client.collections.get(collection_id)

    assert len(responses.calls) == 1
    assert len(items) == 1
    item = items[0]
    assert isinstance(item, Item)
    assert item.id == example_item['_id']
    assert item.title == example_item['title']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_create():
    channel_id = 'abcd'
    responses.add(responses.POST,
                  '%schannels/%s/collections' % (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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_add_item():
    collection_id = 'abcd'
    responses.add(responses.PUT,
                  '%scollections/%s/items' % (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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_streams():
    response = {
        '_total': 2147,
        'streams': [example_stream]
    }
    responses.add(responses.GET,
                  '%ssearch/streams' % BASE_URL,
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

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

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

    assert isinstance(stream.channel, Channel)
    assert stream.channel.id == example_channel['_id']
    assert stream.channel.name == example_channel['name']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_posts():
    channel_id = '1234'
    response = {
        '_cursor': '1479487861147094000',
        '_topic': 'feeds.channel.44322889',
        'posts': [example_post]
    }
    responses.add(responses.GET,
                  '%sfeed/%s/posts' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    posts = client.channel_feed.get_posts(channel_id)

    assert len(responses.calls) == 1
    assert len(posts) == 1
    post = posts[0]
    assert isinstance(post, Post)
    assert post.id == example_post['id']
    assert post.body == example_post['body']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_create_reaction_to_post():
    channel_id = '1234'
    post_id = example_post['id']
    response = {
        'id': '24989127',
        'emote_id': '25',
        'user': {},
        'created_at': '2016-11-29T15:51:12Z',
    }
    responses.add(responses.POST,
                  '%sfeed/%s/posts/%s/reactions' % (BASE_URL, channel_id, post_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    response = client.channel_feed.create_reaction_to_post(
        channel_id, post_id, response['emote_id'])

    assert len(responses.calls) == 1
    assert response['id']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_post_comments():
    channel_id = '1234'
    post_id = example_post['id']
    response = {
        '_cursor': '1480651694954867000',
        '_total': 1,
        'comments': [example_comment]
    }
    responses.add(responses.GET,
                  '%sfeed/%s/posts/%s/comments' % (BASE_URL, channel_id, post_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    comments = client.channel_feed.get_post_comments(channel_id, post_id)

    assert len(responses.calls) == 1
    assert len(comments) == 1
    comment = comments[0]
    assert isinstance(comment, Comment)
    assert comment.id == example_comment['id']
    assert comment.body == example_comment['body']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_delete_post_comment():
    channel_id = '1234'
    post_id = example_post['id']
    comment_id = example_comment['id']
    responses.add(responses.DELETE,
                  '%sfeed/%s/posts/%s/comments/%s' % (BASE_URL, channel_id, post_id, comment_id),
                  body=json.dumps(example_comment),
                  status=200,
                  content_type='application/json')

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

    comment = client.channel_feed.delete_post_comment(channel_id, post_id, comment_id)

    assert len(responses.calls) == 1
    assert isinstance(comment, Comment)
    assert comment.id == example_comment['id']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_create_reaction_to_comment():
    channel_id = '1234'
    post_id = example_post['id']
    comment_id = example_comment['id']
    body = {
        'created_at': '2016-12-02T04:26:47Z',
        'emote_id': '1',
        'id': '1341393b-e872-4554-9f6f-acd5f8b669fc',
        'user': {}
    }
    url = '%sfeed/%s/posts/%s/comments/%s/reactions' % (BASE_URL, channel_id, post_id, comment_id)
    responses.add(responses.POST,
                  url,
                  body=json.dumps(body),
                  status=200,
                  content_type='application/json')

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

    response = client.channel_feed.create_reaction_to_comment(channel_id, post_id, comment_id, '1')

    assert len(responses.calls) == 1
    assert response['id']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_delete_reaction_to_comment():
    channel_id = '1234'
    post_id = example_post['id']
    comment_id = example_comment['id']
    body = {
        'deleted': True
    }
    url = '%sfeed/%s/posts/%s/comments/%s/reactions' % (BASE_URL, channel_id, post_id, comment_id)
    responses.add(responses.DELETE,
                  url,
                  body=json.dumps(body),
                  status=200,
                  content_type='application/json')

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

    response = client.channel_feed.delete_reaction_to_comment(channel_id, post_id, comment_id, '1')

    assert len(responses.calls) == 1
    assert response['deleted']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_top():
    responses.add(responses.GET,
                  '%sgames/top' % 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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_update():
    channel_id = example_channel['_id']
    responses.add(responses.PUT,
                  '%schannels/%s' % (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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_editors():
    channel_id = example_channel['_id']
    response = {
        'users': [example_user]
    }
    responses.add(responses.GET,
                  '%schannels/%s/editors' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

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

    users = client.channels.get_editors(channel_id)

    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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_followers():
    channel_id = example_channel['_id']
    response = {
        '_cursor': '1481675542963907000',
        '_total': 41,
        'follows': [example_follower]
    }
    responses.add(responses.GET,
                  '%schannels/%s/follows' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    followers = client.channels.get_followers(channel_id)

    assert len(responses.calls) == 1
    assert len(followers) == 1
    follow = followers[0]
    assert isinstance(follow, Follow)
    assert follow.notifications == example_follower['notifications']
    assert isinstance(follow.user, User)
    assert follow.user.id == example_user['_id']
    assert follow.user.name == example_user['name']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
def test_get_teams():
    channel_id = example_channel['_id']
    response = {
        'teams': [example_team]
    }
    responses.add(responses.GET,
                  '%schannels/%s/teams' % (BASE_URL, channel_id),
                  body=json.dumps(response),
                  status=200,
                  content_type='application/json')

    client = TwitchClient('client id')

    teams = client.channels.get_teams(channel_id)

    assert len(responses.calls) == 1
    assert len(teams) == 1
    team = teams[0]
    assert isinstance(team, Team)
    assert team.id == example_team['_id']
    assert team.name == example_team['name']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']
项目:python-twitch-client    作者:tsifrer    | 项目源码 | 文件源码
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']