From d0a94e20cd7b09aaf3aa0726bd94ffd0cd938720 Mon Sep 17 00:00:00 2001 From: juga Date: Mon, 26 Oct 2020 10:55:17 +0000 Subject: [PATCH] tests: Create identities fixture to use in message Since the identities are not being tested in the message tests, facilitate to create them. --- tests/conftest.py | 30 ++++++++++++++++++++++++++++++ tests/test_message.py | 16 +++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1aa45d7..cac2a3b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,9 @@ """pytest configuration for the unit tests.""" +import os import pytest +from . import constants + @pytest.fixture() def datadir(request): @@ -43,3 +46,30 @@ def alice_sec_key_data(datadir): def bob_pub_key_data(datadir): key_data = datadir.read('bob@openpgp.example.pub.asc') 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 diff --git a/tests/test_message.py b/tests/test_message.py index c6bc979..10b59fd 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1,23 +1,13 @@ """Message unit tests.""" -import os from . import constants -def test_msg_enc_dec_roundtrip(tmpdir, alice_sec_key_data, bob_pub_key_data): - os.environ["HOME"] = str(tmpdir) +def test_msg_enc_dec_roundtrip(create_alice_identity, create_bob_identity): import pEp - alice = pEp.Identity( - constants.ALICE_ADDRESS, constants.ALICE_NAME, - 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, '' - ) + alice = create_alice_identity + bob = create_bob_identity msg = pEp.Message(constants.OUTGOING_MSG, alice) msg.to = [bob]