Exemplo n.º 1
0
async def test_parse_metadata(dummy_guillotina):
    from guillotina.contrib.catalog.pg import PGSearchUtility

    util = PGSearchUtility()
    with mocks.MockTransaction():
        content = test_utils.create_content(Container)
        query = parse_query(content, {"_metadata": "foobar"})
        result = util.load_meatdata(query, {"foobar": "foobar", "blah": "blah"})
        assert result == {"foobar": "foobar"}

        query = parse_query(content, {"_metadata_not": "foobar"})
        result = util.load_meatdata(query, {"foobar": "foobar", "blah": "blah"})
        assert result == {"blah": "blah"}
Exemplo n.º 2
0
async def test_fulltext_query_pg_catalog(container_requester):
    from guillotina.contrib.catalog.pg import PGSearchUtility

    async with container_requester as requester:
        await requester(
            "POST",
            "/db/guillotina/",
            data=json.dumps({
                "@type": "Item",
                "id": "item1",
                "title": "Something interesting about foobar"
            }),
        )
        await requester(
            "POST",
            "/db/guillotina/",
            data=json.dumps({
                "@type": "Item",
                "title": "Something else",
                "id": "item2"
            }),
        )

        async with requester.db.get_transaction_manager(
        ) as tm, await tm.begin():
            test_utils.login()
            root = await tm.get_root()
            container = await root.async_get("guillotina")

            util = PGSearchUtility()
            await util.initialize()
            results = await util.search(container, {"title": "something"})
            assert len(results["items"]) == 2
            results = await util.search(container, {"title": "interesting"})
            assert len(results["items"]) == 1
Exemplo n.º 3
0
async def test_fulltext_query_pg_catalog(container_requester):
    from guillotina.contrib.catalog.pg import PGSearchUtility

    async with container_requester as requester:
        await requester('POST',
                        '/db/guillotina/',
                        data=json.dumps({
                            "@type":
                            "Item",
                            "id":
                            "item1",
                            "title":
                            "Something interesting about foobar"
                        }))
        await requester('POST',
                        '/db/guillotina/',
                        data=json.dumps({
                            "@type": "Item",
                            "title": "Something else",
                            "id": "item2",
                        }))

        async with requester.db.get_transaction_manager(
        ) as tm, await tm.begin():
            test_utils.login()
            root = await tm.get_root()
            container = await root.async_get('guillotina')

            util = PGSearchUtility()
            await util.initialize()
            results = await util.query(container, {'title': 'something'})
            assert len(results['member']) == 2
            results = await util.query(container, {'title': 'interesting'})
            assert len(results['member']) == 1
Exemplo n.º 4
0
async def test_query_pg_catalog(container_requester):
    from guillotina.contrib.catalog.pg import PGSearchUtility

    async with container_requester as requester:
        await requester(
            "POST", "/db/guillotina/", data=json.dumps({"@type": "Item", "title": "Item1", "id": "item1"})
        )
        await requester(
            "POST", "/db/guillotina/", data=json.dumps({"@type": "Item", "title": "Item2", "id": "item2"})
        )

        async with requester.db.get_transaction_manager() as tm, await tm.begin():
            test_utils.login()
            root = await tm.get_root()
            container = await root.async_get("guillotina")

            util = PGSearchUtility()
            await util.initialize()
            results = await util.query(container, {"id": "item1"})
            assert len(results["member"]) == 1

            results = await util.query(container, {"_size": "1"})
            assert len(results["member"]) == 1
            results = await util.query(container, {"_size": "1", "_from": "1"})
            assert len(results["member"]) == 1

            results = await util.query_aggregation(container, {"_metadata": "title"})
            assert len(results["member"]) == 2
            assert results["member"][0][0] == "Item1"

            results = await util.query_aggregation(container, {"_metadata": ["title", "creators"]})
            assert len(results["member"]) == 2
            assert results["member"][0][1][0] == "root"
Exemplo n.º 5
0
async def test_build_pg_query(dummy_guillotina):
    from guillotina.contrib.catalog.pg import PGSearchUtility
    util = PGSearchUtility()
    with mocks.MockTransaction():
        content = test_utils.create_content(Container)
        query = parse_query(content, {'uuid': content.uuid}, util)
        assert content.uuid == query['wheres_arguments'][0]
        assert "json->'uuid'" in query['wheres'][0]
Exemplo n.º 6
0
async def test_query_pg_catalog(container_requester):
    from guillotina.contrib.catalog.pg import PGSearchUtility

    async with container_requester as requester:
        await requester('POST',
                        '/db/guillotina/',
                        data=json.dumps({
                            "@type": "Item",
                            "title": "Item1",
                            "id": "item1"
                        }))
        await requester('POST',
                        '/db/guillotina/',
                        data=json.dumps({
                            "@type": "Item",
                            "title": "Item2",
                            "id": "item2",
                        }))

        async with requester.db.get_transaction_manager(
        ) as tm, await tm.begin():
            test_utils.login()
            root = await tm.get_root()
            container = await root.async_get('guillotina')

            util = PGSearchUtility()
            await util.initialize()
            results = await util.query(container, {'id': 'item1'})
            assert len(results['member']) == 1

            results = await util.query(container, {'_size': '1'})
            assert len(results['member']) == 1
            results = await util.query(container, {'_size': '1', '_from': '1'})
            assert len(results['member']) == 1

            results = await util.query_aggregation(container,
                                                   {'_metadata': 'title'})
            assert len(results['member']) == 2
            assert results['member'][0][0] == 'Item1'

            results = await util.query_aggregation(
                container, {'_metadata': ['title', 'creators']})
            assert len(results['member']) == 2
            assert results['member'][0][1][0] == 'root'