You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # This file is under GNU Affero General Public License 3.0
  3. # see LICENSE.txt
  4. """pytest configuration for the unit tests."""
  5. from .model import *
  6. # Init
  7. @pytest.fixture()
  8. def env_init(tmpdir_factory, request):
  9. """Create a tmp dir for the tests"""
  10. base = str(abs(hash(request.node.nodeid)))[:3]
  11. bn = tmpdir_factory.mktemp(base)
  12. print(bn)
  13. import os
  14. os.environ["PEP_HOME"] = str(bn)
  15. os.environ["HOME"] = str(bn)
  16. @pytest.fixture()
  17. def pEp(env_init):
  18. import pEp
  19. return pEp
  20. @pytest.fixture()
  21. def alice_myself(pEp, model):
  22. alice = pEp.Identity(
  23. model.alice.addr,
  24. model.alice.name,
  25. model.alice.user_id
  26. )
  27. pEp.myself(alice)
  28. return alice
  29. @pytest.fixture()
  30. def alice_imported(pEp, model):
  31. pEp.import_key(model.alice.key_sec)
  32. alice = pEp.Identity(
  33. model.alice.addr,
  34. model.alice.name,
  35. model.alice.user_id
  36. )
  37. return alice
  38. @pytest.fixture()
  39. def import_ident_alice_as_own_ident(pEp, model, alice_imported):
  40. alice = alice_imported
  41. pEp.set_own_key(alice, model.alice.fpr)
  42. return alice
  43. @pytest.fixture()
  44. def import_ident_bob(pEp, model):
  45. pEp.import_key(model.bob.key_pub)
  46. bob = pEp.Identity(
  47. model.bob.addr,
  48. model.bob.name,
  49. )
  50. bob.update()
  51. return bob