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_not_subscribed(self): # subscribe a client to a topic client = MagicMock() p = PubSubManager() p.subscriptions["topic"] = set([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")
def test_publish_subscribed(self): # subscribe a client to a topic client = MagicMock() p = PubSubManager() p.subscriptions["topic"] = set([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")