-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathtest_http_client.py
More file actions
109 lines (77 loc) · 4.25 KB
/
test_http_client.py
File metadata and controls
109 lines (77 loc) · 4.25 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# This file was auto-generated by Fern from our API Definition.
from intercom.core.http_client import get_request_body, remove_none_from_dict
from intercom.core.request_options import RequestOptions
def get_request_options() -> RequestOptions:
return {"additional_body_parameters": {"see you": "later"}}
def get_request_options_with_none() -> RequestOptions:
return {"additional_body_parameters": {"see you": "later", "optional": None}}
def test_get_json_request_body() -> None:
json_body, data_body = get_request_body(json={"hello": "world"}, data=None, request_options=None, omit=None)
assert json_body == {"hello": "world"}
assert data_body is None
json_body_extras, data_body_extras = get_request_body(
json={"goodbye": "world"}, data=None, request_options=get_request_options(), omit=None
)
assert json_body_extras == {"goodbye": "world", "see you": "later"}
assert data_body_extras is None
def test_get_files_request_body() -> None:
json_body, data_body = get_request_body(json=None, data={"hello": "world"}, request_options=None, omit=None)
assert data_body == {"hello": "world"}
assert json_body is None
json_body_extras, data_body_extras = get_request_body(
json=None, data={"goodbye": "world"}, request_options=get_request_options(), omit=None
)
assert data_body_extras == {"goodbye": "world", "see you": "later"}
assert json_body_extras is None
def test_get_none_request_body() -> None:
json_body, data_body = get_request_body(json=None, data=None, request_options=None, omit=None)
assert data_body is None
assert json_body is None
json_body_extras, data_body_extras = get_request_body(
json=None, data=None, request_options=get_request_options(), omit=None
)
assert json_body_extras == {"see you": "later"}
assert data_body_extras is None
def test_get_empty_json_request_body() -> None:
unrelated_request_options: RequestOptions = {"max_retries": 3}
json_body, data_body = get_request_body(json=None, data=None, request_options=unrelated_request_options, omit=None)
assert json_body is None
assert data_body is None
json_body_extras, data_body_extras = get_request_body(
json={}, data=None, request_options=unrelated_request_options, omit=None
)
assert json_body_extras is None
assert data_body_extras is None
def test_json_body_preserves_none_values() -> None:
"""Test that JSON bodies preserve None values (they become JSON null)."""
json_body, data_body = get_request_body(
json={"hello": "world", "optional": None}, data=None, request_options=None, omit=None
)
# JSON bodies should preserve None values
assert json_body == {"hello": "world", "optional": None}
assert data_body is None
def test_data_body_preserves_none_values_without_multipart() -> None:
"""Test that data bodies preserve None values when not using multipart.
The filtering of None values happens in HttpClient.request/stream methods,
not in get_request_body. This test verifies get_request_body doesn't filter None.
"""
json_body, data_body = get_request_body(
json=None, data={"hello": "world", "optional": None}, request_options=None, omit=None
)
# get_request_body should preserve None values in data body
# The filtering happens later in HttpClient.request when multipart is detected
assert data_body == {"hello": "world", "optional": None}
assert json_body is None
def test_remove_none_from_dict_filters_none_values() -> None:
"""Test that remove_none_from_dict correctly filters out None values."""
original = {"hello": "world", "optional": None, "another": "value", "also_none": None}
filtered = remove_none_from_dict(original)
assert filtered == {"hello": "world", "another": "value"}
# Original should not be modified
assert original == {"hello": "world", "optional": None, "another": "value", "also_none": None}
def test_remove_none_from_dict_empty_dict() -> None:
"""Test that remove_none_from_dict handles empty dict."""
assert remove_none_from_dict({}) == {}
def test_remove_none_from_dict_all_none() -> None:
"""Test that remove_none_from_dict handles dict with all None values."""
assert remove_none_from_dict({"a": None, "b": None}) == {}