def test_widget_render():
    crom.configure(widget_fixture)
        
    field = widget_fixture.MyField("Cool Test")
    request = Request()
    form = Form(None, request)
        
    widget = interfaces.IWidget(field, form, request)
    assert isinstance(widget, Widget)
    assert widget.component is field

    assert widget.render() == (
        "<p>Too complicated widget for Cool Test</p>")
    
    field2 = widget_fixture.AnotherField("Bad Test")
    widget = interfaces.IWidget(field2, form, request)
    assert isinstance(widget, widget_fixture.NoRenderWidget)
        
    with pytest.raises(ComponentLookupError):
        # No template or render method defined
        # Error !
        widget.render()

        
    field = widget_fixture.YetAnotherField("Cool Template Test")
    request = Request()
    form = Form(None, request)
        
    widget = interfaces.IWidget(field, form, request)
    assert widget.component is field
    
    assert widget.render() == (
        """<p>Nice template for Cool Template Test</p>
""")
Beispiel #2
0
def test_subscriptions():
    from .fixtures import subscriptions as module

    # grok the component module
    crom.configure(module)

    source1 = module.One()

    # we can list them without instanciating
    subs = list(extiface.subscription_lookup(module.ISomeSubscription, source1))

    assert subs == [module.Subscription]

    # and we should now be able to get simple subscriptions
    subs = list(extiface.subscription_lookup(module.ISomeSubscription, source1, subscribe=True))

    assert len(subs) == 1
    assert isinstance(subs[0], module.Subscription)

    # we should also be able to get multi subscriptions
    source2 = module.Two()
    source3 = module.Three()

    subs = list(extiface.subscription_lookup(module.ISomeSubscription, source2, source3, subscribe=True))

    assert len(subs) == 2
    assert isinstance(subs[0], module.MultiSubscription1)
    assert isinstance(subs[1], module.MultiSubscription2)

    # ordered components are sortable
    sorted_subs = list(utils.sort_components(subs))
    assert isinstance(sorted_subs[0], module.MultiSubscription2)
    assert isinstance(sorted_subs[1], module.MultiSubscription1)
def setup_module(module):
    import cromlech.dawnlight

    testing.setup()
    crom.configure(cromlech.dawnlight)
    crom.implicit.registry.register(
        (Interface, IRequest), IView, 'index', RawView)
    crom.implicit.registry.register(
        (IRenderable,), IResponseFactory, '', RenderableResponseFactory)
Beispiel #4
0
def test_component():
    from .fixtures import base_view as module

    # grok the component module
    crom.configure(module)

    # we should now be able to adapt things
    assert implicit.registry.lookup(
        (context, request), IView, 'uselessrock') is module.UselessRock
Beispiel #5
0
def test_component():
    from .fixtures import component as module
    # grok the component module
    crom.configure(module)
    # we should now be able to adapt things
    source = module.Source()
    adapted = module.ITarget(source)
    assert module.ITarget.providedBy(adapted)
    assert isinstance(adapted, module.Adapter)
    assert adapted.context is source
Beispiel #6
0
def test_component():
    from .fixtures import component as module

    # grok the component module
    crom.configure(module)

    # we should now be able to adapt things
    source = module.Source()
    adapted = module.ITarget(source)
    assert module.ITarget.providedBy(adapted)
    assert isinstance(adapted, module.Adapter)
    assert adapted.context is source
Beispiel #7
0
def test_new_grokker():
    from .fixtures import new_grokker as module
    # this module defines a new 'view' grokker that uses the
    # same registration machinery as the component grokker

    # grok the new grokker module
    crom.configure(module)
    # we should now be able to adapt things
    source = module.Source()
    view = module.ITarget(source, name='foo')
    assert module.ITarget.providedBy(view)
    assert isinstance(view, module.View)
    assert view.context is source
Beispiel #8
0
async def prepare_crypto(app, loop):
    key = get_key('jwt.key')
    app.jwt_service = JWTService(key, JWTHandler, lifetime=600)

    # Bootstrapping the Crom registry
    monkey.incompat()
    implicit.initialize()

    # Configure
    configure(taels)
    configure(taels_demo)

    print('INITIALIZED !!')
Beispiel #9
0
def test_new_grokker():
    from .fixtures import new_grokker as module
    # this module defines a new 'view' grokker that uses the
    # same registration machinery as the component grokker

    # grok the new grokker module
    crom.configure(module)
    # we should now be able to adapt things
    source = module.Source()
    view = module.ITarget(source, name='foo')
    assert module.ITarget.providedBy(view)
    assert isinstance(view, module.View)
    assert view.context is source
def test_extends():

    crom.configure(extends_fixture)

    request = Request()
    context = object()
    form = IView(context, request, name='othernameform')

    assert isinstance(form, extends_fixture.OtherNameForm)
    assert len(form.fields) == 1
    assert list(form.fields)[0].title == "Name"
    
    assert len(form.actions) == 2
    assert [a.title for a in form.actions] == ['Register', 'Kill']
