Exemple #1
0
    async def test_channel_update_and_download(self):
        """
        Test whether we can successfully update a channel and download the new version
        """
        # First we have to manually add the old version
        old_payload = ChannelMetadataPayload.from_file(CHANNEL_METADATA)
        with db_session:
            old_channel = self.session.mds.ChannelMetadata.from_payload(
                old_payload)
            chan_dir = CHANNEL_DIR / old_channel.dirname

        self.session.mds.process_channel_dir(chan_dir, old_payload.public_key,
                                             old_payload.id_)

        channel_tdef = TorrentDef.load(CHANNEL_TORRENT_UPDATED)
        libtorrent_port = self.get_port()
        await self.setup_seeder(channel_tdef, CHANNEL_DIR, libtorrent_port)

        payload = ChannelMetadataPayload.from_file(CHANNEL_METADATA_UPDATED)
        # Download the channel in our session
        with db_session:
            self.session.mds.process_payload(payload)
            channel = self.session.mds.ChannelMetadata.get(
                signature=payload.signature)

        def fake_get_metainfo(*args, **kwargs):
            return succeed(channel_tdef.get_metainfo())

        self.session.dlmgr.get_metainfo = fake_get_metainfo
        # The leecher should be hinted to leech from localhost. Thus, we must extend start_download_from_tdef
        # and get_metainfo to provide the hint.
        original_start_download_from_tdef = self.session.dlmgr.start_download

        def hinted_start_download(tdef=None, config=None, hidden=False):
            download = original_start_download_from_tdef(tdef=tdef,
                                                         config=config,
                                                         hidden=hidden)
            download.add_peer(
                ("127.0.0.1",
                 self.seeder_session.config.get_libtorrent_port()))
            return download

        self.session.dlmgr.start_download = hinted_start_download
        await self.session.gigachannel_manager.download_channel(channel)
        await self.session.gigachannel_manager.process_queued_channels()

        with db_session:
            # There should be 8 torrents + 1 channel torrent
            channel2 = self.session.mds.ChannelMetadata.get(
                public_key=database_blob(payload.public_key))
            self.assertEqual(channel2.timestamp, channel2.local_version)
            self.assertEqual(1565621688018, channel2.timestamp)
            self.assertEqual(8, self.session.mds.ChannelNode.select().count())
Exemple #2
0
def test_compute_channel_update_progress(metadata_store, tmpdir):
    """
    Test estimating progress of channel processing
    """
    payload = ChannelMetadataPayload.from_file(CHANNEL_METADATA_UPDATED)
    channel = metadata_store.process_payload(payload)[0][0]
    with patch.object(metadata_store, 'get_channel_dir_path', lambda _: Path(CHANNEL_DIR)):
        assert metadata_store.compute_channel_update_progress(channel) == 0.0
        metadata_store.process_channel_dir(CHANNEL_DIR, channel.public_key, channel.id_)
        assert metadata_store.compute_channel_update_progress(channel) == 1.0
Exemple #3
0
def test_process_channel_dir(metadata_store):
    """
    Test processing a directory containing metadata blobs
    """
    payload = ChannelMetadataPayload.from_file(CHANNEL_METADATA)
    channel = metadata_store.process_payload(payload)[0][0]
    assert not channel.contents_list
    metadata_store.process_channel_dir(CHANNEL_DIR, channel.public_key, channel.id_)
    assert len(channel.contents_list) == 4
    assert channel.timestamp == 1565621688015
    assert channel.local_version == channel.timestamp
Exemple #4
0
 def test_process_channel_dir(self):
     """
     Test processing a directory containing metadata blobs
     """
     payload = ChannelMetadataPayload.from_file(CHANNEL_METADATA)
     channel = self.mds.process_payload(payload)[0][0]
     self.assertFalse(channel.contents_list)
     self.mds.process_channel_dir(CHANNEL_DIR, channel.public_key,
                                  channel.id_)
     self.assertEqual(len(channel.contents_list), 4)
     self.assertEqual(channel.timestamp, 1565621688015)
     self.assertEqual(channel.local_version, channel.timestamp)