<s> import ClientConstants as CC <EOL> import ClientGUIDialogs <EOL> import collections <EOL> import HydrusConstants as HC <EOL> import HydrusData <EOL> import HydrusEncryption <EOL> import os <EOL> import potr <EOL> import TestConstants <EOL> import unittest <EOL> import HydrusGlobals <EOL> class Catcher ( ) : <EOL> def __init__ ( self ) : <EOL> self . _last_write = '<STR_LIT>' <EOL> def GetLastWrite ( self ) : <EOL> l_w = self . _last_write <EOL> self . _last_write = '<STR_LIT>' <EOL> return l_w <EOL> def write ( self , data ) : self . _last_write = data <EOL> class TestIM ( unittest . TestCase ) : <EOL> def test_otr ( self ) : <EOL> alice = HydrusData . GenerateKey ( ) . encode ( '<STR_LIT>' ) <EOL> bob = HydrusData . GenerateKey ( ) . encode ( '<STR_LIT>' ) <EOL> alice_privkey_hex = '<STR_LIT>' <EOL> bob_privkey_hex = '<STR_LIT>' <EOL> alice_privkey = HydrusEncryption . LoadOTRKey ( alice_privkey_hex . decode ( '<STR_LIT>' ) ) <EOL> bob_privkey = HydrusEncryption . LoadOTRKey ( bob_privkey_hex . decode ( '<STR_LIT>' ) ) <EOL> alice_account = HydrusEncryption . HydrusOTRAccount ( alice , alice_privkey , { } ) <EOL> bob_account = HydrusEncryption . HydrusOTRAccount ( bob , bob_privkey , { } ) <EOL> alice_context = HydrusEncryption . HydrusOTRContext ( alice_account , bob ) <EOL> bob_context = HydrusEncryption . HydrusOTRContext ( bob_account , alice ) <EOL> catcher = Catcher ( ) <EOL> self . assertEqual ( alice_context . state , potr . context . STATE_PLAINTEXT ) <EOL> self . assertEqual ( bob_context . state , potr . context . STATE_PLAINTEXT ) <EOL> m = alice_context . sendMessage ( potr . context . FRAGMENT_SEND_ALL , '<STR_LIT>' ) <EOL> res = bob_context . receiveMessage ( m , catcher ) <EOL> m = catcher . GetLastWrite ( ) <EOL> res = alice_context . receiveMessage ( m , catcher ) <EOL> m = catcher . GetLastWrite ( ) <EOL> res = bob_context . receiveMessage ( m , catcher ) <EOL> m = catcher . GetLastWrite ( ) <EOL> res = alice_context . receiveMessage ( m , catcher ) <EOL> m = catcher . GetLastWrite ( ) <EOL> res = bob_context . receiveMessage ( m , catcher ) <EOL> self . assertEqual ( alice_context . state , potr . context . STATE_ENCRYPTED ) <EOL> self . assertEqual ( bob_context . state , potr . context . STATE_ENCRYPTED ) <EOL> self . assertEqual ( bob_privkey . getPublicPayload ( ) , alice_context . getCurrentKey ( ) . getPublicPayload ( ) ) <EOL> self . assertEqual ( alice_privkey . getPublicPayload ( ) , bob_context . getCurrentKey ( ) . getPublicPayload ( ) ) <EOL> self . assertEqual ( alice_context . getCurrentTrust ( ) , None ) <EOL> alice_context . setCurrentTrust ( '<STR_LIT>' ) <EOL> self . assertEqual ( alice_context . getCurrentTrust ( ) , '<STR_LIT>' ) <EOL> [ ( args , kwargs ) ] = HydrusGlobals . test_controller . GetWrite ( '<STR_LIT>' ) <EOL> self . assertEqual ( args , ( alice , { bob : { alice_context . getCurrentKey ( ) . cfingerprint ( ) : '<STR_LIT>' } } ) ) <EOL> self . assertEqual ( bob_context . getCurrentTrust ( ) , None ) <EOL> bob_context . setCurrentTrust ( '<STR_LIT>' ) <EOL> self . assertEqual ( bob_context . getCurrentTrust ( ) , '<STR_LIT>' ) <EOL> [ ( args , kwargs ) ] = HydrusGlobals . test_controller . GetWrite ( '<STR_LIT>' ) <EOL> self . assertEqual ( args , ( bob , { alice : { bob_context . getCurrentKey ( ) . cfingerprint ( ) : '<STR_LIT>' } } ) ) <EOL> m = alice_context . sendMessage ( potr . context . FRAGMENT_SEND_ALL , '<STR_LIT>' , appdata = catcher ) <EOL> m = catcher . GetLastWrite ( ) <EOL> res = bob_context . receiveMessage ( m , catcher ) <EOL> ( message , gumpf ) = res <EOL> self . assertEqual ( message , '<STR_LIT>' ) <EOL> m = bob_context . sendMessage ( potr . context . FRAGMENT_SEND_ALL , '<STR_LIT>' , appdata = catcher ) <EOL> m = catcher . GetLastWrite ( ) <EOL> res = alice_context . receiveMessage ( m , catcher ) <EOL> ( message , gumpf ) = res <EOL> self . assertEqual ( message , '<STR_LIT>' ) </s>
