Browse Source

tests: Create identities fixture to use in message

Since the identities are not being tested in the message tests,
facilitate to create them.
PYADAPT-98
juga 5 years ago
parent
commit
d0a94e20cd
  1. 30
      tests/conftest.py
  2. 16
      tests/test_message.py

30
tests/conftest.py

@ -1,6 +1,9 @@
"""pytest configuration for the unit tests.""" """pytest configuration for the unit tests."""
import os
import pytest import pytest
from . import constants
@pytest.fixture() @pytest.fixture()
def datadir(request): def datadir(request):
@ -43,3 +46,30 @@ def alice_sec_key_data(datadir):
def bob_pub_key_data(datadir): def bob_pub_key_data(datadir):
key_data = datadir.read('bob@openpgp.example.pub.asc') key_data = datadir.read('bob@openpgp.example.pub.asc')
return key_data return key_data
@pytest.fixture()
def create_alice_identity(tmpdir, alice_sec_key_data, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
import pEp
pEp.import_key(alice_sec_key_data)
alice = pEp.Identity(
constants.ALICE_ADDRESS, constants.ALICE_NAME,
constants.ALICE_NAME_ADDR, constants.ALICE_FP, 0, ''
)
pEp.set_own_key(alice, constants.ALICE_FP)
return alice
@pytest.fixture()
def create_bob_identity(tmpdir, bob_pub_key_data):
os.environ["HOME"] = str(tmpdir)
import pEp
pEp.import_key(bob_pub_key_data)
bob = pEp.Identity(
constants.BOB_ADDRESS, constants.BOB_NAME, '',
constants.BOB_FP, 56, ''
)
return bob

16
tests/test_message.py

@ -1,23 +1,13 @@
"""Message unit tests.""" """Message unit tests."""
import os
from . import constants from . import constants
def test_msg_enc_dec_roundtrip(tmpdir, alice_sec_key_data, bob_pub_key_data): def test_msg_enc_dec_roundtrip(create_alice_identity, create_bob_identity):
os.environ["HOME"] = str(tmpdir)
import pEp import pEp
alice = pEp.Identity( alice = create_alice_identity
constants.ALICE_ADDRESS, constants.ALICE_NAME, bob = create_bob_identity
constants.ALICE_NAME_ADDR, constants.ALICE_FP, 0, ''
)
pEp.import_key(bob_pub_key_data)
bob = pEp.Identity(
constants.BOB_ADDRESS, constants.BOB_NAME, '',
constants.BOB_FP, 56, ''
)
msg = pEp.Message(constants.OUTGOING_MSG, alice) msg = pEp.Message(constants.OUTGOING_MSG, alice)
msg.to = [bob] msg.to = [bob]

Loading…
Cancel
Save