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

@ -14,7 +14,6 @@ import enum
import pytest
from libp2p.crypto.rsa import create_new_key_pair
from libp2p.network.notifee_interface import INotifee
from tests.configs import LISTEN_MADDR
from tests.factories import SwarmFactory
@ -57,7 +56,7 @@ class MyNotifee(INotifee):
@pytest.mark.asyncio
async def test_notify(is_host_secure):
swarms = [SwarmFactory(is_host_secure, create_new_key_pair()) for _ in range(2)]
swarms = [SwarmFactory(is_secure=is_host_secure) for _ in range(2)]
events_0_0 = []
events_1_0 = []

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])