예제 #1
0
async def test_servce_manifest_view_url_default(db_path):
    app = Datasette([db_path],
                    metadata=plugin_metadata({"name_field": "name"})).app()
    async with httpx.AsyncClient(app=app) as client:
        response = await client.get("http://localhost/test/dogs/-/reconcile")
        assert 200 == response.status_code
        data = response.json()
        assert data["view"]["url"] == "http://localhost/test/dogs/{{id}}"
예제 #2
0
async def test_response_queries_no_results_get(db_path):
    app = Datasette([db_path],
                    metadata=plugin_metadata({"name_field": "name"})).app()
    async with httpx.AsyncClient(app=app) as client:
        queries = json.dumps({"q0": {"query": "abcdef"}})
        response = await client.get(
            "http://localhost/test/dogs/-/reconcile?queries={}".format(queries)
        )
        assert 200 == response.status_code
        data = response.json()
        assert "q0" in data.keys()
        assert len(data["q0"]["result"]) == 0
        assert response.headers["Access-Control-Allow-Origin"] == "*"
예제 #3
0
async def test_servce_manifest_view_url_custom(db_path):
    custom_view_url = "https://example.com/{{id}}"
    app = Datasette(
        [db_path],
        metadata=plugin_metadata({
            "name_field": "name",
            "view_url": custom_view_url,
        }),
    ).app()
    async with httpx.AsyncClient(app=app) as client:
        response = await client.get("http://localhost/test/dogs/-/reconcile")
        assert 200 == response.status_code
        data = response.json()
        assert data["view"]["url"] == custom_view_url
예제 #4
0
async def test_response_without_query(db_path):
    app = Datasette([db_path],
                    metadata=plugin_metadata({"name_field": "name"})).app()
    async with httpx.AsyncClient(app=app) as client:
        response = await client.get("http://localhost/test/dogs/-/reconcile")
        assert 200 == response.status_code
        data = response.json()
        assert "name" in data.keys()
        assert isinstance(data["defaultTypes"], list)
        assert len(data["defaultTypes"]) == 1
        assert data["defaultTypes"][0]["id"] == "object"
        assert data["defaultTypes"][0]["name"] == "Object"
        assert data["view"]["url"].startswith("http")
        assert response.headers["Access-Control-Allow-Origin"] == "*"
async def test_schema_manifest(db_path):
    schemas = get_schema("manifest.json")

    app = Datasette([db_path],
                    metadata=plugin_metadata({"name_field": "name"})).app()
    async with httpx.AsyncClient(app=app) as client:
        response = await client.get("http://localhost/test/dogs/-/reconcile")
        data = response.json()
        for schema_version, schema in schemas.items():
            print("Schema version: {}".format(schema_version))
            jsonschema.validate(
                instance=data,
                schema=schema,
                cls=jsonschema.Draft7Validator,
            )
async def test_response_queries_no_results_schema_get(db_path):
    schemas = get_schema("reconciliation-result-batch.json")
    app = Datasette([db_path],
                    metadata=plugin_metadata({"name_field": "name"})).app()
    async with httpx.AsyncClient(app=app) as client:
        queries = json.dumps({"q0": {"query": "abcdef"}})
        response = await client.get(
            "http://localhost/test/dogs/-/reconcile?queries={}".format(queries)
        )
        assert 200 == response.status_code
        data = response.json()
        for schema_version, schema in schemas.items():
            print("Schema version: {}".format(schema_version))
            jsonschema.validate(
                instance=data,
                schema=schema,
                cls=jsonschema.Draft7Validator,
            )
예제 #7
0
async def test_response_queries_post(db_path):
    app = Datasette([db_path],
                    metadata=plugin_metadata({"name_field": "name"})).app()
    async with httpx.AsyncClient(app=app) as client:
        response = await client.post(
            "http://localhost/test/dogs/-/reconcile",
            data={"queries": json.dumps({"q0": {
                "query": "fido"
            }})},
        )
        assert 200 == response.status_code
        data = response.json()
        assert "q0" in data.keys()
        assert len(data["q0"]["result"]) == 1
        result = data["q0"]["result"][0]
        assert result["id"] == "3"
        assert result["name"] == "Fido"
        assert result["score"] == 100
        assert result["type"] == [{
            "name": "Object",
            "id": "object",
        }]
        assert response.headers["Access-Control-Allow-Origin"] == "*"