Exemple #1
0
def test_suggested_facets(app_client):
    suggestions = [
        {
            "name": suggestion["name"],
            "querystring": suggestion["toggle_url"].split("?")[-1],
        }
        for suggestion in app_client.get("/fixtures/facetable.json").json[
            "suggested_facets"
        ]
    ]
    expected = [
        {"name": "planet_int", "querystring": "_facet=planet_int"},
        {"name": "on_earth", "querystring": "_facet=on_earth"},
        {"name": "state", "querystring": "_facet=state"},
        {"name": "city_id", "querystring": "_facet=city_id"},
        {"name": "neighborhood", "querystring": "_facet=neighborhood"},
        {"name": "tags", "querystring": "_facet=tags"},
    ]
    if detect_json1():
        expected.append({"name": "tags", "querystring": "_facet_array=tags"})
    assert expected == suggestions
Exemple #2
0
def register_facet_classes():
    classes = [ColumnFacet, DateFacet, ManyToManyFacet]
    if detect_json1():
        classes.append(ArrayFacet)
    return classes
Exemple #3
0
                {
                    "value": 4,
                    "label": "Memnonia",
                    "count": 1,
                    "toggle_url": "http://localhost/?city_id=4",
                    "selected": False,
                },
            ],
            "truncated":
            False,
        }
    } == buckets


@pytest.mark.asyncio
@pytest.mark.skipif(not detect_json1(),
                    reason="Requires the SQLite json1 module")
async def test_array_facet_suggest(app_client):
    facet = ArrayFacet(
        app_client.ds,
        MockRequest("http://localhost/"),
        database="fixtures",
        sql="select * from facetable",
        table="facetable",
    )
    suggestions = await facet.suggest()
    assert [{
        "name": "tags",
        "type": "array",
        "toggle_url": "http://localhost/?_facet_array=tags",
    }] == suggestions
Exemple #4
0
                },
                {
                    "value": 4,
                    "label": "Memnonia",
                    "count": 1,
                    "toggle_url": "http://localhost/?_city_id__exact=4",
                    "selected": False,
                },
            ],
            "truncated": False,
        }
    ] == buckets


@pytest.mark.asyncio
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
async def test_array_facet_suggest(app_client):
    facet = ArrayFacet(
        app_client.ds,
        Request.fake("/"),
        database="fixtures",
        sql="select * from facetable",
        table="facetable",
    )
    suggestions = await facet.suggest()
    assert [
        {
            "name": "tags",
            "type": "array",
            "toggle_url": "http://localhost/?_facet_array=tags",
        }