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 2 years ago
parent
commit
d0a94e20cd
2 changed files with 33 additions and 13 deletions
  1. +30
    -0
      tests/conftest.py
  2. +3
    -13
      tests/test_message.py

+ 30
- 0
tests/conftest.py View File

@ -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

+ 3
- 13
tests/test_message.py View File

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


Loading…
Cancel
Save