Beispiel #1
0
async def test_add_behavior(dummy_guillotina):
    utils.login()

    async with transaction(db=await get_database("db")):
        container = await create_content("Container",
                                         id="guillotina",
                                         title="Guillotina")
        container.__name__ = "guillotina"
        utils.register(container)

        item = await create_content_in_container(container,
                                                 "Item",
                                                 id_="foobar")
        with pytest.raises(AttributeError):
            item.add_behavior(123)

        with pytest.raises(ComponentLookupError):
            item.add_behavior("foo")

        all_behaviors = await get_all_behaviors(item)
        assert len(all_behaviors) == 1
        assert all_behaviors[0][0] == IDublinCore

        # IDublinCore already exists and check it is not added
        item.add_behavior(IDublinCore.__identifier__)
        assert len(item.__behaviors__) == 0
        assert len(await get_all_behaviors(item)) == 1

        # Manually add IDublinCore and check it is not returned twice
        item.__behaviors__ |= {IDublinCore.__identifier__}
        assert len(await get_all_behaviors(item)) == 1

        item.add_behavior(IAttachment)
        assert len(await get_all_behaviors(item)) == 2
Beispiel #2
0
async def test_creator_used_from_content_creation(dummy_guillotina):
    utils.login()

    async with transaction(db=await get_database("db")):
        container = await create_content("Container", id="guillotina", title="Guillotina")
        container.__name__ = "guillotina"
        utils.register(container)

        import guillotina.tests

        configure.register_configuration(
            Folder,
            dict(
                type_name="TestType2", behaviors=[], module=guillotina.tests
            ),  # for registration initialization
            "contenttype",
        )
        root = get_utility(IApplication, name="root")

        configure.load_configuration(root.app.config, "guillotina.tests", "contenttype")
        root.app.config.execute_actions()
        load_cached_schema()

        obj = await create_content_in_container(
            container, "TestType2", "foobar", creators=("root",), contributors=("root",)
        )

        assert obj.creators == ("root",)
        assert obj.contributors == ("root",)

        behavior = IDublinCore(obj)
        assert behavior.creators == ("root",)
        assert behavior.contributors == ("root",)
Beispiel #3
0
async def test_allowed_types(dummy_guillotina):
    utils.login()

    async with transaction(db=await get_database("db")):
        container = await create_content("Container", id="guillotina", title="Guillotina")
        container.__name__ = "guillotina"
        utils.register(container)

        import guillotina.tests

        configure.register_configuration(
            Folder,
            dict(
                type_name="TestType",
                allowed_types=["Item"],
                module=guillotina.tests,  # for registration initialization
            ),
            "contenttype",
        )
        root = get_utility(IApplication, name="root")

        configure.load_configuration(root.app.config, "guillotina.tests", "contenttype")
        root.app.config.execute_actions()
        load_cached_schema()

        obj = await create_content_in_container(container, "TestType", "foobar")

        constrains = IConstrainTypes(obj, None)
        assert constrains.get_allowed_types() == ["Item"]
        assert constrains.is_type_allowed("Item")

        with pytest.raises(NotAllowedContentType):
            await create_content_in_container(obj, "TestType", "foobar")
        await create_content_in_container(obj, "Item", "foobar")
Beispiel #4
0
async def test_allowed_types(dummy_guillotina):
    utils.login()

    container = await create_content('Container',
                                     id='guillotina',
                                     title='Guillotina')
    container.__name__ = 'guillotina'
    utils.register(container)

    import guillotina.tests
    configure.register_configuration(
        Folder,
        dict(
            type_name="TestType",
            allowed_types=['Item'],
            module=guillotina.tests  # for registration initialization
        ),
        'contenttype')
    root = get_utility(IApplication, name='root')

    configure.load_configuration(root.app.config, 'guillotina.tests',
                                 'contenttype')
    root.app.config.execute_actions()
    load_cached_schema()

    obj = await create_content_in_container(container, 'TestType', 'foobar')

    constrains = IConstrainTypes(obj, None)
    assert constrains.get_allowed_types() == ['Item']
    assert constrains.is_type_allowed('Item')

    with pytest.raises(NotAllowedContentType):
        await create_content_in_container(obj, 'TestType', 'foobar')
    await create_content_in_container(obj, 'Item', 'foobar')
Beispiel #5
0
async def test_allowed_to_create_content(dummy_guillotina):
    utils.login()

    async with transaction(db=await get_database("db")):
        container = await create_content("Container", id="guillotina", title="Guillotina")
        container.__name__ = "guillotina"
        utils.register(container)

        await create_content_in_container(container, "Item", id_="foobar")
Beispiel #6
0
async def test_allowed_to_create_content(dummy_guillotina):
    utils.login()

    container = await create_content('Container',
                                     id='guillotina',
                                     title='Guillotina')
    container.__name__ = 'guillotina'
    utils.register(container)

    await create_content_in_container(container, 'Item', id_='foobar')
Beispiel #7
0
async def test_globally_addable_types(dummy_guillotina):
    utils.login()

    async with transaction(db=await get_database("db")):
        container = await create_content("Container",
                                         id="guillotina",
                                         title="Guillotina")
        container.__name__ = "guillotina"
        utils.register(container)

        import guillotina.tests

        # Define BarType which is not globally addable
        configure.register_configuration(
            Folder,
            dict(type_name="BarType",
                 module=guillotina.tests,
                 globally_addable=False), "contenttype")

        # Define the only content where BarType is addable
        configure.register_configuration(
            Folder,
            dict(type_name="FooType",
                 allowed_types=["BarType"],
                 module=guillotina.tests),
            "contenttype",
        )

        root = get_utility(IApplication, name="root")

        configure.load_configuration(root.app.config, "guillotina.tests",
                                     "contenttype")
        root.app.config.execute_actions()
        load_cached_schema()

        # Check that BarType can be added in FooType
        foo = await create_content_in_container(container, "FooType", "foo")
        await create_content_in_container(foo, "BarType", "bar")

        # Check that BarType cannot be globally added
        with pytest.raises(NotAllowedContentType):
            await create_content_in_container(container, "BarType", "bar")

        # Check it can be bypassed
        await create_content_in_container(container,
                                          "BarType",
                                          "bar",
                                          check_constraints=False)
Beispiel #8
0
async def test_creator_used_from_content_creation(dummy_guillotina):
    utils.login()

    container = await create_content('Container',
                                     id='guillotina',
                                     title='Guillotina')
    container.__name__ = 'guillotina'
    utils.register(container)

    import guillotina.tests
    configure.register_configuration(
        Folder,
        dict(
            type_name="TestType2",
            behaviors=[],
            module=guillotina.tests  # for registration initialization
        ),
        'contenttype')
    root = get_utility(IApplication, name='root')

    configure.load_configuration(root.app.config, 'guillotina.tests',
                                 'contenttype')
    root.app.config.execute_actions()
    load_cached_schema()

    obj = await create_content_in_container(container,
                                            'TestType2',
                                            'foobar',
                                            creators=('root', ),
                                            contributors=('root', ))

    assert obj.creators == ('root', )
    assert obj.contributors == ('root', )

    behavior = IDublinCore(obj)
    assert behavior.creators == ('root', )
    assert behavior.contributors == ('root', )