Skip to content

Commit 22ee811

Browse files
author
titouanfreville
committed
feat: Support HTTPX interfaces
# Wrap at 72 chars. ################################## which is here: # # type: # fix -> change that do not modify fonctional code but fix an issue # feat -> code introduce a new feature # refactor -> change that only modify code without introducing feature nor solving bug # perf -> change that optimize performance # test -> modification impacting testing only # ci -> modification on ci # docs -> doc update # # scope: feature impacted by the changes # # append ! if change is breaking # cf: https://www.conventionalcommits.org/en/v1.0.0/ for more information # ###### COMMIT SAMPLE ################################################### # feat(HOOKS): Add commit hooks style validation # # To ensure all of Tankyou dev follow commit rules, we wish to enforce # commit content using commit-msg hook # This hook will be configured to be installed globally and will be # triggered on each repository ######################################################################## # # Title: Summary, imperative, start upper case, don't end with a period (.) # # Remember blank line between title and body. # # Body: Explain *what* and *why* (not *how*). # # # How to Write a Git Commit Message: # https://chris.beams.io/posts/git-commit/ # # 1.Separate subject from body with a blank line # 2. Limit the subject line to 50 characters # 3. Capitalize the subject line # 4. Do not end the subject line with a period # 5. Use the imperative mood in the subject line # 6. Wrap the body at 72 characters # 7. Use the body to explain what and why vs. how # # Footer: # - BREAKING CHANGE: indicate what change are breaking the API and why
1 parent 6e42db4 commit 22ee811

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

apiritif/http.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ class HTTP(object):
5151
HTTP is a base class to make http request with apiritif.
5252
"""
5353

54+
__is_httpx: bool = False
55+
5456
log = log.getChild("http")
5557

56-
def __init__(self, request_client: Any = None):
58+
def __init__(self, request_client: Any = None, is_httpx: bool = False):
5759
"""Initialize a test instance.
5860
request_client can be any system matching `requests` interfaces
5961
"""
6062
self.__client = request_client or requests
6163
self.__support_session = hasattr(self.__client, "Session")
64+
self.__is_httpx = is_httpx
6265

6366
def target(self, *args, **kwargs):
6467
return HTTPTarget(
@@ -161,15 +164,15 @@ def request(
161164
)
162165
raise
163166

164-
http.log.info("Response: %s %s", response.status_code, response.reason)
167+
http.log.info("Response: %s %s", response.status_code, response.reason if not self.__is_httpx else response.reason_phrase)
165168
http.log.debug("Response headers: %r", response.headers)
166169
http.log.debug(
167170
"Response cookies: %r",
168171
{x: response.cookies.get(x) for x in response.cookies},
169172
)
170173
http.log.debug("Response content: \n%s", response.content)
171174

172-
wrapped_response = HTTPResponse(response)
175+
wrapped_response = HTTPResponse(response, self.__is_httpx)
173176

174177
recorder.record_http_request(
175178
method, address, prepared, wrapped_response, session
@@ -689,16 +692,17 @@ def connect(self, path, **kwargs):
689692

690693

691694
class HTTPResponse(object):
692-
def __init__(self, py_response):
695+
def __init__(self, py_response, is_httpx: bool = False):
693696
"""
694697
Construct HTTPResponse from requests.Response object
695698
696699
:type py_response: requests.Response
697700
"""
701+
self.__is_httpx=is_httpx
698702
self.url = py_response.url
699703
self.method = py_response.request.method
700704
self.status_code = int(py_response.status_code)
701-
self.reason = py_response.reason
705+
self.reason = py_response.reason if not self.__is_httpx else py_response.reason_phrase
702706

703707
self.headers = CaseInsensitiveDict(py_response.headers)
704708
self.cookies = {x: py_response.cookies.get(x) for x in py_response.cookies}

0 commit comments

Comments
 (0)