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")
  def test_payload_with_cache_no_data(self):
    callback = MagicMock(return_value="computed")
    topic = PubSubTopic("with_cache_no_data", callback, None)

    topic.data = None
    payload = topic.payload(True)

    callback.assert_called_once_with()
    self.assertEqual(payload, "computed")
    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")
    def test_payload_with_cache_no_data(self):
        callback = MagicMock(return_value="computed")
        topic = PubSubTopic("with_cache_no_data", callback, None)

        topic.data = None
        payload = topic.payload(True)

        callback.assert_called_once_with()
        self.assertEqual(payload, "computed")
  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")
    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")