-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_query.py
More file actions
51 lines (43 loc) · 1.6 KB
/
test_query.py
File metadata and controls
51 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from lib import endpoints
from test_helpers import expect_equal
def test_query():
url, headers = endpoints.query_request(
'*[_type == "sensor" && _id == $id && value < $threshold][0...$limit && isActive=$active]',
variables={
"id": "temperature-xyz",
"limit": 100,
"isActive": True,
"threshold": 0.052,
},
project_id="abc",
dataset="iot",
api_version="2026-02-26",
token="your token",
params={"tag": "test-request"},
)
expect_equal(
url,
"https://abc.api.sanity.io/v2026-02-26/data/query/iot?tag=test-request&$id=%22temperature-xyz%22&$limit=100&$isActive=true&$threshold=0.052&query=%2a%5b_type%20%3d%3d%20%22sensor%22%20%26%26%20_id%20%3d%3d%20%24id%20%26%26%20value%20%3c%20%24threshold%5d%5b0...%24limit%20%26%26%20isActive%3d%24active%5d",
)
def test_query_use_cdn():
url, headers = endpoints.query_request(
"*[_type == 'sensor' && _id == $id]",
variables={"id": "temperature-xyz"},
project_id="abc",
dataset="iot",
api_version="2026-02-26",
use_cdn=True,
)
expect_equal(
url,
"https://abc.apicdn.sanity.io/v2026-02-26/data/query/iot?$id=%22temperature-xyz%22&query=%2a%5b_type%20%3d%3d%20%27sensor%27%20%26%26%20_id%20%3d%3d%20%24id%5d",
)
def test_with_token():
_, headers = endpoints.query_request(
"*[_type == 'sensor'",
project_id="abc",
dataset="iot",
api_version="2026-02-26",
token="xyz",
)
expect_equal(headers["Authorization"], "Bearer xyz")