]> git.jsancho.org Git - datasette-connectors.git/blobdiff - tests/fixtures.py
Test HTTP redirection
[datasette-connectors.git] / tests / fixtures.py
index 4cb60cef297aaf5fe12e21ff3591e94f4c9ea613..f6f695da316234e4e3113a3504cc1e049ff355a7 100644 (file)
@@ -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