From 8b202b6bf7f695b3785600ab40402fa21a87473b Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 13 Nov 2020 13:56:23 +0100 Subject: [PATCH] basic_doctest.py: rewrite as pytest --- test/basic_doctest.py | 73 +++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/test/basic_doctest.py b/test/basic_doctest.py index 2207bed..9ac1055 100755 --- a/test/basic_doctest.py +++ b/test/basic_doctest.py @@ -1,27 +1,54 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" ->>> import pEp ->>> me = pEp.Identity("alice.smith@peptest.ch", "Alice Smith", "23") ->>> me.username -'Alice Smith' ->>> print(me) -Alice Smith ->>> you = pEp.Identity("bob.bourne@peptest.ch", "Bob Bourne", "42") ->>> print(you) -Bob Bourne ->>> m = pEp.outgoing_message(me) ->>> m.to = [you] ->>> m.shortmsg = "let's meet next week" ->>> m.longmsg = "Please call me back" ->>> m2 = m.encrypt() ->>> print(m2) ->>> m3, keys, rating, flags = m2.decrypt() ->>> rating -pEp.rating.reliable -""" +from . import constants +import pytest -if __name__ == "__main__": - import doctest - doctest.testmod() +# """ +# >>> import pEp +# >>> me = pEp.Identity("alice.smith@peptest.ch", "Alice Smith", "23") +# >>> me.username +# 'Alice Smith' +# >>> print(me) +# Alice Smith +# >>> you = pEp.Identity("bob.bourne@peptest.ch", "Bob Bourne", "42") +# >>> print(you) +# Bob Bourne +# >>> m = pEp.outgoing_message(me) +# >>> m.to = [you] +# >>> m.shortmsg = "let's meet next week" +# >>> m.longmsg = "Please call me back" +# >>> m2 = m.encrypt() +# >>> print(m2) +# >>> m3, keys, rating, flags = m2.decrypt() +# >>> rating +# pEp.rating.reliable +# """ +# +# if __name__ == "__main__": +# import doctest +# doctest.testmod() + +def test_basic(pEp, model): + me = pEp.Identity( + model.alice.addr, + model.alice.name, + model.alice.user_id + ) + assert me.username == model.alice.name + assert str(me) == str(model.alice) + you = pEp.Identity( + model.bob.addr, + model.bob.name, + model.bob.user_id + ) + assert str(you) == str(model.bob) + #TODO: pEp.outgoing_message() needs to return type pEp.Message not None + m = pEp.outgoing_message(me) + m.to = [you] + m.shortmsg = constants.SUBJECT + m.longmsg = constants.BODY + #TODO: encrypt needs to return message type + m2 = m.encrypt() + m3, keys, rating, flags = m2.decrypt() + assert rating == pEp._pEp.rating.reliable