ripgrep
til/pytest/registering-plugins-in-tests.md
53 @pytest.mark.asyncio
54 async def test_insert_alter(ds, unsafe):
55 async with httpx.AsyncClient(app=ds.app()) as client:
56 response = await client.post(
57 "http://localhost/-/insert/data/dogs?pk=id",
til/asgi/lifespan-test-httpx.md
23 app = ds.app()
24 async with LifespanManager(app):
25 async with httpx.AsyncClient(app=app) as client:
26 response = await client.get("http://localhost/-/asgi-scope")
27 assert 200 == response.status_code
dogsheep-beta/tests/test_plugin.py
12 @pytest.mark.asyncio
13 async def test_search(ds):
14 async with httpx.AsyncClient(app=ds.app()) as client:
15 response = await client.get("http://localhost/-/beta")
16 assert 200 == response.status_code
141 )
142 async def test_advanced_search(ds, q, expected):
143 async with httpx.AsyncClient(app=ds.app()) as client:
144 response = await client.get(
145 "http://localhost/-/beta?" + urllib.parse.urlencode({"q": q})
173 )
174 async def test_search_order(ds, sort, expected):
175 async with httpx.AsyncClient(app=ds.app()) as client:
176 q = "email"
177 response = await client.get(
213 )
214 async def test_search_order_for_timeline(ds, sort, expected):
215 async with httpx.AsyncClient(app=ds.app()) as client:
216 url = "http://localhost/-/beta"
217 if sort:
234 @pytest.mark.asyncio
235 async def test_fixture(ds):
236 async with httpx.AsyncClient(app=ds.app()) as client:
237 response = await client.get("http://localhost/-/databases.json")
238 assert 200 == response.status_code
243 async def test_plugin_is_installed():
244 app = Datasette([], memory=True).app()
245 async with httpx.AsyncClient(app=app) as client:
246 response = await client.get("http://localhost/-/plugins.json")
247 assert 200 == response.status_code
datasette-yaml/tests/test_yaml.py
9 async def test_plugin_is_installed():
10 app = Datasette([], memory=True).app()
11 async with httpx.AsyncClient(app=app) as client:
12 response = await client.get("http://localhost/-/plugins.json")
13 assert 200 == response.status_code
29 )
30 app = Datasette([str(db_path)]).app()
31 async with httpx.AsyncClient(app=app) as client:
32 response = await client.get("http://localhost/test/dogs.yaml")
33 assert response.status_code == 200
datasette-write/tests/test_write.py
85 @pytest.mark.asyncio
86 async def test_execute_write(ds, database, sql, expected_message):
87 async with httpx.AsyncClient(
88 app=ds.app(), cookies={"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}
89 ) as client:
datasette-vega/tests/test_vega.py
7 async def test_plugin_is_installed():
8 app = Datasette([], memory=True).app()
9 async with httpx.AsyncClient(app=app) as client:
10 response = await client.get("http://localhost/-/plugins.json")
11 assert response.status_code == 200
datasette-upload-csvs/tests/test_datasette_upload_csvs.py
13 app = ds.app()
14 async with LifespanManager(app):
15 async with httpx.AsyncClient(app=app) as client:
16 response = await client.get("http://localhost/")
17 assert 200 == response.status_code
21 async def test_redirect():
22 datasette = Datasette([], memory=True)
23 async with httpx.AsyncClient(app=datasette.app()) as client:
24 response = await client.get("http://localhost/-/upload-csv")
25 assert response.status_code == 302
33 app = ds.app()
34 async with LifespanManager(app):
35 async with httpx.AsyncClient(app=app) as client:
36 cookies = {}
37 if auth:
104
105 # First test the upload page exists
106 async with httpx.AsyncClient(app=datasette.app()) as client:
107 response = await client.get("http://localhost/-/upload-csvs", cookies=cookies)
108 assert 200 == response.status_code
149 ds = Datasette([path])
150 app = ds.app()
151 async with httpx.AsyncClient(app=app) as client:
152 response = await client.get("http://localhost/-/upload-csvs")
153 assert 403 == response.status_code
154 # Now try with a root actor
155 async with httpx.AsyncClient(app=app) as client2:
156 response2 = await client2.get(
157 "http://localhost/-/upload-csvs",
datasette-template-sql/tests/test_template_sql.py
28 @pytest.mark.asyncio
29 async def test_sql_against_named_database(app):
30 async with httpx.AsyncClient(app=app) as client:
31 response = await client.get("http://localhost/news")
32 assert 200 == response.status_code
40 @pytest.mark.asyncio
41 async def test_sql_against_default_database(app):
42 async with httpx.AsyncClient(app=app) as client:
43 response = await client.get("http://localhost/")
44 assert 200 == response.status_code
49 @pytest.mark.asyncio
50 async def test_sql_with_arguments(app):
51 async with httpx.AsyncClient(app=app) as client:
52 response = await client.get("http://localhost/news")
53 assert 200 == response.status_code
datasette-socrata/datasette_socrata/__init__.py
56 metadata_url = "https://{}/api/views/{}.json".format(domain, id)
57 try:
58 async with httpx.AsyncClient() as client:
59 metadata_response = await client.get(metadata_url)
60 if metadata_response.status_code != 200:
68 async def get_row_count(domain, id):
69 # Fetch the row count too - we ignore errors and keep row_count at None
70 async with httpx.AsyncClient() as client:
71 count_url = "https://{}/resource/{}.json?$select=count(*)".format(domain, id)
72 count_response = await client.get(count_url)
259 return await database.execute_write_fn(_write, block=True)
260
261 async with httpx.AsyncClient() as client:
262 async with client.stream("GET", csv_url) as response:
263 reader = AsyncDictReader(response.aiter_lines())
datasette-seaborn/tests/test_seaborn.py
24 async def test_requires_seaborn(ds):
25 app = ds.app()
26 async with httpx.AsyncClient(app=app) as client:
27 response = await client.get("http://localhost/penguins/penguins.seaborn")
28 assert response.status_code == 500
36
37 async def get_dims(path):
38 async with httpx.AsyncClient(app=app) as client:
39 response = await client.get("http://localhost{}".format(path))
40 assert response.status_code == 200
datasette-saved-queries/tests/test_saved_queries.py
22 @pytest.mark.asyncio
23 async def test_plugin_is_installed(ds):
24 async with httpx.AsyncClient(app=ds.app()) as client:
25 response = await client.get("http://localhost/-/plugins.json")
26 assert 200 == response.status_code
31 @pytest.mark.asyncio
32 async def test_table_created(ds):
33 async with httpx.AsyncClient(app=ds.app()) as client:
34 response = await client.get("http://localhost/data/saved_queries.json")
35 assert 200 == response.status_code
39 @pytest.mark.asyncio
40 async def test_save_query(ds):
41 async with httpx.AsyncClient(app=ds.app()) as client:
42 # Get the csrftoken cookie
43 response1 = await client.get("http://localhost/data/save_query")
69 @pytest.mark.asyncio
70 async def test_save_query_authenticated_actor(ds):
71 async with httpx.AsyncClient(app=ds.app()) as client:
72 response1 = await client.get("http://localhost/data/save_query")
73 response2 = await client.post(
datasette-ripgrep/README.md
16 Some example searches:
17
18 - [with.\*AsyncClient](https://ripgrep.datasette.io/-/ripgrep?pattern=with.*AsyncClient) - regular expression search for `with.*AsyncClient`
19 - [.plugin_config, literal=on](https://ripgrep.datasette.io/-/ripgrep?pattern=.plugin_config\(&literal=on) - a non-regular expression search for `.plugin_config(`
20 - [with.\*AsyncClient glob=datasette/\*\*](https://ripgrep.datasette.io/-/ripgrep?pattern=with.*AsyncClient&glob=datasette%2F%2A%2A) - search for that pattern only within the `datasette/` top folder
21 - ["sqlite-utils\[">\] glob=setup.py](https://ripgrep.datasette.io/-/ripgrep?pattern=%22sqlite-utils%5B%22%3E%5D&glob=setup.py) - a regular expression search for packages that depend on either `sqlite-utils` or `sqlite-utils>=some-version`
22 - [test glob=!\*.html](https://ripgrep.datasette.io/-/ripgrep?pattern=test&glob=%21*.html) - search for the string `test` but exclude results in HTML files
datasette-remote-metadata/datasette_remote_metadata/__init__.py
24 fetch_url += "&" if "?" in url else "?"
25 fetch_url += str(random.random())
26 async with httpx.AsyncClient() as client:
27 response = await client.get(
28 fetch_url,
datasette-redirect-to-https/tests/test_redirect_to_https.py
20 datasette = Datasette([], memory=True)
21 async with LifespanManager(datasette.app()):
22 async with httpx.AsyncClient(app=datasette.app()) as client:
23 response = await client.get("https://localhost{}".format(path))
24 assert response.status_code == 200
datasette-psutil/tests/test_psutil.py
7 async def test_datasette_psutil():
8 ds = Datasette([], memory=True)
9 async with httpx.AsyncClient(app=ds.app()) as client:
10 response = await client.get("http://localhost/-/psutil")
11 assert 200 == response.status_code
datasette-plugin-demos/tests/test_plugin_demos.py
7 async def test_plugin_is_installed():
8 app = Datasette([], memory=True).app()
9 async with httpx.AsyncClient(app=app) as client:
10 response = await client.get("http://localhost/-/plugins.json")
11 assert 200 == response.status_code
datasette-permissions-sql/tests/test_permissions_sql.py
90 @pytest.mark.asyncio
91 async def test_permissions_sql(ds, actor, table, expected_status):
92 async with httpx.AsyncClient(app=ds.app()) as client:
93 cookies = {}
94 if actor:
105 @pytest.mark.asyncio
106 async def test_fallback(ds, actor, expected_status):
107 async with httpx.AsyncClient(app=ds.app()) as client:
108 cookies = {}
109 if actor:
datasette-media/tests/test_media.py
24 },
25 ).app()
26 async with httpx.AsyncClient(app=app) as client:
27 response = await client.get("http://localhost/-/media/photos/key")
28 assert 200 == response.status_code
51 },
52 ).app()
53 async with httpx.AsyncClient(app=app) as client:
54 response = await client.get("http://localhost/-/media/text/key")
55 assert 200 == response.status_code
136 },
137 ).app()
138 async with httpx.AsyncClient(app=app) as client:
139 response = await client.get("http://localhost/-/media/photos/1")
140 assert 200 == response.status_code
166 },
167 ).app()
168 async with httpx.AsyncClient(app=app) as client:
169 response = await client.get("http://localhost/-/media/photos/1")
170 assert 200 == response.status_code
193 },
194 ).app()
195 async with httpx.AsyncClient(app=app) as client:
196 response = await client.get("http://localhost/-/media/photos/1")
197 assert 200 == response.status_code
220 },
221 ).app()
222 async with httpx.AsyncClient(app=app) as client:
223 response = await client.get("http://localhost/-/media/photos/1")
224 assert 200 == response.status_code
260 },
261 ).app()
262 async with httpx.AsyncClient(app=app) as client:
263 response = await client.get("http://localhost/-/media/photos/1", params=args)
264 assert 200 == response.status_code
datasette-media/datasette_media/__init__.py
73 if should_transform:
74 if content is None and content_url:
75 async with httpx.AsyncClient() as client:
76 response = await client.get(row["content_url"])
77 content = response.content
datasette-mask-columns/tests/test_mask_columns.py
12 datasette = Datasette([path], memory=True)
13 # Without the plugin:
14 async with httpx.AsyncClient(app=datasette.app()) as client:
15 response = await client.get("http://localhost/foo/users.json?_shape=array")
16 assert 200 == response.status_code
29 },
30 )
31 async with httpx.AsyncClient(app=datasette2.app()) as client:
32 response = await client.get("http://localhost/foo/users.json?_shape=array")
33 assert 200 == response.status_code
datasette-insert-unsafe/tests/test_insert_unsafe.py
18 async def test_plugin_is_installed():
19 app = Datasette([], memory=True).app()
20 async with httpx.AsyncClient(app=app) as client:
21 response = await client.get("http://localhost/-/plugins.json")
22 assert 200 == response.status_code
28 async def test_insert_allowed(db_path):
29 app = Datasette([str(db_path)]).app()
30 async with httpx.AsyncClient(app=app) as client:
31 response = await client.post(
32 "http://localhost/-/insert/data/newtable", json=[{"foo": "bar"}],
40 plugin = pm.unregister(name="insert_unsafe")
41 try:
42 async with httpx.AsyncClient(app=app) as client:
43 response = await client.post(
44 "http://localhost/-/insert/data/newtable", json=[{"foo": "bar"}],
datasette-init/tests/test_init.py
35 )
36 await ds.invoke_startup()
37 async with httpx.AsyncClient(app=ds.app()) as client:
38 response = await client.get("http://localhost/test/dogs.json")
39 assert 200 == response.status_code
67 )
68 await ds.invoke_startup()
69 async with httpx.AsyncClient(app=ds.app()) as client:
70 response = await client.get("http://localhost/test/dogs.json")
71 assert 200 == response.status_code
79 ds = build_datasette(tmp_path_factory, {"views": {"two": "select 1 + 1"}})
80 await ds.invoke_startup()
81 async with httpx.AsyncClient(app=ds.app()) as client:
82 response = await client.get("http://localhost/test/two.json?_shape=array")
83 assert 200 == response.status_code
92 db_init=lambda db: db.create_view("two", "select 1 + 3"),
93 )
94 async with httpx.AsyncClient(app=ds.app()) as client:
95 response = await client.get("http://localhost/test/two.json?_shape=array")
96 assert [{"1 + 3": 4}] == response.json()
104 ds = Datasette([], memory=True)
105 await ds.invoke_startup()
106 async with httpx.AsyncClient(app=ds.app()) as client:
107 assert 200 == (await client.get("http://localhost/")).status_code
datasette-indieauth/tests/test_indieauth.py
15 async def test_plugin_is_installed():
16 app = Datasette([], memory=True).app()
17 async with httpx.AsyncClient(app=app) as client:
18 response = await client.get("http://localhost/-/plugins.json")
19 assert 200 == response.status_code
35 app = datasette.app()
36 paths = ("/-/actor.json", "/", "/:memory:", "/-/metadata")
37 async with httpx.AsyncClient(app=app) as client:
38 # All pages should 403 and show login form
39 for path in paths:
168 datasette = Datasette([], memory=True)
169 app = datasette.app()
170 async with httpx.AsyncClient(app=app) as client:
171 # Get CSRF token
172 csrftoken = await _get_csrftoken(client)
241 datasette = Datasette([], memory=True)
242 app = datasette.app()
243 async with httpx.AsyncClient(app=app) as client:
244 response = await client.get("http://localhost/-/indieauth/done")
245 assert response.status_code == 400
274 datasette = Datasette([], memory=True)
275 app = datasette.app()
276 async with httpx.AsyncClient(app=app) as client:
277 csrftoken = await _get_csrftoken(client)
278 # Submit the form
300 else:
301 ds_indieauth = bad_cookie
302 async with httpx.AsyncClient(app=app) as client:
303 response = await client.get(
304 "http://localhost/-/indieauth/done",
322 datasette = Datasette([], memory=True)
323 app = datasette.app()
324 async with httpx.AsyncClient(app=app) as client:
325 csrftoken = await _get_csrftoken(client)
326 # Submit the form
352 datasette = Datasette([], memory=True)
353 app = datasette.app()
354 async with httpx.AsyncClient(app=app) as client:
355 csrftoken = await _get_csrftoken(client)
356 # Submit the form
datasette-indieauth/datasette_indieauth/utils.py
131 canonical_url = None
132 chunk = None
133 async with httpx.AsyncClient(max_redirects=5) as client:
134 try:
135 response = await client.get(url)
datasette-indieauth/datasette_indieauth/__init__.py
125 "code_verifier": code_verifier,
126 }
127 async with httpx.AsyncClient() as client:
128 response = await client.post(authorization_endpoint, data=data)
129
datasette-import-table/tests/test_import_table.py
15 async def test_plugin_is_installed():
16 app = Datasette([], memory=True).app()
17 async with httpx.AsyncClient(app=app) as client:
18 response = await client.get("http://localhost/-/plugins.json")
19 assert 200 == response.status_code
39 datasette = Datasette([db_path])
40 cookies = {"ds_actor": datasette.sign({"a": {"id": "root"}}, "actor")}
41 async with httpx.AsyncClient(app=datasette.app()) as client:
42 response = await client.get("http://localhost/-/import-table", cookies=cookies)
43 assert 200 == response.status_code
62 datasette = Datasette([db_path1, db_path2])
63 cookies = {"ds_actor": datasette.sign({"a": {"id": "root"}}, "actor")}
64 async with httpx.AsyncClient(app=datasette.app()) as client:
65 response = await client.get("http://localhost/-/import-table", cookies=cookies)
66 assert response.status_code == 200
79 ds = Datasette([path])
80 app = ds.app()
81 async with httpx.AsyncClient(app=app) as client:
82 response = await client.get("http://localhost/-/import-table")
83 assert 403 == response.status_code
84 # Now try with a root actor
85 async with httpx.AsyncClient(app=app) as client2:
86 response2 = await client2.get(
87 "http://localhost/-/import-table",
datasette-import-table/datasette_import_table/__init__.py
107
108 while url:
109 async with httpx.AsyncClient() as client:
110 response = await client.get(url)
111 data = response.json()
146 async def load_first_page(url):
147 url = url + ".json?_shape=objects&_size=max"
148 async with httpx.AsyncClient() as client:
149 response = await client.get(url)
150 if response.status_code != 200:
datasette-glitch/tests/test_glitch.py
8 async def test_plugin_is_installed():
9 app = Datasette([], memory=True).app()
10 async with httpx.AsyncClient(app=app) as client:
11 response = await client.get("http://localhost/-/plugins.json")
12 assert 200 == response.status_code
datasette-edit-templates/tests/test_edit_templates.py
7 async def test_plugin_is_installed():
8 app = Datasette([], memory=True).app()
9 async with httpx.AsyncClient(app=app) as client:
10 response = await client.get("http://localhost/-/plugins.json")
11 assert 200 == response.status_code
datasette-edit-schema/tests/test_edit_schema.py
27 async def test_csrf_required(db_path):
28 ds = Datasette([db_path])
29 async with httpx.AsyncClient(app=ds.app()) as client:
30 response = await client.post(
31 "http://localhost/-/edit-schema/data/creatures",
41 async def test_table_actions(db_path, authenticate):
42 ds = Datasette([db_path])
43 async with httpx.AsyncClient(app=ds.app()) as client:
44 cookies = None
45 if authenticate:
61 ds = Datasette([db_path])
62 cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}
63 async with httpx.AsyncClient(app=ds.app()) as client:
64 # Get a csrftoken
65 csrftoken = (
84 db = sqlite_utils.Database(db_path)
85 assert "creatures" in db.table_names()
86 async with httpx.AsyncClient(app=ds.app()) as client:
87 # Get a csrftoken
88 csrftoken = (
112 table = db["creatures"]
113 assert {"name": str, "description": str} == table.columns_dict
114 async with httpx.AsyncClient(app=ds.app()) as client:
115 # Get a csrftoken
116 csrftoken = (
157 ds = Datasette([db_path])
158 cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}
159 async with httpx.AsyncClient(app=ds.app()) as client:
160 csrftoken = (
161 await client.get(
228 table = db["creatures"]
229 assert table.columns_dict == {"name": str, "description": str}
230 async with httpx.AsyncClient(app=ds.app()) as client:
231 csrftoken = (
232 await client.get(
250 async def test_static_assets(db_path):
251 ds = Datasette([db_path])
252 async with httpx.AsyncClient(app=ds.app()) as client:
253 for path in (
254 "/-/static-plugins/datasette-edit-schema/draggable.1.0.0-beta.11.bundle.min.js",
268 someuser_cookies = {"ds_actor": ds.sign({"a": {"id": "someuser"}}, "actor")}
269 root_cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}
270 async with httpx.AsyncClient(app=ds.app()) as client:
271 response = await client.get(
272 "http://localhost" + path,
297 ds = Datasette([db_path])
298 cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}
299 async with httpx.AsyncClient(app=ds.app()) as client:
300 csrftoken = (
301 await client.get(
datasette-dns/tests/test_dns.py
10 async def test_plugin_is_installed():
11 app = Datasette([], memory=True).app()
12 async with httpx.AsyncClient(app=app) as client:
13 response = await client.get("http://localhost/-/plugins.json")
14 assert 200 == response.status_code
22 m.side_effect = dns.resolver.NoAnswer
23 app = Datasette([], memory=True).app()
24 async with httpx.AsyncClient(app=app) as client:
25 response = await client.get(
26 "http://localhost/:memory:.json?"
datasette-dateutil/tests/test_dateutil.py
7 async def test_plugin_is_installed():
8 app = Datasette([], memory=True).app()
9 async with httpx.AsyncClient(app=app) as client:
10 response = await client.get("http://localhost/-/plugins.json")
11 assert 200 == response.status_code
85 async def test_dateutil_sql_functions(sql, expected):
86 app = Datasette([], memory=True).app()
87 async with httpx.AsyncClient(app=app) as client:
88 response = await client.get(
89 "http://localhost/_memory.json",
101 async def test_dateutil_unbounded_rrule_error():
102 app = Datasette([], memory=True).app()
103 async with httpx.AsyncClient(app=app) as client:
104 response = await client.get(
105 "http://localhost/_memory.json",
datasette-copyable/tests/test_copyable.py
24 @pytest.mark.asyncio
25 async def test_plugin_is_installed(ds):
26 async with httpx.AsyncClient(app=ds.app()) as client:
27 response = await client.get("http://localhost/-/plugins.json")
28 assert 200 == response.status_code
33 @pytest.mark.asyncio
34 async def test_plugin_adds_copyable_extension(ds):
35 async with httpx.AsyncClient(app=ds.app()) as client:
36 response = await client.get("http://localhost/test/dogs")
37 assert 200 == response.status_code
41 @pytest.mark.asyncio
42 async def test_copyable_page_tsv(ds):
43 async with httpx.AsyncClient(app=ds.app()) as client:
44 response = await client.get("http://localhost/test/dogs.copyable")
45 assert 200 == response.status_code
55 @pytest.mark.asyncio
56 async def test_raw_page_tsv(ds):
57 async with httpx.AsyncClient(app=ds.app()) as client:
58 response = await client.get("http://localhost/test/dogs.copyable?_raw=1")
59 assert 200 == response.status_code
67 @pytest.mark.asyncio
68 async def test_copyable_page_github(ds):
69 async with httpx.AsyncClient(app=ds.app()) as client:
70 response = await client.get(
71 "http://localhost/test/dogs.copyable?_table_format=github"
84 @pytest.mark.asyncio
85 async def test_raw_page_github(ds):
86 async with httpx.AsyncClient(app=ds.app()) as client:
87 response = await client.get(
88 "http://localhost/test/dogs.copyable?_table_format=github&_raw=1"
99 @pytest.mark.asyncio
100 async def test_raw_page_tsv_with_labels(ds):
101 async with httpx.AsyncClient(app=ds.app()) as client:
102 response = await client.get(
103 "http://localhost/test/dogs.copyable?_labels=on&_raw=1"
113 @pytest.mark.asyncio
114 async def test_copyable_page_github_with_labels(ds):
115 async with httpx.AsyncClient(app=ds.app()) as client:
116 response = await client.get(
117 "http://localhost/test/dogs.copyable?_table_format=github&_labels=on"
datasette-configure-fts/tests/test_configure_fts.py
36 async def test_initial_db_is_not_searchable(db_path):
37 app = Datasette([db_path]).app()
38 async with httpx.AsyncClient(app=app) as client:
39 response = await client.get("http://localhost/data.json")
40 assert 200 == response.status_code
48 ds = Datasette([db_path])
49 app = ds.app()
50 async with httpx.AsyncClient(app=app) as client:
51 response = await client.get("http://localhost{}".format(path))
52 assert 403 == response.status_code
53 # Now try with a root actor
54 async with httpx.AsyncClient(app=app) as client2:
55 response2 = await client2.get(
56 "http://localhost{}".format(path),
65 ds = Datasette([db_path])
66 app = ds.app()
67 async with httpx.AsyncClient(app=app) as client:
68 response = await client.get(
69 "http://localhost/-/configure-fts",
78 async def test_database_page_sets_cookie(db_path):
79 ds = Datasette([db_path])
80 async with httpx.AsyncClient(app=ds.app()) as client:
81 response = await client.get(
82 "http://localhost/-/configure-fts/data",
89 async def test_lists_databases_if_more_than_one(db_path, db_path2):
90 ds = Datasette([db_path, db_path2])
91 async with httpx.AsyncClient(app=ds.app()) as client:
92 response = await client.get(
93 "http://localhost/-/configure-fts",
103 async def test_lists_tables_in_database(db_path2):
104 ds = Datasette([db_path2])
105 async with httpx.AsyncClient(app=ds.app()) as client:
106 response = await client.get(
107 "http://localhost/-/configure-fts/data2",
114 assert b"<h2>mammals</h2>" in response.content
115 # If we select just two tables, only those two
116 async with httpx.AsyncClient(app=ds.app()) as client:
117 response2 = await client.get(
118 "http://localhost/-/configure-fts/data2?table=dogs&table=mammals",
136 }
137 )
138 async with httpx.AsyncClient(app=ds.app()) as client:
139 response = await client.get(
140 "http://localhost/-/configure-fts/data?table=mixed_types",
153 async def test_make_table_searchable(db_path):
154 ds = Datasette([db_path])
155 async with httpx.AsyncClient(app=ds.app()) as client:
156 response1 = await client.get(
157 "http://localhost/-/configure-fts/data",
197 db = sqlite_utils.Database(db_path)
198 db["creatures"].enable_fts(["name"])
199 async with httpx.AsyncClient(app=ds.app()) as client:
200 response1 = await client.get(
201 "http://localhost/-/configure-fts/data",
222 async def test_table_actions(db_path, authenticate):
223 ds = Datasette([db_path])
224 async with httpx.AsyncClient(app=ds.app()) as client:
225 cookies = None
226 if authenticate:
datasette-column-inspect/tests/test_column_inspect.py
22 async def test_table_page_has_script_on_it(db_path):
23 app = Datasette([db_path]).app()
24 async with httpx.AsyncClient(app=app) as client:
25 response = await client.get("http://localhost/data/creatures")
26 assert 200 == response.status_code
datasette-block/tests/test_block.py
16 app = datasette.app()
17 async with LifespanManager(app):
18 async with httpx.AsyncClient(app=app) as client:
19 response = await client.get("http://localhost" + path)
20 assert response.status_code == expected_status_code
datasette-backup/tests/test_backup.py
22 async def test_plugin_is_installed():
23 app = Datasette([], memory=True).app()
24 async with httpx.AsyncClient(app=app) as client:
25 response = await client.get("http://localhost/-/plugins.json")
26 assert 200 == response.status_code
31 @pytest.mark.asyncio
32 async def test_backup_sql(ds):
33 async with httpx.AsyncClient(app=ds.app()) as client:
34 assert (
35 await client.get("http://localhost/-/backup/nope.sql")
65 db["dogs"].enable_fts(["name"])
66 ds = Datasette([db_path])
67 async with httpx.AsyncClient(app=ds.app()) as client:
68 response = await client.get("http://localhost/-/backup/fts.sql")
69 assert response.status_code == 200
datasette-auth-tokens/tests/test_auth_tokens.py
67 @pytest.mark.asyncio
68 async def test_token(ds, token, path, expected_status):
69 async with httpx.AsyncClient(app=ds.app()) as client:
70 response = await client.get(
71 "http://localhost{}".format(path),
88 @pytest.mark.asyncio
89 async def test_query_param(ds, token, path, expected_status):
90 async with httpx.AsyncClient(app=ds.app()) as client:
91 response = await client.get(
92 "http://localhost{}&_auth_token={}".format(path, token),
110 @pytest.mark.asyncio
111 async def test_query(ds, token, path, expected_status):
112 async with httpx.AsyncClient(app=ds.app()) as client:
113 response = await client.get(
114 "http://localhost{}".format(path),
129 @pytest.mark.asyncio
130 async def test_actor(ds, token, expected_actor):
131 async with httpx.AsyncClient(app=ds.app()) as client:
132 response = await client.get(
133 "http://localhost/-/actor.json",
142 @pytest.mark.asyncio
143 async def test_tokens_table_not_visible(ds, path):
144 async with httpx.AsyncClient(app=ds.app()) as client:
145 response = await client.get("http://localhost{}".format(path))
146 assert 403 == response.status_code
datasette-auth-passwords/tests/test_auth_passwords.py
21 async def test_plugin_is_installed():
22 app = Datasette([], memory=True).app()
23 async with httpx.AsyncClient(app=app) as client:
24 response = await client.get("http://localhost/-/plugins.json")
25 assert 200 == response.status_code
49 async def test_password_tool():
50 app = Datasette([], memory=True).app()
51 async with httpx.AsyncClient(app=app) as client:
52 response1 = await client.get("http://localhost/-/password-tool")
53 csrftoken = response1.cookies["ds_csrftoken"]
68 app = Datasette([], memory=True).app()
69 message = "This instance does not have any configured accounts"
70 async with httpx.AsyncClient(app=app) as client:
71 response = await client.get("http://localhost/-/login")
72 assert message in response.text
73 app2 = Datasette([], memory=True, metadata=TEST_METADATA).app()
74 async with httpx.AsyncClient(app=app2) as client2:
75 response2 = await client2.get("http://localhost/-/login")
76 assert message not in response2.text
90 async def test_login(username, password, should_login, expected_username):
91 ds = Datasette([], memory=True, metadata=TEST_METADATA)
92 async with httpx.AsyncClient(app=ds.app()) as client:
93 # Get csrftoken
94 csrftoken = (await client.get("http://localhost/-/login")).cookies[
datasette-auth-existing-cookies/datasette_auth_existing_cookies/__init__.py
47 return datasette._auth_existing_cookies_cache[cache_key]
48
49 async with httpx.AsyncClient() as client:
50 response = await client.get(api_url, params=header_params, cookies=cookies)
51
datasette-auth-github/datasette_auth_github/views.py
45
46 # Exchange that code for a token
47 async with httpx.AsyncClient() as client:
48 github_response = await client.post(
49 "https://github.com/login/oauth/access_token",
67 profile_url = "https://api.github.com/user"
68 try:
69 async with httpx.AsyncClient() as client:
70 profile = (
71 await client.get(
datasette-auth-github/datasette_auth_github/utils.py
13 org, profile["login"]
14 )
15 async with httpx.AsyncClient() as client:
16 response = await client.get(
17 url, headers={"Authorization": "token {}".format(access_token)}
30 org_slug, team_slug
31 )
32 async with httpx.AsyncClient() as client:
33 response = await client.get(
34 lookup_url,
45 )
46 )
47 async with httpx.AsyncClient() as client:
48 response = await client.get(
49 team_membership_url,
datasette-atom/tests/test_atom.py
101 async def test_incorrect_sql_returns_400():
102 app = Datasette([], immutables=[], memory=True).app()
103 async with httpx.AsyncClient(app=app) as client:
104 response = await client.get(
105 "http://localhost/:memory:.atom?sql=select+sqlite_version()"
128 """
129 app = Datasette([], immutables=[], memory=True).app()
130 async with httpx.AsyncClient(app=app) as client:
131 response = await client.get(
132 "http://localhost/:memory:.atom?" + urllib.parse.urlencode({"sql": sql})
151 """
152 app = Datasette([], immutables=[], memory=True).app()
153 async with httpx.AsyncClient(app=app) as client:
154 response = await client.get(
155 "http://localhost/:memory:.atom?" + urllib.parse.urlencode({"sql": sql})
174 """
175 app = Datasette([], immutables=[], memory=True).app()
176 async with httpx.AsyncClient(app=app) as client:
177 response = await client.get(
178 "http://localhost/:memory:.atom?" + urllib.parse.urlencode({"sql": sql})
197 """
198 app = Datasette([], immutables=[], memory=True).app()
199 async with httpx.AsyncClient(app=app) as client:
200 response = await client.get(
201 "http://localhost/:memory:?" + urllib.parse.urlencode({"sql": sql})
205 assert b'<a href="/:memory:.atom' in response.content
206 # But with a different query that link is not shown:
207 async with httpx.AsyncClient(app=app) as client:
208 response = await client.get(
209 "http://localhost/:memory:?"
234 },
235 ).app()
236 async with httpx.AsyncClient(app=app) as client:
237 response = await client.get("http://localhost/:memory:/feed.atom")
238 assert 200 == response.status_code
273 metadata=metadata,
274 ).app()
275 async with httpx.AsyncClient(app=app) as client:
276 response = await client.get("http://localhost/:memory:/latest.atom")
277 assert 200 == response.status_code
datasette-allow-permissions-debug/tests/test_allow_permissions_debug.py
7 async def test_plugin_is_installed():
8 app = Datasette([], memory=True).app()
9 async with httpx.AsyncClient(app=app) as client:
10 response = await client.get("http://localhost/-/plugins.json")
11 assert 200 == response.status_code
17 async def test_allows_access():
18 app = Datasette([], memory=True).app()
19 async with httpx.AsyncClient(app=app) as client:
20 response = await client.get("http://localhost/-/permissions")
21 assert 200 == response.status_code
datasette/docs/internals.rst
1055 async def fetch_url(url):
1056 with trace("fetch-url", url=url):
1057 async with httpx.AsyncClient() as client:
1058 return await client.get(url)
1059
datasette/datasette/app.py
1528
1529 async def get(self, path, **kwargs):
1530 async with httpx.AsyncClient(app=self.app) as client:
1531 return await client.get(self._fix(path), **kwargs)
1532
1533 async def options(self, path, **kwargs):
1534 async with httpx.AsyncClient(app=self.app) as client:
1535 return await client.options(self._fix(path), **kwargs)
1536
1537 async def head(self, path, **kwargs):
1538 async with httpx.AsyncClient(app=self.app) as client:
1539 return await client.head(self._fix(path), **kwargs)
1540
1541 async def post(self, path, **kwargs):
1542 async with httpx.AsyncClient(app=self.app) as client:
1543 return await client.post(self._fix(path), **kwargs)
1544
1545 async def put(self, path, **kwargs):
1546 async with httpx.AsyncClient(app=self.app) as client:
1547 return await client.put(self._fix(path), **kwargs)
1548
1549 async def patch(self, path, **kwargs):
1550 async with httpx.AsyncClient(app=self.app) as client:
1551 return await client.patch(self._fix(path), **kwargs)
1552
1553 async def delete(self, path, **kwargs):
1554 async with httpx.AsyncClient(app=self.app) as client:
1555 return await client.delete(self._fix(path), **kwargs)
1556
1557 async def request(self, method, path, **kwargs):
1558 avoid_path_rewrites = kwargs.pop("avoid_path_rewrites", None)
1559 async with httpx.AsyncClient(app=self.app) as client:
1560 return await client.request(
1561 method, self._fix(path, avoid_path_rewrites), **kwargs