Skip to content

Commit

Permalink
allow for types not in a list
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Feb 2, 2024
1 parent 9513ca9 commit bf8c3ec
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ jobs:
- name: Run tests
run: |
hatch run test
lint:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
run: |
pip install -e .[lint]
pip install hatch
- name: Run lint
run: |
hatch run lint:style
deploy:
runs-on: ubuntu-latest
needs: [test]
needs: [test, lint]
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion src/datasette_reconcile/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-present David Kane <david@dkane.net>
#
# SPDX-License-Identifier: MIT
__version__ = "0.6.0"
__version__ = "0.6.1"
2 changes: 2 additions & 0 deletions src/datasette_reconcile/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ async def _reconcile_queries(self, queries):
params["search_query"] = f"%{query['query']}%"

types = query.get("type", [])
if not isinstance(types, list) and types:
types = [types]
type_field = self.config.get("type_field")
if types and type_field:
where_clauses.append(
Expand Down
25 changes: 25 additions & 0 deletions tests/test_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,31 @@ async def test_response_suggest_type_1(db_path):

@pytest.mark.asyncio
async def test_response_queries_post_type(db_path):
app = Datasette([db_path], metadata=plugin_metadata({"name_field": "name", "type_field": "status"})).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", "type": "bad dog"}})},
)
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": "bad dog",
"id": "bad dog",
}
]
assert response.headers["Access-Control-Allow-Origin"] == "*"


@pytest.mark.asyncio
async def test_response_queries_post_type_list(db_path):
app = Datasette([db_path], metadata=plugin_metadata({"name_field": "name", "type_field": "status"})).app()
async with httpx.AsyncClient(app=app) as client:
response = await client.post(
Expand Down

0 comments on commit bf8c3ec

Please sign in to comment.