Ejemplo n.º 1
0
async def test_navigator_get(container_requester):
    async with container_requester as requester:
        response, status = await requester('POST',
                                           '/db/guillotina/',
                                           data=json.dumps({
                                               "@type": "Folder",
                                               "title": "Folder1",
                                               "id": "folder1"
                                           }))
        response, status = await requester('POST',
                                           '/db/guillotina/folder1',
                                           data=json.dumps({
                                               "@type": "Folder",
                                               "title": "Folder2",
                                               "id": "folder2"
                                           }))
        response, status = await requester('POST',
                                           '/db/guillotina',
                                           data=json.dumps({
                                               "@type": "Item",
                                               "title": "Item0",
                                               "id": "item0"
                                           }))
        response, status = await requester('POST',
                                           '/db/guillotina/folder1',
                                           data=json.dumps({
                                               "@type": "Item",
                                               "title": "Item1",
                                               "id": "item1"
                                           }))
        response, status = await requester('POST',
                                           '/db/guillotina/folder1/folder2',
                                           data=json.dumps({
                                               "@type": "Item",
                                               "title": "Item2",
                                               "id": "item2"
                                           }))
        assert status == 201
        request = get_mocked_request(db=requester.db)
        root = await get_root(request)
        tm = requester.db.get_transaction_manager()
        txn = await tm.begin()
        container = await root.async_get('guillotina')
        item0 = await container.async_get('item0')
        txn.delete(item0)

        nav = Navigator(txn, container)
        item1 = await nav.get('/folder1/item1')
        assert item1.__name__ == 'item1'
        item1_bis = await nav.get('/folder1/item1')
        item2 = await nav.get('/folder1/folder2/item2')
        folder2 = await nav.get('/folder1/folder2')
        assert item2.__parent__ is folder2
        assert item1_bis is item1

        nav.delete(item2)
        assert await nav.get('/folder1/folder2/item2') is None
        assert await nav.get('/folder1/item0') is None

        await tm.abort(txn=txn)
Ejemplo n.º 2
0
async def test_navigator_preload(container_requester):
    async with container_requester as requester:
        response, status = await requester("POST",
                                           "/db/guillotina/",
                                           data=json.dumps({
                                               "@type": "Item",
                                               "title": "Item1",
                                               "id": "item1"
                                           }))
        assert status == 201
        root = await get_root(db=requester.db)
        tm = requester.db.get_transaction_manager()
        txn = await tm.begin()
        container = await root.async_get("guillotina")
        item1 = await container.async_get("item1")
        item1.title = "Item1bis"
        txn.register(item1)

        nav = Navigator(txn, container)
        item1_bis = await nav.get("/item1")

        assert item1_bis.title == "Item1bis"
        assert item1_bis is item1

        await tm.abort(txn=txn)
Ejemplo n.º 3
0
async def test_navigator_preload(container_requester):
    async with container_requester as requester:
        response, status = await requester('POST',
                                           '/db/guillotina/',
                                           data=json.dumps({
                                               "@type": "Item",
                                               "title": "Item1",
                                               "id": "item1"
                                           }))
        assert status == 201
        request = get_mocked_request(requester.db)
        root = await get_root(request)
        txn = await request._tm.begin(request)
        container = await root.async_get('guillotina')
        item1 = await container.async_get('item1')
        item1.title = "Item1bis"
        txn.register(item1)

        nav = Navigator(txn, container)
        item1_bis = await nav.get('/item1')

        assert item1_bis.title == 'Item1bis'
        assert item1_bis is item1

        await request._tm.abort(txn=txn)
Ejemplo n.º 4
0
async def test_navigator_get(container_requester):
    async with container_requester as requester:
        response, status = await requester(
            "POST",
            "/db/guillotina/",
            data=json.dumps({"@type": "Folder", "title": "Folder1", "id": "folder1"}),
        )
        response, status = await requester(
            "POST",
            "/db/guillotina/folder1",
            data=json.dumps({"@type": "Folder", "title": "Folder2", "id": "folder2"}),
        )
        response, status = await requester(
            "POST", "/db/guillotina", data=json.dumps({"@type": "Item", "title": "Item0", "id": "item0"})
        )
        response, status = await requester(
            "POST",
            "/db/guillotina/folder1",
            data=json.dumps({"@type": "Item", "title": "Item1", "id": "item1"}),
        )
        response, status = await requester(
            "POST",
            "/db/guillotina/folder1/folder2",
            data=json.dumps({"@type": "Item", "title": "Item2", "id": "item2"}),
        )
        assert status == 201
        root = await get_root(db=requester.db)
        tm = requester.db.get_transaction_manager()
        txn = await tm.begin()
        container = await root.async_get("guillotina")
        item0 = await container.async_get("item0")
        txn.delete(item0)

        nav = Navigator(txn, container)
        item1 = await nav.get("/folder1/item1")
        assert item1.__name__ == "item1"
        item1_bis = await nav.get("/folder1/item1")
        item2 = await nav.get("/folder1/folder2/item2")
        folder2 = await nav.get("/folder1/folder2")
        assert item2.__parent__ is folder2
        assert item1_bis is item1

        nav.delete(item2)
        assert await nav.get("/folder1/folder2/item2") is None
        assert await nav.get("/folder1/item0") is None

        await tm.abort(txn=txn)
Ejemplo n.º 5
0
async def test_navigator_get(container_requester):
    async with container_requester as requester:
        response, status = await requester(
            'POST',
            '/db/guillotina/',
            data=json.dumps({
                "@type": "Folder",
                "title": "Folder1",
                "id": "folder1"
            }))
        response, status = await requester(
            'POST',
            '/db/guillotina/folder1',
            data=json.dumps({
                "@type": "Folder",
                "title": "Folder2",
                "id": "folder2"
            }))
        response, status = await requester(
            'POST',
            '/db/guillotina',
            data=json.dumps({
                "@type": "Item",
                "title": "Item0",
                "id": "item0"
            }))
        response, status = await requester(
            'POST',
            '/db/guillotina/folder1',
            data=json.dumps({
                "@type": "Item",
                "title": "Item1",
                "id": "item1"
            }))
        response, status = await requester(
            'POST',
            '/db/guillotina/folder1/folder2',
            data=json.dumps({
                "@type": "Item",
                "title": "Item2",
                "id": "item2"
            }))
        assert status == 201
        request = get_mocked_request(requester.db)
        root = await get_root(request)
        txn = await request._tm.begin(request)
        container = await root.async_get('guillotina')
        item0 = await container.async_get('item0')
        txn.delete(item0)

        nav = Navigator(txn, container)
        item1 = await nav.get('/folder1/item1')
        assert item1.__name__ == 'item1'
        item1_bis = await nav.get('/folder1/item1')
        item2 = await nav.get('/folder1/folder2/item2')
        folder2 = await nav.get('/folder1/folder2')
        assert item2.__parent__ is folder2
        assert item1_bis is item1

        nav.delete(item2)
        assert await nav.get('/folder1/folder2/item2') is None
        assert await nav.get('/folder1/item0') is None

        await request._tm.abort(txn=txn)