MCPcopy
hub / github.com/openai/openai-python / test_copy_default_headers

Method test_copy_default_headers

tests/test_client.py:175–212  ·  tests/test_client.py::TestOpenAI.test_copy_default_headers
(self)

Source from the content-addressed store, hash-verified

173 assert isinstance(client.timeout, httpx.Timeout)
174
175 def test_copy_default_headers(self) -> None:
176 client = OpenAI(
177 base_url=base_url,
178 api_key=api_key,
179 admin_api_key=admin_api_key,
180 _strict_response_validation=True,
181 default_headers={class="st">"X-Foo": class="st">"bar"},
182 )
183 assert client.default_headers[class="st">"X-Foo"] == class="st">"bar"
184
185 class="cm"># does not override the already given value when not specified
186 copied = client.copy()
187 assert copied.default_headers[class="st">"X-Foo"] == class="st">"bar"
188
189 class="cm"># merges already given headers
190 copied = client.copy(default_headers={class="st">"X-Bar": class="st">"stainless"})
191 assert copied.default_headers[class="st">"X-Foo"] == class="st">"bar"
192 assert copied.default_headers[class="st">"X-Bar"] == class="st">"stainless"
193
194 class="cm"># uses new values for any already given headers
195 copied = client.copy(default_headers={class="st">"X-Foo": class="st">"stainless"})
196 assert copied.default_headers[class="st">"X-Foo"] == class="st">"stainless"
197
198 class="cm"># set_default_headers
199
200 class="cm"># completely overrides already set values
201 copied = client.copy(set_default_headers={})
202 assert copied.default_headers.get(class="st">"X-Foo") is None
203
204 copied = client.copy(set_default_headers={class="st">"X-Bar": class="st">"Robert"})
205 assert copied.default_headers[class="st">"X-Bar"] == class="st">"Robert"
206
207 with pytest.raises(
208 ValueError,
209 match=class="st">"`default_headers` and `set_default_headers` arguments are mutually exclusive",
210 ):
211 client.copy(set_default_headers={}, default_headers={class="st">"X-Foo": class="st">"Bar"})
212 client.close()
213
214 def test_copy_default_query(self) -> None:
215 client = OpenAI(

Callers

nothing calls this directly

Calls 4

copyMethod · 0.95
OpenAIClass · 0.90
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected