async def test_status(): context = await Context.create_with_config(await get_test_config()) issue_credential = IssueCredential(for_relationship, thread_id) msg = issue_credential.status_msg() assert msg['@type'] == '{}/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, IssueCredential.STATUS) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] == thread_id await cleanup(context)
async def test_reject_credential(): context = await Context.create_with_config(await get_test_config()) issue_credential = IssueCredential(for_relationship, thread_id, None, None, comment) msg = issue_credential.reject_msg() assert msg['@type'] == '{}/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, IssueCredential.REJECT) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] == thread_id assert msg['comment'] == comment await cleanup(context)
async def issue_credential(loop, rel_did, cred_def_id): # input parameters for issue credential credential_name = 'CISDigitalCredential' credential_data = { 'name': 'Sanjay Sagore', 'degree': 'Bachelors', 'year': '2021' } # constructor for the Issue Credential protocol issue = IssueCredential(rel_did, None, cred_def_id, credential_data, credential_name, 0, True) offer_sent = loop.create_future() cred_sent = loop.create_future() spinner = make_spinner('Wait for Connect.me to accept the Credential Offer' ) # Console spinner # handler for 'sent` message when the offer for credential is sent async def send_offer_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: offer_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_offer_handler) spinner.start() # request that credential is offered await issue.offer_credential(context) await offer_sent # wait for sending of offer to connect.me user # handler for 'sent` message when the credential is sent async def send_cred_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: cred_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) spinner = make_spinner('waiting to send credential') # Console spinner spinner.start() handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) await cred_sent await asyncio.sleep( 3 ) # Wait a few seconds for the credential to arrive before sending the proof
async def issue_credential(loop, rel_did, cred_def_id): with open('sample_data.json') as f: data = json.load(f) credential_name = 'CISDigitalCredential' credential_data = data # constructor for the Issue Credential protocol issue = IssueCredential(rel_did, None, cred_def_id, credential_data, credential_name, 0, True) offer_sent = loop.create_future() cred_sent = loop.create_future() spinner = make_spinner('Wait for Connect.me to accept the Credential Offer' ) # Console spinner # handler for 'sent` message when the offer for credential is sent async def send_offer_handler(msg_name, message): print("SEND CRDDSSSSSS") spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: offer_sent.set_result(None) else: print("SEND CRDDSSSSSS NOT HANDLEDD") non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_offer_handler) spinner.start() # request that credential is offered await issue.offer_credential(context) await offer_sent # wait for sending of offer to connect.me user # handler for 'sent` message when the credential is sent async def send_cred_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: cred_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) spinner = make_spinner('waiting to send credential') # Console spinner spinner.start() handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) await cred_sent await asyncio.sleep( 3 ) # Wait a few seconds for the credential to arrive before sending the proof
async def test_propose_credential(): context = await Context.create_with_config(await get_test_config()) issue_credential = IssueCredential(for_relationship, None, cred_def_id, credential_values, comment) msg = issue_credential.propose_credential_msg() assert msg['@type'] == '{}/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, IssueCredential.PROPOSE) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['cred_def_id'] == cred_def_id assert msg['credential_values']['name'] == credential_values['name'] assert msg['credential_values']['degree'] == credential_values['degree'] assert msg['credential_values']['gpa'] == credential_values['gpa'] assert msg['comment'] == comment await cleanup(context)
def test_init(): issue_credential = IssueCredential(for_relationship, thread_id, cred_def_id, credential_values, comment, price, auto_issue) assert issue_credential.for_relationship == for_relationship assert issue_credential.thread_id == thread_id assert issue_credential.cred_def_id == cred_def_id assert json.dumps(issue_credential.values) == json.dumps(credential_values) assert issue_credential.comment == comment assert issue_credential.price == price assert issue_credential.auto_issue == auto_issue
async def test_offer_credential(): context = await Context.create_with_config(await get_test_config()) issue_credential = IssueCredential(for_relationship, None, cred_def_id, credential_values, comment, price, auto_issue) msg = issue_credential.offer_credential_msg() assert msg['@type'] == '{};spec/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, IssueCredential.OFFER) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['cred_def_id'] == cred_def_id assert msg['credential_values']['name'] == credential_values['name'] assert msg['credential_values']['degree'] == credential_values['degree'] assert msg['credential_values']['gpa'] == credential_values['gpa'] assert msg['comment'] == comment assert msg['price'] == price assert msg['auto_issue'] == auto_issue await cleanup(context)
async def issue_credential(loop, rel_did, cred_def_id): # input parameters for issue credential credential_name = 'Degree' credential_data = {'name': 'Joe Smith', 'degree': 'Bachelors'} # constructor for the Issue Credential protocol issue = IssueCredential(rel_did, None, cred_def_id, credential_data, 'comment', 0) offer_sent = loop.create_future() accept_request = loop.create_future() cred_sent = loop.create_future() spinner = make_spinner('Wait for Connect.me to accept the Credential Offer' ) # Console spinner # handler for 'ask_accept` message when the offer for credential is accepted async def send_offer_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: offer_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_offer_handler) spinner.start() # request that credential is offered await issue.offer_credential(context) await offer_sent # wait for connect.me user to accept offer async def accept_request_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.ACCEPT_REQUEST: accept_request.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) spinner = make_spinner('waiting to accept request') # Console spinner spinner.start() handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, accept_request_handler) await accept_request # request that credential be issued async def send_cred_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: cred_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) # request that credential is offered spinner = make_spinner('waiting to send credential') # Console spinner spinner.start() handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) await issue.issue_credential(context) await cred_sent await asyncio.sleep( 3 ) # Wait a few seconds for the credential to arrive before sending the proof
async def issue_credential(loop, rel_did, cred_def_id, cred_data=None): # input parameters for issue credential credential_name = 'Medication' if cred_data == None: credential_data = { 'Medication Snomed': '324095003', 'Medication Display': 'Oxytetracycline 250mg tablets', 'Repeat Frequency': '1', 'Repeat Period': '6', 'Repeat Unit': 'h', 'Route Snomed': '26643006', 'Route Display': 'Oral', 'Dose Quantity': '1', 'Dose Unit': 'Tablet' } else: credential_data = cred_data # constructor for the Issue Credential protocol issue = IssueCredential(rel_did, None, cred_def_id, credential_data, "Medication Prescribtion", 0, True) offer_sent = loop.create_future() cred_sent = loop.create_future() spinner = make_spinner('Wait for Connect.me to accept the Credential Offer' ) # Console spinner # handler for 'sent` message when the offer for credential is sent async def send_offer_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: offer_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_offer_handler) spinner.start() # request that credential is offered await issue.offer_credential(context) await offer_sent # wait for sending of offer to connect.me user # handler for 'sent` message when the credential is sent async def send_cred_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == IssueCredential.SENT: cred_sent.set_result(None) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) spinner = make_spinner('waiting to send credential') # Console spinner spinner.start() handlers.add_handler(IssueCredential.MSG_FAMILY, IssueCredential.MSG_FAMILY_VERSION, send_cred_handler) await cred_sent await asyncio.sleep( 3 ) # Wait a few seconds for the credential to arrive before sending the proof