code: def test_execute_sql(config):
      schema_re = re.compile("const schema = ({.*?});", re.DOTALL)
      with make_app_client(config=config) as client:
          form_fragment = '<form class="sql" action="/fixtures"'
  
          # Anonymous users - should not display the form:
          anon_html = client.get("/fixtures").text
          assert form_fragment not in anon_html
          # And const schema should be an empty object:
          assert "const schema = {};" in anon_html
          # This should 403:
          assert client.get("/fixtures?sql=select+1").status == 403
          # ?_where= not allowed on tables:
          assert (
              client.get("/fixtures/facet_cities?_where=id=3").status
              == 403
          )
  
          # But for logged in user all of these should work:
          cookies = {"ds_actor": client.actor_cookie({"id": "root"})}
          response_text = client.get("/fixtures", cookies=cookies).text
          # Extract the schema= portion of the JavaScript
          schema_json = schema_re.search(response_text).group(1)
          schema = json.loads(schema_json)
          assert set(schema["attraction_characteristic"]) == {
              "name",
              "pk",
          }
          assert schema["paginated_view"] == []
          assert form_fragment in response_text
          query_response = client.get(
              "/fixtures?sql=select+1", cookies=cookies
          )
          assert query_response.status == 200
          schema2 = json.loads(
              schema_re.search(query_response.text).group(1)
          )
          assert set(schema2["attraction_characteristic"]) == {
              "name",
              "pk",
          }
          assert (
              client.get(
                  "/fixtures/facet_cities?_where=id=3", cookies=cookies
              ).status
              == 200
          )
  
imports: import collections
  from datasette.app import Datasette
  from datasette.cli import cli
  from datasette.default_permissions import restrictions_allow_action
  from .fixtures import app_client, assert_permissions_checked, make_app_client
  from click.testing import CliRunner
  from bs4 import BeautifulSoup
  import copy
  import json
  from pprint import pprint
  import pytest_asyncio
  import pytest
  import re
  import time
  import urllib
label_desc: Use image node_id 9 for calling a global function with example usage: test_execute_sql(config) without return types