handshake
authorVolker Birk <vb@pep.foundation>
Fri, 05 Jan 2018 21:54:50 +0100
changeset 2358a40432f11e35
parent 2357 5d93322dfd2e
child 2359 a7ff871066a7
handshake
test/python_tests/test_1.py
test/python_tests/test_handshake.py
     1.1 --- a/test/python_tests/test_1.py	Fri Jan 05 21:36:23 2018 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,100 +0,0 @@
     1.4 -# -*- coding: utf-8 -*-
     1.5 -
     1.6 -# this file is under GNU General Public License 3.0
     1.7 -# Copyleft 2017, p≡p foundation
     1.8 -
     1.9 -
    1.10 -from transport import *
    1.11 -
    1.12 -
    1.13 -def setup_gnupg():
    1.14 -    assert os.environ["GNUPGHOME"] != ""
    1.15 -
    1.16 -
    1.17 -mydir = os.path.dirname(os.path.realpath(__file__))
    1.18 -
    1.19 -
    1.20 -class Test1:
    1.21 -
    1.22 -    def setup_method(self):
    1.23 -        arthome = "test1"
    1.24 -
    1.25 -        os.environ["HOME"] = os.path.join(mydir, arthome)
    1.26 -        os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
    1.27 -
    1.28 -        os.chdir(os.path.join(mydir, arthome))
    1.29 -
    1.30 -    @property
    1.31 -    def me(self):
    1.32 -        # because of flaws of py.test these two statements are necessary
    1.33 -        setup_gnupg()   # work around a bug with initializing os.environ
    1.34 -        import pEp      # after that import pEp module, not before
    1.35 -
    1.36 -        i = pEp.Identity()
    1.37 -        i.address = "test1@peptest.ch"
    1.38 -        i.username = "Alice One"
    1.39 -        pEp.myself(i)
    1.40 -        return i
    1.41 -
    1.42 -    @property
    1.43 -    def you(self):
    1.44 -        setup_gnupg() ; import pEp
    1.45 -
    1.46 -        i = pEp.Identity()
    1.47 -        i.address = "test2@peptest.ch"
    1.48 -        i.username = "Bob Two"
    1.49 -        pEp.update_identity(i)
    1.50 -        return i
    1.51 -
    1.52 -    def test_send_message(self):
    1.53 -        setup_gnupg() ; import pEp
    1.54 -
    1.55 -        msg = pEp.Message()
    1.56 -        msg.from_ = self.me
    1.57 -        msg.to = [self.you]
    1.58 -        msg.shortmsg = "Subject line"
    1.59 -        msg.longmsg = "Message Text\n"
    1.60 -
    1.61 -        enc = msg.encrypt()
    1.62 -        send_message("test2", str(enc))
    1.63 -
    1.64 -class Test2:
    1.65 -
    1.66 -    def setup_method(self):
    1.67 -        arthome = "test2"
    1.68 -
    1.69 -        os.environ["HOME"] = os.path.join(mydir, arthome)
    1.70 -        os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
    1.71 -
    1.72 -        os.chdir(os.path.join(mydir, arthome))
    1.73 -
    1.74 -    @property
    1.75 -    def me(self):
    1.76 -        # because of flaws of py.test these two statements are necessary
    1.77 -        setup_gnupg()   # work around a bug with initializing os.environ
    1.78 -        import pEp      # after that import pEp module, not before
    1.79 -
    1.80 -        i = pEp.Identity()
    1.81 -        i.address = "test2@peptest.ch"
    1.82 -        i.username = "Bob Two"
    1.83 -        pEp.myself(i)
    1.84 -        return i
    1.85 -
    1.86 -    @property
    1.87 -    def you(self):
    1.88 -        setup_gnupg() ; import pEp
    1.89 -
    1.90 -        i = pEp.Identity()
    1.91 -        i.address = "test1@peptest.ch"
    1.92 -        i.username = "Alice One"
    1.93 -        pEp.update_identity(i)
    1.94 -        return i
    1.95 -
    1.96 -    def test_receive_message(self):
    1.97 -        setup_gnupg() ; import pEp
    1.98 -
    1.99 -        txt = wait_for_message()
   1.100 -        msg = pEp.Message(txt)
   1.101 -        msg.decrypt()
   1.102 -        assert msg.from_.address == self.you.address
   1.103 -
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/python_tests/test_handshake.py	Fri Jan 05 21:54:50 2018 +0100
     2.3 @@ -0,0 +1,116 @@
     2.4 +# -*- coding: utf-8 -*-
     2.5 +
     2.6 +# this file is under GNU General Public License 3.0
     2.7 +# Copyleft 2017, p≡p foundation
     2.8 +
     2.9 +
    2.10 +from transport import *
    2.11 +
    2.12 +
    2.13 +def setup_gnupg():
    2.14 +    assert os.environ["GNUPGHOME"] != ""
    2.15 +
    2.16 +
    2.17 +mydir = os.path.dirname(os.path.realpath(__file__))
    2.18 +
    2.19 +
    2.20 +class Test1:
    2.21 +
    2.22 +    def setup_method(self):
    2.23 +        arthome = "test1"
    2.24 +
    2.25 +        os.environ["HOME"] = os.path.join(mydir, arthome)
    2.26 +        os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
    2.27 +
    2.28 +        os.chdir(os.path.join(mydir, arthome))
    2.29 +
    2.30 +    @property
    2.31 +    def me(self):
    2.32 +        # because of flaws of py.test these two statements are necessary
    2.33 +        setup_gnupg()   # work around a bug with initializing os.environ
    2.34 +        import pEp      # after that import pEp module, not before
    2.35 +
    2.36 +        i = pEp.Identity()
    2.37 +        i.address = "test1@peptest.ch"
    2.38 +        i.username = "Alice One"
    2.39 +        pEp.myself(i)
    2.40 +        return i
    2.41 +
    2.42 +    @property
    2.43 +    def you(self):
    2.44 +        setup_gnupg() ; import pEp
    2.45 +
    2.46 +        i = pEp.Identity()
    2.47 +        i.address = "test2@peptest.ch"
    2.48 +        i.username = "Bob Two"
    2.49 +        pEp.update_identity(i)
    2.50 +        return i
    2.51 +
    2.52 +    def test_send_and_recv_message(self):
    2.53 +        setup_gnupg() ; import pEp
    2.54 +
    2.55 +        msg = pEp.Message()
    2.56 +        msg.from_ = self.me
    2.57 +        msg.to = [self.you]
    2.58 +        msg.shortmsg = "Subject line"
    2.59 +        msg.longmsg = "Message Text\n"
    2.60 +
    2.61 +        enc = msg.encrypt()
    2.62 +        send_message("test2", str(enc))
    2.63 +
    2.64 +        txt = wait_for_message()
    2.65 +        enc = pEp.Message(txt)
    2.66 +        assert enc.from_.address == "test2@peptest.ch"
    2.67 +        inc, keys, rating, consumed, flags = enc.decrypt()
    2.68 +        assert rating == 6
    2.69 +
    2.70 +
    2.71 +class Test2:
    2.72 +
    2.73 +    def setup_method(self):
    2.74 +        arthome = "test2"
    2.75 +
    2.76 +        os.environ["HOME"] = os.path.join(mydir, arthome)
    2.77 +        os.environ["GNUPGHOME"] = os.path.join(mydir, arthome, '.gnupg')
    2.78 +
    2.79 +        os.chdir(os.path.join(mydir, arthome))
    2.80 +
    2.81 +    @property
    2.82 +    def me(self):
    2.83 +        # because of flaws of py.test these two statements are necessary
    2.84 +        setup_gnupg()   # work around a bug with initializing os.environ
    2.85 +        import pEp      # after that import pEp module, not before
    2.86 +
    2.87 +        i = pEp.Identity()
    2.88 +        i.address = "test2@peptest.ch"
    2.89 +        i.username = "Bob Two"
    2.90 +        pEp.myself(i)
    2.91 +        return i
    2.92 +
    2.93 +    @property
    2.94 +    def you(self):
    2.95 +        setup_gnupg() ; import pEp
    2.96 +
    2.97 +        i = pEp.Identity()
    2.98 +        i.address = "test1@peptest.ch"
    2.99 +        i.username = "Alice One"
   2.100 +        pEp.update_identity(i)
   2.101 +        return i
   2.102 +
   2.103 +    def test_recv_and_send_message(self):
   2.104 +        setup_gnupg() ; import pEp
   2.105 +
   2.106 +        txt = wait_for_message()
   2.107 +        msg = pEp.Message(txt)
   2.108 +        msg.decrypt()
   2.109 +        assert msg.from_.address == self.you.address
   2.110 +
   2.111 +        out = pEp.Message(1)
   2.112 +        out.from_ = self.me
   2.113 +        out.to = [self.you]
   2.114 +        out.shortmsg = "Subject Back"
   2.115 +        out.longmsg = "Text Back\n"
   2.116 +
   2.117 +        enc = out.encrypt()
   2.118 +        send_message("test1", str(enc))
   2.119 +