def test_init(): relationship = Relationship( for_relationship='RxRJCMe5XNqc9e9J1YPwhL', thread_id='7a80285e-896c-45f6-b386-39ed7c49230c', label='test') assert relationship.label == 'test' assert relationship.for_relationship == 'RxRJCMe5XNqc9e9J1YPwhL' assert relationship.thread_id == '7a80285e-896c-45f6-b386-39ed7c49230c' relationship = Relationship(label=None) assert relationship.label == ''
def test_init(): relationship = Relationship( for_relationship=for_relationship, thread_id=thread_id, label=label, logo_url=logo_url, ) assert relationship.label == label assert relationship.for_relationship == for_relationship assert relationship.thread_id == thread_id assert relationship.logo_url == logo_url relationship = Relationship(label=None) assert relationship.label is None assert relationship.logo_url is None
async def test_sms_connection_invitation(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship(for_relationship=for_relationship, thread_id=thread_id) msg = relationship.sms_connection_invitation_msg(context) print(msg) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.SMS_CONNECTION_INVITATION) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['~for_relationship'] == for_relationship
async def test_connection_invitation(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship( for_relationship='RxRJCMe5XNqc9e9J1YPwhL', thread_id='7a80285e-896c-45f6-b386-39ed7c49230c', label='test') msg = relationship.connection_invitation_msg(context) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.CONNECTION_INVITATION) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['~for_relationship'] == 'RxRJCMe5XNqc9e9J1YPwhL'
async def test_create(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship(for_relationship=for_relationship, thread_id=thread_id, label=label) msg = relationship.create_msg(context) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.CREATE) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['label'] == label assert 'logoUrl' not in msg assert 'phoneNumber' not in msg
async def test_sms_out_of_band_invitation(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship(for_relationship=for_relationship, thread_id=thread_id) msg = relationship.sms_out_of_band_invitation_msg(context) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.SMS_OUT_OF_BAND_INVITATION) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['~for_relationship'] == for_relationship assert msg['goalCode'] == GoalsList.P2P_MESSAGING.value.code assert msg['goal'] == GoalsList.P2P_MESSAGING.value.name
async def test_out_of_band_invitation_with_goal(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship(for_relationship=for_relationship, thread_id=thread_id) msg = relationship.out_of_band_invitation_msg(context, goal=GoalsList.ISSUE_VC) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.OUT_OF_BAND_INVITATION) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['~for_relationship'] == for_relationship assert msg['goalCode'] == GoalsList.ISSUE_VC.value.code assert msg['goal'] == GoalsList.ISSUE_VC.value.name assert 'shortInvite' not in msg
async def test_out_of_band_invitation(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship( for_relationship='RxRJCMe5XNqc9e9J1YPwhL', thread_id='7a80285e-896c-45f6-b386-39ed7c49230c', label='test' ) msg = relationship.out_of_band_invitation_msg(context) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.OUT_OF_BAND_INVITATION ) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['~for_relationship'] == 'RxRJCMe5XNqc9e9J1YPwhL' assert msg['goalCode'] == GoalsList.P2P_MESSAGING.value.code assert msg['goal'] == GoalsList.P2P_MESSAGING.value.name
async def test_create(): context = await Context.create_with_config(await get_test_config()) relationship = Relationship( for_relationship='RxRJCMe5XNqc9e9J1YPwhL', thread_id='7a80285e-896c-45f6-b386-39ed7c49230c', label='test', logo_url='logo_url' ) msg = relationship.create_msg(context) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, Relationship.CREATE ) assert msg['@id'] is not None assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['label'] == 'test' assert msg['logoUrl'] == 'logo_url'
async def create_relationship(loop) -> str: global context global handlers # Relationship protocol has two steps # 1. create relationship key # 2. create invitation # Constructor for the Relationship API relationship: Relationship = Relationship() rel_did = loop.create_future() thread_id = loop.create_future() spinner = make_spinner('Waiting to create relationship') # Console spinner # handler for the response to the request to start the Connecting protocol. async def created_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == Relationship.CREATED: thread_id.set_result(message['~thread']['thid']) rel_did.set_result(message['did']) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, created_handler) spinner.start() # starts the relationship protocol await relationship.create(context) thread_id = await thread_id rel_did = await rel_did # Step 2 invitation = loop.create_future() spinner = make_spinner('Waiting to create invitation') # Console spinner # handler for the accept message sent when invitation is created async def invitation_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == Relationship.INVITATION: invite_url = message['inviteURL'] # write QRCode to disk qr = pyqrcode.create(invite_url) qr.png('qrcode.png') if os.environ.get('HTTP_SERVER_URL'): print( 'Open the following URL in your browser and scan presented QR code' ) print( f'{ANSII_GREEN}{os.environ.get("HTTP_SERVER_URL")}/python-example-app/qrcode.html{ANSII_RESET}' ) else: print('QR code generated at: qrcode.png') print( 'Open this file and scan QR code to establish a connection' ) invitation.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) spinner.start() # note this overrides the handler for this message family! This is for demonstration purposes only. handlers.add_handler(Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, invitation_handler) relationship: Relationship = Relationship(rel_did, thread_id) await relationship.connection_invitation(context) await invitation return rel_did # return owning DID for the connection
async def create_relationship(loop) -> str: global context global handlers # Relationship protocol has two steps # 1. create relationship key # 2. create invitation # Constructor for the Relationship API relationship: Relationship = Relationship(label='inviter') rel_did = loop.create_future() thread_id = loop.create_future() spinner = make_spinner('Waiting to create relationship') # Console spinner # handler for the response to the request to start the Connecting protocol. async def created_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == Relationship.CREATED: thread_id.set_result(message['~thread']['thid']) rel_did.set_result(message['did']) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, created_handler) spinner.start() # starts the relationship protocol await relationship.create(context) thread_id = await thread_id rel_did = await rel_did # Step 2 invitation = loop.create_future() spinner = make_spinner('Waiting to create invitation') # Console spinner # handler for the accept message sent when invitation is created async def invitation_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == Relationship.INVITATION: invite_url = message["inviteURL"] print(invite_url) # write QRCode to disk qr = pyqrcode.create(invite_url) qr.png('qrcode.png') print() print('QR code at: qrcode.png') invitation.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) spinner.start() # note this overrides the handler for this message family! This is for demonstration purposes only. handlers.add_handler(Relationship.MSG_FAMILY, Relationship.MSG_FAMILY_VERSION, invitation_handler) relationship: Relationship = Relationship(rel_did, thread_id) await relationship.connection_invitation(context) await invitation return rel_did # return owning DID for the connection