예제 #1
0
    def test_neq(self):
        foo1 = PubSubTopic("foo", None, None)
        foo2 = PubSubTopic("foo", None, None)
        bar = PubSubTopic("bar", None, None)

        self.assertFalse(foo1 != foo2)
        self.assertTrue(foo1 != bar)
예제 #2
0
    def test_init(self):
        topic = PubSubTopic(name="foo", callback="bar", sleep="baz")

        self.assertEqual(topic.name, "foo")
        self.assertEqual(topic.callback, "bar")
        self.assertEqual(topic.sleep, "baz")
        self.assertEqual(topic.data, None)
예제 #3
0
    def test_payload_no_cache_no_data(self):
        callback = MagicMock(return_value="computed")
        topic = PubSubTopic("no_cache_no_data", callback, None)

        payload = topic.payload(False)

        callback.assert_called_once_with()
        self.assertEqual(payload, "computed")
예제 #4
0
    def test_payload_with_cache_with_fresh_data(self):
        callback = MagicMock(return_value="computed")
        topic = PubSubTopic("with_cache_with_fresh_data", callback, None)

        topic.data = self.cached_data
        payload = topic.payload(True)

        self.assertFalse(callback.called)
        self.assertEqual(payload, "cached")
예제 #5
0
    def test_payload_with_cache_with_old_data(self):
        callback = MagicMock(return_value="computed")
        topic = PubSubTopic("with_cache_with_old_data", callback, None)

        topic.data = self.cached_data
        topic.data["date"] = datetime.datetime.now() - datetime.timedelta(seconds=62)

        payload = topic.payload(True)

        self.assertEqual(payload, "computed")
예제 #6
0
async def create_publishers():
    # setup storage
    storage = Storage()

    # list of topics clients can subscribe to
    topics = [
        PubSubTopic('twitchcancer.live', storage.cancer, 1),
        PubSubVariableTopic('twitchcancer.leaderboards.*',
                            storage.leaderboards, 60),
        PubSubVariableTopic('twitchcancer.leaderboard.*', storage.leaderboard,
                            60),
        PubSubTopic('twitchcancer.status', storage.status, 3),
        PubSubVariableTopic('twitchcancer.channel.*', storage.channel, 60),
    ]

    # add publisher tasks to the loop
    tasks = [publish(topic) for topic in topics]
    logger.info('added publisher topics: %s', ', '.join(map(str, topics)))

    await asyncio.gather(*tasks)
예제 #7
0
    def test_exists(self):
        topic = PubSubTopic("foo", None, None)

        self.assertEqual(PubSubTopic.find("foo"), topic)
예제 #8
0
    def test_hash(self):
        foo = PubSubTopic("foo", None, None)

        self.assertEqual(hash(foo), hash(foo.name))
예제 #9
0
    def test_str(self):
        topic = PubSubTopic("foo", None, None)

        self.assertEqual(str(topic), "foo")
예제 #10
0
    def test_duplicate_instances(self):
        PubSubTopic("foo", "bar", None)
        PubSubTopic("foo", "baz", None)

        self.assertEqual(len(PubSubTopic.instances), 1)
예제 #11
0
    def test_instances(self):
        topic = PubSubTopic("foo", None, None)

        self.assertEqual(len(PubSubTopic.instances), 1)
        self.assertEqual(PubSubTopic.instances.pop(), topic)
예제 #12
0
    def test_match(self):
        topic = PubSubTopic("foo", None, None)

        self.assertTrue(topic.match("foo"))
        self.assertFalse(topic.match("bar"))