Reorganize factories

This commit is contained in:
mhchia
2019-11-01 17:34:03 +08:00
committed by Alex Stokes
parent 9500bdbf55
commit 10dd997805
4 changed files with 52 additions and 50 deletions

View File

@ -3,16 +3,13 @@ import asyncio
import pytest
from libp2p.network.exceptions import SwarmException
from tests.factories import ListeningSwarmFactory
from tests.factories import SwarmFactory
from tests.utils import connect_swarm
@pytest.mark.asyncio
async def test_swarm_dial_peer(is_host_secure):
swarms_and_keys = await ListeningSwarmFactory.create_batch_and_listen(
is_host_secure, 3
)
swarms = tuple(swarm for swarm, _key_pair in swarms_and_keys)
swarms = await SwarmFactory.create_batch_and_listen(is_host_secure, 3)
# Test: No addr found.
with pytest.raises(SwarmException):
await swarms[0].dial_peer(swarms[1].get_peer_id())
@ -44,10 +41,7 @@ async def test_swarm_dial_peer(is_host_secure):
@pytest.mark.asyncio
async def test_swarm_close_peer(is_host_secure):
swarms_and_keys = await ListeningSwarmFactory.create_batch_and_listen(
is_host_secure, 3
)
swarms = tuple(swarm for swarm, _key_pair in swarms_and_keys)
swarms = await SwarmFactory.create_batch_and_listen(is_host_secure, 3)
# 0 <> 1 <> 2
await connect_swarm(swarms[0], swarms[1])
await connect_swarm(swarms[1], swarms[2])