-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,67 @@ | ||
import datasette | ||
import pytest | ||
import sqlite3 | ||
from subprocess import Popen, PIPE | ||
import sys | ||
import time | ||
import httpx | ||
|
||
|
||
def pytest_report_header(): | ||
return "Datasette: {}".format(datasette.__version__) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ds_server(tmp_path_factory): | ||
tmpdir = tmp_path_factory.mktemp("tmp") | ||
db_path = str(tmpdir / "data.db") | ||
db = sqlite3.connect(db_path) | ||
for latitude, longitude in ( | ||
("latitude", "longitude"), | ||
("lat", "lon"), | ||
("lat", "lng"), | ||
("lat", "long"), | ||
("foo_latitude", "foo_longitude"), | ||
): | ||
with db: | ||
db.execute( | ||
f""" | ||
create table {latitude}_{longitude} ( | ||
id integer primary key, | ||
{latitude} float, | ||
{longitude} float | ||
) | ||
""" | ||
) | ||
db.execute( | ||
f""" | ||
insert into {latitude}_{longitude} ({latitude}, {longitude}) | ||
values (37.0167, -122.0024), (37.3184, -121.9511) | ||
""" | ||
) | ||
process = Popen( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"datasette", | ||
"--port", | ||
"8126", | ||
str(db_path), | ||
], | ||
stdout=PIPE, | ||
) | ||
wait_until_responds("http://localhost:8126/") | ||
yield "http://localhost:8126" | ||
process.terminate() | ||
process.wait() | ||
|
||
|
||
def wait_until_responds(url, timeout=5.0): | ||
start = time.time() | ||
while time.time() - start < timeout: | ||
try: | ||
httpx.get(url) | ||
return | ||
except httpx.ConnectError: | ||
time.sleep(0.1) | ||
raise AssertionError("Timed out waiting for {} to respond".format(url)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
try: | ||
from playwright import sync_api | ||
except ImportError: | ||
sync_api = None | ||
import pytest | ||
import nest_asyncio | ||
|
||
nest_asyncio.apply() | ||
|
||
pytestmark = pytest.mark.skipif(sync_api is None, reason="playwright not installed") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"table", | ||
( | ||
"foo_latitude_foo_longitude", | ||
"lat_lng", | ||
"lat_lon", | ||
"lat_long", | ||
"latitude_longitude", | ||
), | ||
) | ||
def test_blah(ds_server, table, page): | ||
page.goto(ds_server + "/data/" + table) | ||
# There should be two leaflet-marker-icons | ||
page.wait_for_selector(".leaflet-marker-icon", timeout=15000) | ||
assert len(page.query_selector_all(".leaflet-marker-icon")) == 2 |