creating own identities
authorVolker Birk <vb@pep.foundation>
Thu, 04 Jan 2018 16:21:49 +0100
changeset 2344b9518d23fd64
parent 2343 e000d43a7704
child 2345 c30ed17bf561
creating own identities
test/python_tests/test_setup.py
     1.1 --- a/test/python_tests/test_setup.py	Mon Jan 01 23:24:45 2018 +0100
     1.2 +++ b/test/python_tests/test_setup.py	Thu Jan 04 16:21:49 2018 +0100
     1.3 @@ -17,6 +17,8 @@
     1.4  
     1.5  import os
     1.6  import shutil
     1.7 +from multiprocessing import Process
     1.8 +
     1.9  
    1.10  
    1.11  realhome = os.path.expanduser("~")
    1.12 @@ -32,7 +34,7 @@
    1.13              os.symlink(orig, dirname, True)
    1.14  
    1.15  
    1.16 -def create_home(arthome):
    1.17 +def create_home(mydir, arthome):
    1.18      "create an artificial home directory for testing"
    1.19  
    1.20      os.chdir(mydir)
    1.21 @@ -48,12 +50,35 @@
    1.22      link_if_exists("Library", arthome) # this may exist on macOS
    1.23  
    1.24  
    1.25 +def create_own_identities(mydir, arthome, username):
    1.26 +    "create own identities as part of the test setup"
    1.27 +
    1.28 +    os.environ["HOME"] = os.path.join(mydir, arthome)
    1.29 +    os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
    1.30 +
    1.31 +    import pEp
    1.32 +    me = pEp.Identity()
    1.33 +    me.address = arthome + "@peptest.ch"
    1.34 +    me.username = username
    1.35 +
    1.36 +    pEp.myself(me)
    1.37 +    print(repr(me))
    1.38 +
    1.39 +
    1.40  def create_homes():
    1.41      "create two artificial home directories for the two parties"
    1.42  
    1.43 -    create_home("home1")
    1.44 -    create_home("home2")
    1.45 -    os.chdir(mydir)
    1.46 +    create_home(mydir, "test1")
    1.47 +
    1.48 +    p1 = Process(target=create_own_identities, args=(mydir, 'test1', 'Alice One'))
    1.49 +    p1.start()
    1.50 +    p1.join()
    1.51 +
    1.52 +    create_home(mydir, "test2")
    1.53 +
    1.54 +    p2 = Process(target=create_own_identities, args=(mydir, 'test2', 'Bob Two'))
    1.55 +    p2.start()
    1.56 +    p2.join()
    1.57  
    1.58  
    1.59  def remove_homes():
    1.60 @@ -61,8 +86,8 @@
    1.61      contents"""
    1.62  
    1.63      os.chdir(mydir)
    1.64 -    shutil.rmtree("home1", ignore_errors=True)
    1.65 -    shutil.rmtree("home2", ignore_errors=True)
    1.66 +    shutil.rmtree("test1", ignore_errors=True)
    1.67 +    shutil.rmtree("test2", ignore_errors=True)
    1.68  
    1.69  
    1.70  if __name__ == "__main__":