Test view in the zconsole

Is there a way to test views in the zconsole?

I'd exptect something like getting the content object via app.Plone.mydocument and the view via getMultipleAdapter and output the html code as text produced by the template with the data of the content. Is this the right way?

app._p_jar.sync()
from Testing.makerequest import makerequest
app = makerequest(app)
from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager
admin_username='admin'
acl_users = app.acl_users
user = acl_users.getUser(admin_username)
user = user.__of__(acl_users)
newSecurityManager(None,user)
content = app.Plone.mydocument
view = getMultiAdapter(
        (content , content.REQUEST),
        # name='document_view'
    )

I'm not sure whether this is correct. With name='document_view' I get an error. Without it I get something but I don't know how to go further.

I'v already read the code in Test with getMultiAdapter and in plone.app.contentypes test_view(). But I cannot find out how to get the view departing from app in the zconsole.

Yes this should be possible, but your fake request needs to provide the browser layers.

You should be able to run:

from plone.browserlayer.layer import mark_layer
from zope.traversing.interfaces import BeforeTraverseEvent

event = BeforeTraverseEvent(app.Plone, app.Plone.REQUEST)
mark_layer(None, event)

I did not test this, but something in that direction should be fine.

@maethu I've tried your code. And I do get a view.

But the view has no __of__() nor can it be called view().

What I am missing?

from plone.browserlayer.layer import mark_layer
from zope.traversing.interfaces import BeforeTraverseEvent
from Testing.makerequest import makerequest
app = makerequest(app)
event = BeforeTraverseEvent(app.Plone, app.Plone.REQUEST)
mark_layer(None, event)
from zope.component import getMultiAdapter
view = getMultiAdapter(
        (app.Plone.mydocument, app.Plone.mydocument.REQUEST),
        name='view'
    )

<Products.Five.browser.metaconfigure.SimpleViewClass from /app/lib/python3.12/site-packages/plone/app/dexterity/browser/item.pt object at 0x7f31b043afc0>

Sorry I missed setting the local component registry.
My scripts do that automatically.

from zope.component.hooks import setSite
from plone.browserlayer.layer import mark_layer
from zope.traversing.interfaces import BeforeTraverseEvent
from Testing.makerequest import makerequest
app = makerequest(app)
setSite(app.Plone)
event = BeforeTraverseEvent(app.Plone, app.Plone.REQUEST)
mark_layer(None, event)

Important update:

from zope.component.hooks import setSite
...
setSite(app.Plone)

mark_layer no actually uses the local component registry of your plone site, thats where the browserlayers gets registered during the plone installation.