def subject(self, channel, hosts=None, disable=False): with requests_mock.Mocker() as mock: mock.get("https://api.twitch.tv/kraken/users?login=foo", json={"users": [{ "_id": 1 }]}) if hosts is None: mock.get("https://tmi.twitch.tv/hosts", json={}) else: mock.get("https://tmi.twitch.tv/hosts", [{ "json": { "hosts": [ dict(host_id=host_id, target_id=target_id, target_login=target_login, target_display_name=target_display_name) ] } } for host_id, target_id, target_login, target_display_name in hosts]) session = Streamlink() Twitch.bind(session, "tests.plugins.test_twitch") plugin = Twitch("https://twitch.tv/{0}".format(channel)) plugin.options.set("disable-hosting", disable) res = plugin._switch_to_hosted_channel() return res, plugin.channel, plugin._channel_id, plugin.author
def subject(channel, hosts=None, disable=False): with requests_mock.Mocker() as mock: mock.register_uri(requests_mock.ANY, requests_mock.ANY, exc=requests_mock.exceptions.InvalidRequest) if hosts is None: mock.post("https://gql.twitch.tv/gql", json={}) else: mock.post("https://gql.twitch.tv/gql", response_list=[{ "json": { "data": { "user": { "id": host[0], "hosting": None if not host[1:3] else { "login": host[1], "displayName": host[2] } } } } } for host in hosts]) session = Streamlink() Twitch.bind(session, "tests.plugins.test_twitch") plugin = Twitch("https://twitch.tv/{0}".format(channel)) plugin.options.set("disable-hosting", disable) res = plugin._switch_to_hosted_channel() return res, plugin.channel, plugin.author