예제 #1
0
    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)
예제 #2
0
    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))
예제 #3
0
    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)
예제 #4
0
 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"))
예제 #5
0
 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'))
예제 #6
0
    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))
예제 #7
0
	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'))
예제 #8
0
 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"))
예제 #9
0
 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")
예제 #10
0
	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')
예제 #11
0
	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)
예제 #12
0
	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)
예제 #13
0
    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)
예제 #14
0
	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)
예제 #15
0
    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)
예제 #16
0
	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'))
예제 #17
0
	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'))
예제 #18
0
 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"))