예제 #1
0
    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)
예제 #2
0
    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)