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类add()的实例源码
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']
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']
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']
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']
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']
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']
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']
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']
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']
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']
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']
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']
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']