def test_download(self): """Test Feed `download` method.""" feed_name = 'modified' json_dir = tempfile.mkdtemp(dir=_TEMP_DATA_DIR) # feed does not exist yet json_feed = JSONFeed(feed_name, data_dir=json_dir) self.assertIsInstance(json_feed, JSONFeed) # nothing has been downloaded yet self.assertTrue(not os.listdir(json_dir)) # feed is not ready self.assertFalse(json_feed.is_ready()) _EVENT_LOOP.run_until_complete(json_feed.download()) self.assertTrue(json_feed.filename in os.listdir(json_dir)) self.assertTrue(json_feed.is_downloaded()) # feed should not contain any data atm self.assertIsNone(json_feed.data) # load the data _EVENT_LOOP.run_until_complete(json_feed.load()) # should be json dict self.assertIsInstance(json_feed.data, dict)
def test_flush(self): """Test Feed `flush` method.""" feed_name = 'sample' json_feed = JSONFeed(feed_name, data_dir=_TEST_DATA_DIR) # load the data _EVENT_LOOP.run_until_complete(json_feed.load()) # feed should contain data already self.assertTrue(json_feed.data) process = psutil.Process() memory_usage = process.memory_info().rss # flush the data json_feed.flush() self.assertIsNone(json_feed.data) # sanity check -- lower memory usage self.assertLessEqual(process.memory_info().rss, memory_usage)
def test_load(self): """Test Feed `load` methods.""" # test load existing feed_name = 'sample' json_feed = JSONFeed(feed_name, data_dir=_TEST_DATA_DIR) _EVENT_LOOP.run_until_complete(json_feed.load()) self.assertIsInstance(json_feed, JSONFeed) self.assertIsInstance(json_feed.data, dict) # --- # test download-load json_dir = tempfile.mkdtemp(dir=_TEMP_DATA_DIR) feed_name = 'modified' json_feed = JSONFeed(feed_name, data_dir=json_dir) _EVENT_LOOP.run_until_complete(json_feed.download(load=True)) self.assertIsInstance(json_feed, JSONFeed) self.assertIsInstance(json_feed.data, dict)