Repository navigation
Expand file tree
/
Copy pathtest_language.py
More file actions
85 lines (72 loc) · 3.29 KB
/
Copy pathtest_language.py
File metadata and controls
85 lines (72 loc) · 3.29 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import asyncio
import inspect
import httpx
import pytest
from parseapi import AsyncParseAPI, ParseAPI
OPERATIONS = [
("ip", ["8.8.8.8"], {"deep": True}),
("ip.self", [], {"deep": True}),
("continent", ["EU"], {}),
("continent.countries", ["EU"], {}),
("country", ["DE"], {"deep": True}),
("country.states", ["DE"], {}),
("state", ["CA"], {"country": "US"}),
("state.districts", ["CA"], {"country": "US", "deep": True}),
("district", ["37081"], {"country": "US", "state": "NC"}),
("city", ["München"], {"country": "DE"}),
("city.id", ["city_fixture"], {"deep": True}),
("city.search", ["Mün"], {"limit": 2}),
("city.nearest", [0, 0], {}),
("city.nearby", ["München"], {"radius": 0, "unit": "km"}),
("postal", ["SW1A 1AA"], {"country": "GB"}),
("postal.nearby", ["28202"], {"country": "US", "radius": 0}),
("postal.distance", ["28202", "10001"], {"country": "US"}),
("company", ["732829320"], {"country": "FR", "deep": True}),
("asn", ["AS13335"], {}),
("language", ["ja"], {}),
("time", ["America/New_York"], {"at": "2026-01-01T12:00", "to": "UTC", "deep": True}),
("time.at", [0, 0], {"at": "2026-01-01T12:00Z"}),
("timezone", ["UTC"], {"deep": True}),
("timezone.at", [0, 0], {"deep": True}),
("date", ["03/04/2026"], {"format": "dmy", "to": "2026-05-01", "deep": True}),
("date.today", [], {"to": "2026-05-01"}),
("point", [0, 0], {"deep": True}),
("emoji", ["😀"], {"deep": True}),
("emoji.search", ["visage"], {"limit": 2}),
]
def operation(client, name):
for part in name.split("."):
client = getattr(client, part)
return client
@pytest.mark.parametrize("name,args,options", OPERATIONS)
@pytest.mark.parametrize("async_client", [False, True])
def test_language_is_an_optional_per_request_query(name, args, options, async_client):
calls = []
body = {"name": "Nom traduit", "name_local": "Native name", "future": None}
def handler(request):
calls.append(request)
return httpx.Response(200, json=body)
transport = httpx.MockTransport(handler)
if async_client:
async def run():
async with AsyncParseAPI("fixture", transport=transport) as client:
method = operation(client, name)
assert await method(*args, **options, lang="fr-CA") == body
await method(*args, **options)
asyncio.run(run())
else:
with ParseAPI("fixture", transport=transport) as client:
method = operation(client, name)
assert method(*args, **options, lang="fr-CA") == body
method(*args, **options)
assert len(calls) == 2
assert calls[0].url.path == calls[1].url.path
assert dict(calls[0].url.params) == {**dict(calls[1].url.params), "lang": "fr-CA"}
def test_language_does_not_change_input_parsing_or_unrelated_operations():
calls = []
transport = httpx.MockTransport(lambda request: (calls.append(request), httpx.Response(200, json={}))[1])
with ParseAPI("fixture", transport=transport) as client:
client.date("03/04/2026", format="dmy", lang="en-US")
assert calls[0].url.params["format"] == "dmy"
for name in ["holiday", "name", "email", "phone", "address"]:
assert "lang" not in inspect.signature(operation(client, name)).parameters