__author__ = "Gina Häußge " __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2021 The OctoPrint Project - Released under terms of the AGPLv3 License" import unittest from unittest import mock from octoprint.util import TemporaryDirectory RSS_EXAMPLE = """ RSS Title This is an example of an RSS feed https://www.example.com/main.html 2020 Example.com All rights reserved Mon, 06 Sep 2010 00:01:00 +0000 Sun, 06 Sep 2009 16:20:00 +0000 1800 Example entry Here is some text containing an interesting description. https://www.example.com/blog/post/1 7bd204c6-1655-4c27-aeee-53f933c5395f Sun, 06 Sep 2009 16:20:00 +0000 """ class TestAnnouncements(unittest.TestCase): def test_caches(self): from octoprint.plugins.announcements import AnnouncementPlugin plugin = AnnouncementPlugin() plugin._logger = mock.MagicMock() with TemporaryDirectory() as data_folder: plugin._data_folder = data_folder with mock.patch("requests.get") as mock_get: mock_get.return_value = mock.MagicMock(status_code=200) mock_get.return_value.text = RSS_EXAMPLE network_response = plugin._get_channel_data_from_network( "test", {"url": "https://example.com/feed.xml"} ) cache_response = plugin._get_channel_data_from_cache("test", {"ttl": 1000}) self.maxDiff = 100000 self.assertDictEqual(network_response, cache_response)