Skip to content

Commit

Permalink
Add async json explain for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schilling committed Feb 9, 2025
1 parent d964fdc commit 02cfb9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/test_integration_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,19 @@ async def test_sql_explain_postgres_union_query(self):
connection.vendor == "postgresql", "Test valid only on PostgreSQL"
)
async def test_sql_explain_postgres_json_field(self):
self.client.get("/async_execute_json_sql/")
request_ids = list(get_store().request_ids())
request_id = request_ids[-1]
toolbar = DebugToolbar.fetch(request_id, SQLPanel.panel_id)
panel = toolbar.get_panel_by_id(SQLPanel.panel_id)
djdt_query_id = panel.get_stats()["queries"][-1]["djdt_query_id"]

url = "/__debug__/sql_explain/"
base_query = (
'SELECT * FROM "tests_postgresjson" WHERE "tests_postgresjson"."field" @>'
)
query = base_query + """ '{"foo": "bar"}'"""
data = {
"signed": SignedDataForm.sign(
{
"sql": query,
"raw_sql": base_query + " %s",
"params": '["{\\"foo\\": \\"bar\\"}"]',
"alias": "default",
"duration": "0",
"request_id": request_id,
"djdt_query_id": djdt_query_id,
}
)
}
Expand Down
1 change: 1 addition & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
path("execute_json_sql/", views.execute_json_sql),
path("execute_union_sql/", views.execute_union_sql),
path("async_execute_sql/", views.async_execute_sql),
path("async_execute_json_sql/", views.async_execute_json_sql),
path("async_execute_union_sql/", views.async_execute_union_sql),
path("async_execute_sql_concurrently/", views.async_execute_sql_concurrently),
path("cached_view/", views.cached_view),
Expand Down
8 changes: 8 additions & 0 deletions tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def execute_json_sql(request):
return render(request, "base.html")


async def async_execute_json_sql(request):
list_store = []
# make async query with filter, which is compatible with async for.
async for obj in PostgresJSON.objects.filter(field__contains={"foo": "bar"}):
list_store.append(obj)
return render(request, "base.html")


def execute_union_sql(request):
list(User.objects.all().union(User.objects.all(), all=True))
return render(request, "base.html")
Expand Down

0 comments on commit 02cfb9d

Please sign in to comment.