X-Git-Url: https://git.jsancho.org/?p=datasette-connectors.git;a=blobdiff_plain;f=tests%2Ffixtures.py;fp=tests%2Ffixtures.py;h=f6f695da316234e4e3113a3504cc1e049ff355a7;hp=4cb60cef297aaf5fe12e21ff3591e94f4c9ea613;hb=f1dd3e8c2e09f511840c1cfa8243fb83a6174705;hpb=5c00383b9044ca27de9c51a511962ffad65ed5f3 diff --git a/tests/fixtures.py b/tests/fixtures.py index 4cb60ce..f6f695d 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