Beispiel #11
0
def test_manager_viewlet():
    """The manager is a location (a slot) where viewlet will display.
    It supervises the rendering of each viewlet and merged the output.
    """
    from .fixtures import entities as module

    # grok the component module
    crom.configure(module)

    # We define the actors
    mammoth = object()
    request = Request()
    view = View(mammoth, request)
    generic_template = Template()

    # module contains a manager, called 'Header'
    # we should retrieve it here
    manager = IViewSlot.adapt(mammoth, request, view, name='header')
    assert isinstance(manager, module.Header)

    # With no security guards in place, we can render the manager
    manager.update()
    rendering = manager.render()
    assert rendering == "A nice logo\nYou are allowed.\nBaseline"


    with ContextualSecurityGuards(None, security_check):
        
        # Rending our manager will fail.
        # The reason is : there's no interaction but security
        # guards are declared. Therefore, the security computation
        # cannot go further:
        with pytest.raises(MissingSecurityContext):
            manager.update()

        # With an interaction, we should have a security context
        # With a wrong user, the viewlet is not retrieved.
        with ContextualInteraction(Principal('*****@*****.**')):
            manager.update()
            rendering = manager.render()
            assert rendering == "A nice logo\nBaseline"

        # With an interaction, we should have a security context
        # With a wrong user, the viewlet is not retrieved.
        with ContextualInteraction(Principal('*****@*****.**')):
            manager.update()
            rendering = manager.render()
            assert rendering == "A nice logo\nYou are allowed.\nBaseline"
Beispiel #12
0
def test_component_factory():
    from .fixtures import component as module

    # grok the component module
    crom.configure(module)

    # we should now be able to get component
    component = module.ITarget.component()
    assert module.ITarget.providedBy(component)
    # it's always the same
    assert component is module.ITarget.component()

    assert isinstance(component, module.ComponentFactory)

    # yet we can adapt on it (in this case calling return self)
    assert component is module.ITarget()
Beispiel #13
0
def test_component_factory():
    from .fixtures import component as module

    # grok the component module
    crom.configure(module)

    # we should now be able to get component
    component = module.ITarget.component()
    assert module.ITarget.providedBy(component)
    # it's always the same
    assert component is module.ITarget.component()

    assert isinstance(component, module.ComponentFactory)

    # yet we can adapt on it (in this case calling return self)
    assert component is module.ITarget()
Beispiel #14
0
def test_subscriptions():
    from .fixtures import subscriptions as module

    # grok the component module
    crom.configure(module)

    source1 = module.One()

    # we can list them without instanciating
    subs = list(extiface.subscription_lookup(module.ISomeSubscription,
                                             source1))

    assert subs == [module.Subscription]

    # and we should now be able to get simple subscriptions
    subs = list(
        extiface.subscription_lookup(module.ISomeSubscription,
                                     source1,
                                     subscribe=True))

    assert len(subs) == 1
    assert isinstance(subs[0], module.Subscription)

    # we should also be able to get multi subscriptions
    source2 = module.Two()
    source3 = module.Three()

    subs = list(
        extiface.subscription_lookup(module.ISomeSubscription,
                                     source2,
                                     source3,
                                     subscribe=True))

    assert len(subs) == 2
    assert isinstance(subs[0], module.MultiSubscription1)
    assert isinstance(subs[1], module.MultiSubscription2)

    # ordered components are sortable
    sorted_subs = list(utils.sort_components(subs))
    assert isinstance(sorted_subs[0], module.MultiSubscription2)
    assert isinstance(sorted_subs[1], module.MultiSubscription1)
Beispiel #15
0
def test_no_implicit_grokking():
    from .fixtures import component as module
    # grok the component module
    with py.test.raises(NoImplicitRegistryError):
        crom.configure(module)
Beispiel #16
0
def test_no_implicit_grokking():
    from .fixtures import component as module
    # grok the component module
    with py.test.raises(NoImplicitRegistryError):
        crom.configure(module)
Beispiel #17
0
def crom_setup():
    testing.setup()
    crom.configure(dolmen.forms.base)
def crom_setup():
    testing.setup()
    registerDefault()
    load.reloadComponents()
    crom.configure(dolmen.forms.base)
    crom.configure(dolmen.forms.ztk)
Beispiel #19
0
import dolmen.tales
import gatekeeper
import keeper
import grokker, dolmen.view, dolmen.forms.base, dolmen.forms.ztk
from dolmen.forms.ztk.fields import registerDefault

# Grokking
crom.monkey.incompat()
crom.implicit.initialize()
registerDefault()

crom.configure(
    dolmen.forms.base,
    dolmen.forms.ztk,
    dolmen.tales,
    dolmen.view,
    keeper,
    gatekeeper,
    grokker
)


# Configuration
CONF = 'config.json'
auth_users = {
    'admin': 'admin',
}

if not os.path.isfile(CONF):
    raise RuntimeError('Configuration file does not exist.')
def setup_module(module):
    testing.setup()
    crom.configure(cromlech.events)
    setup_dispatcher()
Beispiel #21
0
import os
import sys
import json
import crom
import dolmen.tales
import gatekeeper
import keeper
import grokker, dolmen.view, dolmen.forms.base, dolmen.forms.ztk
from dolmen.forms.ztk.fields import registerDefault

# Grokking
crom.monkey.incompat()
crom.implicit.initialize()
registerDefault()

crom.configure(dolmen.forms.base, dolmen.forms.ztk, dolmen.tales, dolmen.view,
               keeper, gatekeeper, grokker)

# Configuration
CONF = 'config.json'
auth_users = {
    'admin': 'admin',
}

if not os.path.isfile(CONF):
    raise RuntimeError('Configuration file does not exist.')

with open(CONF, "r") as fd:
    config = json.load(fd)

# Database
from gatekeeper.admin import Messages
Beispiel #22
0
def setup_module(module):
    """ grok the publish module
    """
    testing.setup()
    setSession(SESSION)
    crom.configure(dolmen.message)