Exemplo n.º 1
0
    def test_fetch(self):
        """Test TestJSONFeedMetadata `fetch` method."""
        # existing
        feed_name = 'sample'
        meta = JSONFeedMetadata(feed_name=feed_name, data_dir=_TEST_DATA_DIR)

        future = asyncio.ensure_future(meta.fetch())
        metadata: JSONFeedMetadata = _EVENT_LOOP.run_until_complete(future)
        data: str = metadata.data

        self.assertIsInstance(data, str)
        self.assertTrue(data)

        feed_name = 'modified'
        meta_temp_dir = tempfile.mkdtemp(dir=_TEMP_DATA_DIR)

        # non-existing metadata
        meta = JSONFeedMetadata(feed_name=feed_name, data_dir=meta_temp_dir)

        future = asyncio.ensure_future(meta.fetch())
        metadata: JSONFeedMetadata = _EVENT_LOOP.run_until_complete(future)
        data: str = metadata.data

        self.assertIsInstance(data, str)
        self.assertTrue(data)
Exemplo n.º 2
0
    def test_update(self):
        """Test TestJSONFeedMetadata `update` method."""
        feed_name = 'modified'
        meta_temp_dir = tempfile.mkdtemp(dir=_TEMP_DATA_DIR)

        meta = JSONFeedMetadata(feed_name=feed_name, data_dir=meta_temp_dir)

        future = asyncio.ensure_future(meta.fetch())
        metadata: JSONFeedMetadata = _EVENT_LOOP.run_until_complete(future)
        data: str = metadata.data

        self.assertIsInstance(data, str)
        self.assertTrue(data)

        # should not be ready
        self.assertFalse(meta.is_ready())

        _EVENT_LOOP.run_until_complete(meta.update())

        # should be ready now
        self.assertTrue(meta.is_ready())

        # metadata present in the directory
        self.assertTrue(meta.filename in os.listdir(meta_temp_dir))