Exemplo n.º 1
0
async def test_register_behavior(container_requester):
    cur_count = len(
        configure.get_configurations("guillotina.tests", "behavior"))

    from guillotina.interfaces import IResource
    from guillotina import schema

    class IMyBehavior(Interface):
        foobar = schema.Text()

    class IMyBehavior2(Interface):
        foobar = schema.Text()

    configure.behavior(
        title="MyBehavior",
        provides=IMyBehavior,
        factory="guillotina.behaviors.instance.AnnotationBehavior",
        for_="guillotina.interfaces.IResource",
    )()
    configure.behavior(
        title="MyBehavior2",
        provides=IMyBehavior2,
        factory="guillotina.behaviors.instance.AnnotationBehavior",
        for_="guillotina.interfaces.IResource",
    )()

    assert len(configure.get_configurations("guillotina.tests",
                                            "behavior")) == cur_count + 2

    class IMyType(IResource):
        pass

    class MyType(Item):
        pass

    configure.register_configuration(
        MyType,
        dict(context=IContainer,
             schema=IMyType,
             type_name="MyType2",
             behaviors=[IMyBehavior]),
        "contenttype",
    )

    root = get_utility(IApplication, name="root")
    config = root.app.config
    # now test it...
    configure.load_configuration(config, "guillotina.tests", "contenttype")
    configure.load_configuration(config, "guillotina.tests", "behavior")
    config.execute_actions()

    async with container_requester as requester:
        response, status = await requester("GET", "/db/guillotina/@types")
        type_ = [s for s in response if s["title"] == "MyType2"][0]
        assert "foobar" in type_["definitions"][
            "guillotina.tests.test_configure.IMyBehavior"]["properties"]

    # also get_all_possible_schemas_for_type should come with this new behavior
    behaviors_schemas = get_all_possible_schemas_for_type("MyType2")
    assert IMyBehavior2 in behaviors_schemas
Exemplo n.º 2
0
async def test_register_behavior(container_requester):
    cur_count = len(
        configure.get_configurations('guillotina.tests', 'behavior'))

    from guillotina.interfaces import IFormFieldProvider, IResource
    from zope.interface import provider
    from guillotina import schema

    @provider(IFormFieldProvider)
    class IMyBehavior(Interface):
        foobar = schema.Text()

    class IMyBehavior2(Interface):
        foobar = schema.Text()

    configure.behavior(
        title="MyBehavior",
        provides=IMyBehavior,
        factory="guillotina.behaviors.instance.AnnotationBehavior",
        for_="guillotina.interfaces.IResource"
    )()
    configure.behavior(
        title="MyBehavior2",
        provides=IMyBehavior2,
        factory="guillotina.behaviors.instance.AnnotationBehavior",
        for_="guillotina.interfaces.IResource"
    )()

    assert len(configure.get_configurations('guillotina.tests', 'behavior')) == cur_count + 2

    class IMyType(IResource):
        pass

    class MyType(Item):
        pass

    configure.register_configuration(MyType, dict(
        context=IContainer,
        schema=IMyType,
        type_name="MyType2",
        behaviors=[IMyBehavior]
    ), 'contenttype')

    root = getUtility(IApplication, name='root')
    config = root.app.config
    # now test it...
    configure.load_configuration(config, 'guillotina.tests', 'contenttype')
    configure.load_configuration(config, 'guillotina.tests', 'behavior')
    config.execute_actions()

    async with await container_requester as requester:
        response, status = await requester('GET', '/db/guillotina/@types')
        type_ = [s for s in response if s['title'] == 'MyType2'][0]
        assert 'foobar' in type_['definitions']['IMyBehavior']['properties']

    # also get_all_possible_schemas_for_type should come with this new behavior
    behaviors_schemas = get_all_possible_schemas_for_type('MyType2')
    assert IMyBehavior2 in behaviors_schemas
Exemplo n.º 3
0
async def test_register_behavior(site_requester):
    cur_count = len(
        configure.get_configurations('guillotina.tests', 'behavior'))

    from guillotina.interfaces import IFormFieldProvider
    from zope.interface import provider
    from guillotina import schema

    @provider(IFormFieldProvider)
    class IMyBehavior(Interface):
        foobar = schema.Text()

    configure.behavior(
        title="MyBehavior",
        provides=IMyBehavior,
        factory="guillotina.behaviors.instance.AnnotationBehavior",
        for_="guillotina.interfaces.IResource")()

    assert len(configure.get_configurations('guillotina.tests',
                                            'behavior')) == cur_count + 1

    class IMyType(Interface):
        pass

    class MyType(Item):
        pass

    configure.register_configuration(
        MyType,
        dict(context=ISite,
             schema=IMyType,
             portal_type="MyType2",
             behaviors=[IMyBehavior]), 'contenttype')

    async with await site_requester as requester:
        config = requester.root.app.config
        # now test it...
        configure.load_configuration(config, 'guillotina.tests', 'contenttype')
        config.execute_actions()

        response, status = await requester('GET', '/db/guillotina/@types')
        type_ = [s for s in response if s['title'] == 'MyType2'][0]
        assert 'foobar' in type_['definitions']['IMyBehavior']['properties']