ripgrep
datasette/tests/test_utils.py
439
440 def test_check_connection_spatialite_raises():
441 path = str(pathlib.Path(__file__).parent / "spatialite.db")
442 conn = sqlite3.connect(path)
443 with pytest.raises(utils.SpatialiteConnectionProblem):
573 async def test_initial_path_for_datasette(tmp_path_factory, dbs, expected_path):
574 db_dir = tmp_path_factory.mktemp("dbs")
575 one_table = str(db_dir / "one.db")
576 sqlite3.connect(one_table).execute("create table one (id integer primary key)")
577 two_tables = str(db_dir / "two.db")
578 sqlite3.connect(two_tables).execute("create table two (id integer primary key)")
579 sqlite3.connect(two_tables).execute("create table three (id integer primary key)")
datasette/tests/test_table_html.py
915 def test_custom_table_include():
916 with make_app_client(
917 template_dir=str(pathlib.Path(__file__).parent / "test_templates")
918 ) as client:
919 response = client.get("/fixtures/complex_foreign_keys")
datasette/tests/test_publish_heroku.py
147 with open("test.db", "w") as fp:
148 fp.write("data")
149 output = str(tmp_path_factory.mktemp("generate_dir") / "output")
150 result = runner.invoke(
151 cli.cli,
161 path = pathlib.Path(output)
162 assert path.exists()
163 file_names = {str(r.relative_to(path)) for r in path.glob("*")}
164 assert file_names == {
165 "requirements.txt",
datasette/tests/test_plugins.py
323 def test_hook_extra_template_vars(restore_working_directory):
324 with make_app_client(
325 template_dir=str(pathlib.Path(__file__).parent / "test_templates")
326 ) as client:
327 response = client.get("/-/metadata")
349 def test_plugins_async_template_function(restore_working_directory):
350 with make_app_client(
351 template_dir=str(pathlib.Path(__file__).parent / "test_templates")
352 ) as client:
353 response = client.get("/-/metadata")
401 "utf-8",
402 )
403 db_path = str(tmpdir / "fixtures.db")
404 conn = sqlite3.connect(db_path)
405 conn.executescript(TABLES)
datasette/tests/test_internals_datasette.py
157 def test_datasette_error_if_string_not_list(tmpdir):
158 # https://github.com/simonw/datasette/issues/1985
159 db_path = str(tmpdir / "data.db")
160 with pytest.raises(ValueError):
161 ds = Datasette(db_path)
datasette/tests/test_html.py
83 def test_static_mounts():
84 with make_app_client(
85 static_mounts=[("custom-static", str(pathlib.Path(__file__).parent))]
86 ) as client:
87 response = client.get("/custom-static/test_html.py")
datasette/tests/test_internals_database.py
507 @pytest.mark.timeout(1)
508 async def test_execute_write_fn_connection_exception(tmpdir, app_client):
509 path = str(tmpdir / "immutable.db")
510 sqlite3.connect(path).execute("vacuum")
511 db = Database(app_client.ds, path=path, is_mutable=False)
datasette/tests/test_custom_pages.py
3 from .fixtures import make_app_client
4
5 TEST_TEMPLATE_DIRS = str(pathlib.Path(__file__).parent / "test_templates")
6
7
datasette/tests/test_config_dir.py
53
54 for dbname in ("demo.db", "immutable.db", "j.sqlite3", "k.sqlite"):
55 db = sqlite3.connect(str(config_dir / dbname))
56 db.executescript(
57 """
datasette/tests/test_crossdb.py
41 dbs = []
42 for i in range(11):
43 path = str(db_dir / "db_{}.db".format(i))
44 conn = sqlite3.connect(path)
45 conn.execute("vacuum")
datasette/tests/test_cli.py
71 runner = CliRunner()
72 result = runner.invoke(
73 cli, ["serve", str(pathlib.Path(__file__).parent / "spatialite.db")]
74 )
75 assert result.exit_code != 0
89 [
90 "serve",
91 str(pathlib.Path(__file__).parent / "spatialite.db"),
92 "--load-extension",
93 "spatialite",
189 path.write("datasette-mock-plugin\ndatasette-plugin-2")
190 runner = CliRunner()
191 runner.invoke(cli, ["install", "-r", str(path)])
192 run_module.assert_called_once_with("pip", run_name="__main__")
193 assert sys.argv == ["pip", "install", "-r", str(path)]
194
195
241 def test_plugin_s_overwrite():
242 runner = CliRunner()
243 plugins_dir = str(pathlib.Path(__file__).parent / "plugins")
244
245 result = runner.invoke(
318 assert not db_path.exists()
319 result = runner.invoke(
320 cli, [str(db_path), "--create", "--get", "/-/databases.json"]
321 )
322 assert result.exit_code == 0, result.output
346 [
347 argument,
348 str(config_path),
349 "--get",
350 "/-/settings.json",
358 "'datasette db.db nested/db.db' should attach two databases, /db and /db_2"
359 runner = CliRunner()
360 db_1_path = str(tmpdir / "db.db")
361 nested = tmpdir / "nested"
362 nested.mkdir()
363 db_2_path = str(tmpdir / "nested" / "db.db")
364 for path in (db_1_path, db_2_path):
365 sqlite3.connect(path).execute("vacuum")
373 "'datasette db.db db.db' should only attach one database, /db"
374 runner = CliRunner()
375 db_path = str(tmpdir / "db.db")
376 sqlite3.connect(db_path).execute("vacuum")
377 result = runner.invoke(cli, [db_path, db_path, "--get", "/-/databases.json"])
415 assert not internal_path.exists()
416 result = runner.invoke(
417 cli, ["--memory", "--internal", str(internal_path), "--get", "/"]
418 )
419 assert result.exit_code == 0
datasette/tests/test_api_write.py
8 def ds_write(tmp_path_factory):
9 db_directory = tmp_path_factory.mktemp("dbs")
10 db_path = str(db_directory / "data.db")
11 db_path_immutable = str(db_directory / "immutable.db")
12 db1 = sqlite3.connect(str(db_path))
13 db2 = sqlite3.connect(str(db_path_immutable))
14 for db in (db1, db2):
15 db.execute("vacuum")
datasette/tests/fixtures.py
18 TEMP_PLUGIN_SECRET_FILE = os.path.join(tempfile.gettempdir(), "plugin-secret")
19
20 PLUGINS_DIR = str(pathlib.Path(__file__).parent / "plugins")
21
22 EXPECTED_PLUGINS = [
datasette/tests/conftest.py
188 # https://github.com/simonw/datasette/issues/1407 - so I switched to
189 # using tempfile.gettempdir()
190 uds = str(pathlib.Path(tempfile.gettempdir()) / "datasette.sock")
191 ds_proc = subprocess.Popen(
192 ["datasette", "--memory", "--uds", uds],
datasette/datasette/views/table.py
194 base_url=base_url,
195 table_path=datasette.urls.table(database_name, table_name),
196 flat_pks=str(markupsafe.escape(pk_path)),
197 flat_pks_quoted=path_from_row_pks(row, pks, not pks),
198 )
datasette/datasette/utils/asgi.py
287 headers["content-disposition"] = f'attachment; filename="{filename}"'
288 first = True
289 headers["content-length"] = str((await aiofiles.os.stat(str(filepath))).st_size)
290 async with aiofiles.open(str(filepath), mode="rb") as fp:
291 if first:
292 await asgi_start(
294 200,
295 headers,
296 content_type or guess_type(str(filepath))[0] or "text/plain",
297 )
298 first = False
datasette/datasette/app.py
274 for ext in ("db", "sqlite", "sqlite3"):
275 db_files.extend(config_dir.glob("*.{}".format(ext)))
276 self.files += tuple(str(f) for f in db_files)
277 if (
278 config_dir
483 continue
484 placeholders = "(?, ?, ?, ?)"
485 values = [database_name, str(db.path), db.is_memory, schema_version]
486 if db.path is None:
487 placeholders = "(?, null, ?, ?)"