def test_get_message_type(): write_schema = WriteSchema(schema_name, schema_version, attrs) assert write_schema.get_message_type('message_name') == '{}/{}/{}/message_name'.format( EVERNYM_MSG_QUALIFIER, WriteSchema.MSG_FAMILY, WriteSchema.MSG_FAMILY_VERSION )
async def test_write(): context = await Context.create_with_config(await get_test_config()) write_schema = WriteSchema(schema_name, schema_version, attrs) msg = write_schema.write_msg(context) assert msg['@type'] == '{};spec/{}/{}/{}'.format( EVERNYM_MSG_QUALIFIER, WriteSchema.MSG_FAMILY, WriteSchema.MSG_FAMILY_VERSION, WriteSchema.WRITE_SCHEMA) assert msg['@id'] is not None assert msg['~thread']['thid'] is not None assert msg['name'] == schema_name assert msg['version'] == schema_version assert msg['attrNames'] == list(attrs) await cleanup(context)
async def write_ledger_schema(loop) -> str: # input parameters for schema schema_name = 'CIS_Digital_Credentials' schema_version = get_random_version() schema_attrs = ['name', 'degree', 'year'] # constructor for the Write Schema protocol schema = WriteSchema(schema_name, schema_version, schema_attrs) first_step = loop.create_future() spinner = make_spinner( 'Waiting to write schema to ledger') # Console spinner # handler for message received when schema is written async def schema_written_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == WriteSchema.STATUS: first_step.set_result(message['schemaId']) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(WriteSchema.MSG_FAMILY, WriteSchema.MSG_FAMILY_VERSION, schema_written_handler) spinner.start() # request schema be written to ledger await schema.write(context) schema_id = await first_step # wait for operation to be complete return schema_id # returns ledger schema identifier
def test_init(): write_schema = WriteSchema(schema_name, schema_version, attrs) assert write_schema.name == schema_name assert write_schema.version == schema_version assert len(write_schema.attrs) == 3 assert write_schema.attrs == list(attrs)
def test_init(): write_schema = WriteSchema(schema_name, schema_version, attrs) assert write_schema.name == schema_name assert write_schema.version == schema_version assert len(write_schema.attrs) == 3 assert write_schema.attrs == list(attrs) with pytest.raises(ValueError): WriteSchema(None, schema_version, attrs) with pytest.raises(ValueError): WriteSchema('', schema_version, attrs) with pytest.raises(ValueError): WriteSchema(schema_name, None, attrs) with pytest.raises(ValueError): WriteSchema(schema_name, '', attrs) with pytest.raises(ValueError): WriteSchema(schema_name, schema_version, None) with pytest.raises(ValueError): WriteSchema(schema_name, schema_version, ['name', None])
async def write_ledger_schema(loop) -> str: # input parameters for schema schema_name = 'Diploma' schema_version = get_random_version() schema_attrs = [ 'title', 'email', 'first_name', 'surname', 'date_of_birth', 'national_insurance_number', 'identity_assurance_level', 'uuid', 'user_photograph_link' ] # constructor for the Write Schema protocol schema = WriteSchema(schema_name, schema_version, schema_attrs) first_step = loop.create_future() spinner = make_spinner( 'Waiting to write schema to ledger') # Console spinner # handler for message received when schema is written async def schema_written_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == WriteSchema.STATUS: first_step.set_result(message['schemaId']) else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(WriteSchema.MSG_FAMILY, WriteSchema.MSG_FAMILY_VERSION, schema_written_handler) spinner.start() # request schema be written to ledger await schema.write(context) schema_id = await first_step # wait for operation to be complete return schema_id # returns ledger schema identifier