def test_publish_one_not_existing(self, find): client = MagicMock() PubSubManager().publish_one(client, "topic") # make sure the client didn't get called self.assertFalse(client.send.called)
def test_unsubscribe_not_existing(self): p = PubSubManager() p.unsubscribe("client", "topic") # check that the topic wasn't created self.assertTrue("topic" not in p.subscriptions)
def test_unsubscribe_existing_last(self): p = PubSubManager() p.subscriptions["topic"] = {"client"} p.unsubscribe("client", "topic") # check that the topic was garbage collected self.assertTrue("topic" not in p.subscriptions)
def test_unsubscribe_existing(self): p = PubSubManager() p.subscriptions["topic"] = {"client", "other client"} p.unsubscribe("client", "topic") # check that we are not subbed anymore self.assertTrue("client" not in p.subscriptions["topic"])
def test_unsubscribe_all(self, unsubscribe): p = PubSubManager() p.subscriptions["topic"] = {"client"} p.subscriptions["topic 2"] = {"client"} p.unsubscribe_all("client") # check the number of calls # TODO: check the actual arguments of each call self.assertEqual(unsubscribe.call_count, 2)
def test_subscribe_new(self): p = PubSubManager() p.subscribe("client", "topic") # check that the topic was created self.assertEqual(len(p.subscriptions.keys()), 1) # check that we are subbed self.assertTrue("client" in p.subscriptions["topic"]) self.assertTrue(len(p.subscriptions["topic"]), 1)
def test_subscribe_existing(self): p = PubSubManager() p.subscriptions["topic"] = {"other client"} p.subscribe("client", "topic") # check that the topic was reused self.assertEqual(len(p.subscriptions.keys()), 1) # check that we are subbed self.assertTrue("client" in p.subscriptions["topic"]) self.assertTrue(len(p.subscriptions["topic"]), 2)
def test_publish_one_existing(self): client = MagicMock() topic = MagicMock() topic.payload = MagicMock(return_value="payload") with patch('twitchcancer.api.pubsubtopic.PubSubTopic.find', return_value=topic): PubSubManager().publish_one(client, "topic") # make sure the client got data client.send.assert_called_once_with("topic", "payload")
def test_publish_not_subscribed(self): # subscribe a client to a topic client = MagicMock() p = PubSubManager() p.subscriptions["topic"] = {client} # publish data for another topic topic = MagicMock() topic.match = MagicMock(return_value=False) p.publish(topic) # make sure the client didn't get called self.assertFalse(client.send.called)
def test_publish_subscribed(self): # subscribe a client to a topic client = MagicMock() p = PubSubManager() p.subscriptions["topic"] = {client} # publish data for that topic topic = MagicMock() topic.payload = MagicMock(return_value="payload") p.publish(topic) # make sure the client got data client.send.assert_called_once_with("topic", "payload")