def test_filter_streams(self): sm = streams.StreamManager(self.file_path, "token", use_cache=False) sm.add_stream("twitch.tv/name") sm.game_filter = re.compile(r"asdf.*") data = { "streams": [{ "channel": { "name": "name", "status": "title" }, "game": "ghjkgame" }] } with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_online_streams() self.assertEqual(set(), ret) data = { "streams": [{ "channel": { "name": "name", "status": "title" }, "game": "asdfgame" }] } with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_online_streams() self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual("name", s.user) self.assertEqual("title", s.title)
def test_new_online_stream(self): sm = streams.StreamManager(self.file_path, "token") sm.add_stream("twitch.tv/name1") sm.add_stream("twitch.tv/name2") data = { "streams": [{ "channel": { "name": "name1", "status": "status1" } }] } with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret) data["streams"].append( {"channel": { "name": "name2", "status": "status2" }}) with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual("name2", s.user) self.assertEqual("status2", s.title) ret = sm.get_new_online_streams() self.assertEqual(0, len(ret))
def test_filter_streams(self): sm = streams.StreamManager(self.file_path, 'token', use_cache=False) sm.add_stream('twitch.tv/name') sm.game_filter = re.compile(r'asdf.*') data = { 'streams': [{ 'channel': { 'name': 'name', 'status': 'title' }, 'game': 'ghjkgame' }] } with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_online_streams() self.assertEqual(set(), ret) data = { 'streams': [{ 'channel': { 'name': 'name', 'status': 'title' }, 'game': 'asdfgame' }] } with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_online_streams() self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual('name', s.user) self.assertEqual('title', s.title)
def test_subscription_persists_but_is_not_public_when_stream_removed(self): sm = streams.StreamManager(self.file_path, "token") sm.add_stream("twitch.tv/asdf") sm.add_subscriber("host.com", "asdf") sm.del_stream("asdf") self.assertEqual(["twitch.tv/asdf"], sm.subs["host.com"]) self.assertEqual([], sm.get_subscriptions("host.com"))
def test_subscription_persists_but_is_not_public_when_stream_removed(self): sm = streams.StreamManager(self.file_path, 'token') sm.add_stream('twitch.tv/asdf') sm.add_subscriber('host.com', 'asdf') sm.del_stream('asdf') self.assertEqual(['twitch.tv/asdf'], sm.subs['host.com']) self.assertEqual([], sm.get_subscriptions('host.com'))
def test_new_online_stream(self): sm = streams.StreamManager(self.file_path, 'token') sm.add_stream('twitch.tv/name1') sm.add_stream('twitch.tv/name2') data = { 'streams': [{ 'channel': { 'name': 'name1', 'status': 'status1' } }] } with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret) data['streams'].append( {'channel': { 'name': 'name2', 'status': 'status2' }}) with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual('name2', s.user) self.assertEqual('status2', s.title) ret = sm.get_new_online_streams() self.assertEqual(0, len(ret))
def test_can_subscribe_to_stream(self): sm = streams.StreamManager(self.file_path) sm.add_stream('twitch.tv/asdf') self.assertEqual(None, sm.get_subscriptions('host.com')) sm.add_subscriber('host.com', 'asdf') self.assertEqual(['twitch.tv/asdf'], sm.get_subscriptions('host.com')) sm.del_subscriber('host.com', 'asdf') self.assertEqual([], sm.get_subscriptions('host.com'))
def test_can_subscribe_to_stream(self): sm = streams.StreamManager(self.file_path, "token") sm.add_stream("twitch.tv/asdf") self.assertEqual(None, sm.get_subscriptions("host.com")) sm.add_subscriber("host.com", "asdf") self.assertEqual(["twitch.tv/asdf"], sm.get_subscriptions("host.com")) sm.del_subscriber("host.com", "asdf") self.assertEqual([], sm.get_subscriptions("host.com"))
def test_can_add_and_remove_streams(self): sm = streams.StreamManager(self.file_path, "token") with self.assertRaises(streams.error.StreamNotFoundException): sm.find_stream("asdf") sm.add_stream("twitch.tv/asdf") self.assertEqual("twitch.tv/asdf", sm.find_stream("asdf")) sm.del_stream("asdf") with self.assertRaises(streams.error.StreamNotFoundException): sm.find_stream("asdf")
def test_can_add_and_remove_streams(self): sm = streams.StreamManager(self.file_path) with self.assertRaises(streams.StreamNotFoundException): sm.find_stream('asdf') sm.add_stream('twitch.tv/asdf') self.assertEqual('twitch.tv/asdf', sm.find_stream('asdf')) sm.del_stream('asdf') with self.assertRaises(streams.StreamNotFoundException): sm.find_stream('asdf')
def test_rebroadcast_is_not_new_stream(self): sm = streams.StreamManager(self.file_path) sm.add_stream('twitch.tv/name') data = {'streams': []} with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret) data['streams'].append({'channel': {'name': 'name', 'status': 'rebroadcast'}}) with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret)
def test_all_online_streams(self): sm = streams.StreamManager(self.file_path) sm.add_stream('twitch.tv/name') data = {'streams': [{'channel': {'name': 'name', 'status': 'status'}}]} with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_online_streams() mf.assert_called_with(['name']) self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual('name', s.user) self.assertEqual('status', s.title)
def test_all_online_streams(self): sm = streams.StreamManager(self.file_path, "token") sm.add_stream("twitch.tv/name") data = {"streams": [{"channel": {"name": "name", "status": "status"}}]} with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_online_streams() mf.assert_called_with(["name"], "token") self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual("name", s.user) self.assertEqual("status", s.title)
def test_rebroadcast_namechange_is_new_stream(self): sm = streams.StreamManager(self.file_path) sm.add_stream('twitch.tv/name') data = {'streams': [{'channel': {'name': 'name', 'status': 'rebroadcast'}}]} with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret) data['streams'].append({'channel': {'name': 'name', 'status': 'live'}}) with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual(1, len(ret)) s = ret.pop() self.assertTrue(isinstance(s, streams.Stream)) self.assertEqual('name', s.user) self.assertEqual('live', s.title)
def test_rebroadcast_is_not_new_stream(self): sm = streams.StreamManager(self.file_path, "token") sm.add_stream("twitch.tv/name") data = {"streams": []} with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret) data["streams"].append( {"channel": { "name": "name", "status": "rebroadcast" }}) with mock.patch(twitch_f, return_value=data) as mf: ret = sm.get_new_online_streams() self.assertEqual([], ret)
def test_subscription_persists_when_stream_removed(self): sm = streams.StreamManager(self.file_path) sm.add_stream('twitch.tv/asdf') sm.add_subscriber('host.com', 'asdf') sm.del_stream('asdf') self.assertEqual(['twitch.tv/asdf'], sm.get_subscriptions('host.com'))
def test_streams_are_persisted(self): sm = streams.StreamManager(self.file_path) sm.add_stream('twitch.tv/asdf') sm = streams.StreamManager(self.file_path) self.assertEqual('twitch.tv/asdf', sm.find_stream('asdf'))
def test_streams_are_persisted(self): sm = streams.StreamManager(self.file_path, "token") sm.add_stream("twitch.tv/asdf") sm = streams.StreamManager(self.file_path, "token") self.assertEqual("twitch.tv/asdf", sm.find_stream("asdf"))