Skip to content

Commit

Permalink
Initial Playwright test, refs #19
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 8, 2024
1 parent 008c1ab commit a4fb99c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,29 @@ You can also navigate to `/-/search` on your Datasette instance to use the searc
## Screenshot

![Animated screenshot showing the plugin in action](https://raw.githubusercontent.com/simonw/datasette-search-all/main/animated-screenshot.gif)

## Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:
```bash
cd datasette-search-all
python -m venv venv
source venv/bin/activate
```
Or if you are using `pipenv`:
```bash
pipenv shell
```
Now install the dependencies and tests:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```
To run the browser automation tests:
```bash
pip install -e '.[test,playwright]'
pytest
```
1 change: 1 addition & 0 deletions datasette_search_all/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def search_all(datasette, request):
def extra_template_vars(template, datasette, request):
if template != "index.html":
return

# Add list of searchable tables
async def inner():
searchable_tables = list(await get_searchable_tables(datasette, request))
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def get_long_description():
package_data={"datasette_search_all": ["templates/*.html"]},
install_requires=["datasette>=0.63.1"],
python_requires=">=3.7",
extras_require={"test": ["pytest", "pytest-asyncio", "sqlite-utils"]},
tests_require=["datasette-search-all[test]"],
extras_require={
"test": ["pytest", "pytest-asyncio", "sqlite-utils"],
"playwright": ["pytest-playwright"]
},
)
18 changes: 1 addition & 17 deletions tests/test_search_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
import json


@pytest.fixture
def db_path(tmpdir):
path = str(tmpdir / "data.db")
db = sqlite_utils.Database(path)
db["creatures"].insert_all(
[
{"name": "Cleo", "description": "A medium sized dog"},
{"name": "Siroco", "description": "A troublesome Kakapo"},
]
)
return path


@pytest.mark.asyncio
async def test_no_form_on_index_if_not_searchable(db_path):
datasette = Datasette([db_path])
Expand Down Expand Up @@ -49,10 +36,7 @@ async def test_shows_nav_menu_if_searchable(db_path):
datasette = Datasette([db_path])
response = await datasette.client.get("/")
assert response.status_code == 200
for fragment in (
'<details class="nav-menu',
'"/-/search">Search all tables</a>'
):
for fragment in ('<details class="nav-menu', '"/-/search">Search all tables</a>'):
assert fragment in response.text


Expand Down

0 comments on commit a4fb99c

Please sign in to comment.