async def test_is_saving_record(self):
        context = RequestContext()
        storage = BasicStorage()

        context.injector.bind_instance(BaseStorage, storage)
        context.connection_ready = True
        context.message = CredentialRequest(
            credential={
                "credential_type": "TEST",
                "credential_values": {
                    "test": "one",
                    "value": "two"
                },
            })

        responder = MockResponder()
        responder.connection_id = "1234"

        handler_inst = CredentialRequestHandler()
        await handler_inst.handle(context, responder)

        assert len(responder.messages) == 0
        assert 1 == len(responder.webhooks)

        id = responder.webhooks[0][1]["credential_exchange_id"]
        exchange = await CredentialExchangeRecord.retrieve_by_id(context, id)
        assert exchange != None
        assert exchange.connection_id == responder.connection_id
        assert exchange.state == CredentialExchangeRecord.STATE_REQUEST_RECEIVED
        assert exchange.credential_request == context.message.credential
def context():
    """Fixture for context used in tests."""
    # pylint: disable=W0621
    context = RequestContext()
    context.message = ProvideData(goal_code="test_goal", data=[TEST_DATA])
    context.connection_record = ConnectionRecord(connection_id=TEST_CONN_ID)
    context.connection_ready = True
    yield context
    async def test_is_handler_saving_record(self):
        context = RequestContext()
        # wallet is required for issuer to sign stuff cause it holds keys
        wallet = BasicWallet()
        # storage is required to save exchange record and save credential
        storage = BasicStorage(wallet)
        # issuer required to create credential
        issuer = PDSIssuer(wallet)
        # holder requiered to save credential
        holder = PDSHolder(context)

        context.injector.bind_instance(BaseWallet, wallet)
        context.injector.bind_instance(BaseStorage, storage)
        context.injector.bind_instance(BaseIssuer, issuer)
        context.injector.bind_instance(BaseHolder, holder)

        record = CredentialExchangeRecord(
            connection_id=connection_id,
            initiator=CredentialExchangeRecord.INITIATOR_SELF,
            role=CredentialExchangeRecord.ROLE_HOLDER,
            state=CredentialExchangeRecord.STATE_REQUEST_SENT,
            thread_id=thread_id,
            credential_request=credential_request,
        )
        await record.save(context)

        credential = await create_credential(context,
                                             credential_request,
                                             their_public_did="1234-theirdid")
        context.message: CredentialIssue = CredentialIssue(
            credential=credential)
        context.message.assign_thread_id(thread_id)
        context.connection_ready = True

        handler_inst = CredentialIssueHandler()
        responder = MockResponder()
        responder.connection_id = connection_id

        await handler_inst.handle(context, responder)

        credential_id = responder.webhooks[0][1]["credential_id"]
        assert credential_id
        credential = await holder.get_credential(credential_id)
        credential = json.loads(credential)
        assert credential["credentialSubject"]

        for key in credential_request["credential_values"]:
            if (credential["credentialSubject"][key] !=
                    credential_request["credential_values"][key]):
                raise Exception(
                    f"""Requested Credential VALUES differ from Issued Credential,
                    RequestedCredential: {credential_request},
                    IssuedCredential: {credential}""")
Ejemplo n.º 4
0
def context(profile, mock_admin_connection):
    """RequestContext fixture."""
    context = RequestContext(profile)
    context.connection_record = mock_admin_connection
    context.connection_ready = True
    yield context