Browse Source

PYADPT-110: Update sync testing (sync_handshake.py) to work with new sync impl

PYADPT-110
heck 4 years ago
parent
commit
3a6058e4b5
  1. 73
      test/sync_handshake.py

73
test/sync_handshake.py

@ -112,37 +112,36 @@ def add_debug_info(msg):
return msg return msg
class UserInterface(pEp.UserInterface):
def notifyHandshake(self, me, partner, signal): def this_notifyHandshake(me, partner, signal):
print(colored(str(signal), "yellow"), end=" ") print(colored(str(signal), "yellow"), end=" ")
output("on " + device_name + "" if not me.fpr else output("on " + device_name + "" if not me.fpr else
"for identities " + str(me.fpr) + " " + str(partner.fpr)) "for identities " + str(me.fpr) + " " + str(partner.fpr))
if me.fpr and partner.fpr: if me.fpr and partner.fpr:
assert me.fpr != partner.fpr assert me.fpr != partner.fpr
if signal in ( if signal in (
pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE, pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE,
pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OUR_DEVICE, pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OUR_DEVICE,
pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_FORM_GROUP pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_FORM_GROUP
): ):
if isinstance(end_on, list): if isinstance(end_on, list):
end_on.extend([ end_on.extend([
pEp.sync_handshake_signal.SYNC_NOTIFY_SOLE, pEp.sync_handshake_signal.SYNC_NOTIFY_SOLE,
pEp.sync_handshake_signal.SYNC_NOTIFY_IN_GROUP, pEp.sync_handshake_signal.SYNC_NOTIFY_IN_GROUP,
]) ])
sleep(.5) # user is reading message sleep(.5) # user is reading message
try: try:
if not options.noanswer: if not options.noanswer:
if options.reject: if options.reject:
self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) pEp.deliver_handshake_result(SYNC_HANDSHAKE_REJECTED)
else: else:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) pEp.deliver_handshake_result(SYNC_HANDSHAKE_ACCEPTED)
except NameError:
except NameError: pEp.deliver_handshake_result(SYNC_HANDSHAKE_ACCEPTED)
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) if signal in end_on:
if signal in end_on: global the_end
global the_end the_end = True
the_end = True
def shutdown_sync(): def shutdown_sync():
@ -153,6 +152,7 @@ def run(name, color=None, imap=False, own_ident=1, leave=False):
global device_name global device_name
device_name = name device_name = name
pEp.notify_handshake = this_notifyHandshake
if color: if color:
global output global output
@ -170,7 +170,7 @@ def run(name, color=None, imap=False, own_ident=1, leave=False):
me = pEp.Identity(imap_settings.IMAP_EMAIL, name + " of " + imap_settings.IMAP_USER, name) me = pEp.Identity(imap_settings.IMAP_EMAIL, name + " of " + imap_settings.IMAP_USER, name)
pEp.myself(me) pEp.myself(me)
pEp.messageToSend = messageImapToSend pEp.message_to_send = messageImapToSend
else: else:
me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman", name) me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman", name)
pEp.myself(me) pEp.myself(me)
@ -183,22 +183,19 @@ def run(name, color=None, imap=False, own_ident=1, leave=False):
me3 = pEp.Identity("alice@pep.foundation", name + " of Alice Neuman", name) me3 = pEp.Identity("alice@pep.foundation", name + " of Alice Neuman", name)
pEp.myself(me3) pEp.myself(me3)
pEp.messageToSend = messageToSend pEp.message_to_send = messageToSend
if multithreaded: if multithreaded:
from threading import Thread from threading import Thread
def sync_thread(): def sync_thread():
print(colored("********* ", "yellow") + colored("sync_thread entered", color)) print(colored("********* ", "yellow") + colored("sync_thread entered", color))
ui = UserInterface()
print(colored("********* ", "yellow") + colored("UserInterface object created", color)) print(colored("********* ", "yellow") + colored("UserInterface object created", color))
pEp.do_sync_protocol() pEp.Sync.run()
print(colored("********* ", "yellow") + colored("leaving sync_thread", color)) print(colored("********* ", "yellow") + colored("leaving sync_thread", color))
sync = Thread(target=sync_thread) sync = Thread(target=sync_thread)
sync.start() sync.start()
else: else:
pEp.script_is_implementing_sync() pEp.start_sync();
sync = None
ui = UserInterface()
try: try:
if leave: if leave:

Loading…
Cancel
Save