|
6 | 6 | import os |
7 | 7 | import pytest |
8 | 8 | from dotenv import load_dotenv, find_dotenv |
9 | | -from devtools_testutils import remove_batch_sanitizers, add_general_regex_sanitizer, add_body_key_sanitizer |
| 9 | +from devtools_testutils import ( |
| 10 | + remove_batch_sanitizers, |
| 11 | + add_general_regex_sanitizer, |
| 12 | + add_body_key_sanitizer, |
| 13 | + add_remove_header_sanitizer, |
| 14 | +) |
10 | 15 |
|
11 | 16 | if not load_dotenv(find_dotenv(), override=True): |
12 | 17 | print("Did not find a .env file. Using default environment variable values for tests.") |
@@ -101,6 +106,24 @@ def sanitize_url_paths(): |
101 | 106 | add_body_key_sanitizer(json_path="blobReference.credential.sasUri", value="sanitized-sas-uri") |
102 | 107 | add_body_key_sanitizer(json_path="blobReferenceForConsumption.credential.sasUri", value="sanitized-sas-uri") |
103 | 108 |
|
| 109 | + # Remove Stainless headers from OpenAI client requests, since they include platform and OS specific info, which we can't have in recorded requests. |
| 110 | + # Here is an example of all the `x-stainless` headers from a Responses call: |
| 111 | + # x-stainless-arch: other:amd64 |
| 112 | + # x-stainless-async: false |
| 113 | + # x-stainless-lang: python |
| 114 | + # x-stainless-os: Windows |
| 115 | + # x-stainless-package-version: 2.8.1 |
| 116 | + # x-stainless-read-timeout: 600 |
| 117 | + # x-stainless-retry-count: 0 |
| 118 | + # x-stainless-runtime: CPython |
| 119 | + # x-stainless-runtime-version: 3.14.0 |
| 120 | + # Note that even though the doc string for `add_remove_header_sanitizer` says `condition` is supported, it is not implemented. So we can't do this: |
| 121 | + # add_remove_header_sanitizer(condition='{"uriRegex": "(?i)^x-stainless-.*$"}') |
| 122 | + # We have to explicitly list all the headers to remove: |
| 123 | + add_remove_header_sanitizer( |
| 124 | + headers="x-stainless-arch, x-stainless-async, x-stainless-lang, x-stainless-os, x-stainless-package-version, x-stainless-read-timeout, x-stainless-retry-count, x-stainless-runtime, x-stainless-runtime-version" |
| 125 | + ) |
| 126 | + |
104 | 127 | # Remove the following sanitizers since certain fields are needed in tests and are non-sensitive: |
105 | 128 | # - AZSDK3493: $..name |
106 | 129 | # - AZSDK3430: $..id |
|
0 commit comments