def test_monitor_downloads_recreate_ip(self): """ Test whether an old introduction point is recreated """ mock_state = MockObject() mock_download = MockObject() mock_tdef = MockObject() mock_tdef.get_infohash = lambda: b'a' mock_download.get_def = lambda: mock_tdef mock_download.add_peer = lambda _: succeed(None) mock_download.get_state = lambda: mock_state mock_download.config = MockObject() mock_download.config.get_hops = lambda: 1 mock_download.apply_ip_filter = lambda _: None mock_state.get_status = lambda: 4 mock_state.get_download = lambda: mock_download def mock_create_ip(*_, **__): mock_create_ip.called = True mock_create_ip.called = False self.nodes[0].overlay.create_introduction_point = mock_create_ip self.nodes[0].overlay.download_states[b'a'] = 3 self.nodes[0].overlay.monitor_downloads([mock_state]) self.assertTrue(mock_create_ip.called)
def test_readd_bittorrent_peers(self): """ Test the readd bittorrent peers method """ mock_torrent = MockObject() mock_torrent.add_peer = lambda _: succeed(None) mock_torrent.tdef = MockObject() mock_torrent.tdef.get_infohash = lambda: b'a' * 20 self.nodes[0].overlay.bittorrent_peers = {mock_torrent: [None]} self.nodes[0].overlay.readd_bittorrent_peers() self.assertNotIn(mock_torrent, self.nodes[0].overlay.bittorrent_peers)