X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=tests%2Ffixtures.py;h=a93c2afcdd0d52aa99835444366bcdefb2a4b5c2;hb=716ff0016ebb03dbef77fd4a9c6b2f8f9781cb58;hp=70a59d841c772eaf95c79d884e403c7d2f19d543;hpb=52416a749fac092a032a8b5239e477dd68180dfa;p=datasette-connectors.git diff --git a/tests/fixtures.py b/tests/fixtures.py index 70a59d8..a93c2af 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -8,26 +8,52 @@ from datasette.utils.testing import TestClient import os import pytest import tempfile +import contextlib -@pytest.fixture(scope='session') -def app_client(max_returned_rows=None): +def populate_file(filepath): + dummyfile = open(filepath, "w") + dummyfile.write("This is a dummy file. We need something to force a SQLite error") + dummyfile.close() + + +@contextlib.contextmanager +def make_app_client( + max_returned_rows=None, + config=None, + is_immutable=False, +): with tempfile.TemporaryDirectory() as tmpdir: filepath = os.path.join(tmpdir, 'dummy_tables.db') populate_file(filepath) + if is_immutable: + files = [] + immutables = [filepath] + else: + files = [filepath] + immutables = [] + config = config or {} + config.update({ + 'default_page_size': 50, + 'max_returned_rows': max_returned_rows or 1000, + }) ds = Datasette( - [filepath], - config={ - 'default_page_size': 50, - 'max_returned_rows': max_returned_rows or 1000, - } + files, + immutables=immutables, + config=config, ) client = TestClient(ds.app()) client.ds = ds yield client -def populate_file(filepath): - dummyfile = open(filepath, "w") - dummyfile.write("This is a dummy file. We need something to force a SQLite error") - dummyfile.close() +@pytest.fixture(scope='session') +def app_client(): + with make_app_client() as client: + yield client + + +@pytest.fixture(scope='session') +def app_client_with_hash(): + with make_app_client(config={"hash_urls": True}, is_immutable=True) as client: + yield client