mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-05-18 15:11:28 +00:00
* Replace dependency `requests` with `httpx` Fixes #12742 Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> * updating DIRECTORY.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: cclauss <cclauss@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
28 lines
853 B
Python
28 lines
853 B
Python
import json
|
|
|
|
import httpx
|
|
|
|
from .fetch_github_info import AUTHENTICATED_USER_ENDPOINT, fetch_github_info
|
|
|
|
|
|
def test_fetch_github_info(monkeypatch):
|
|
class FakeResponse:
|
|
def __init__(self, content) -> None:
|
|
assert isinstance(content, (bytes, str))
|
|
self.content = content
|
|
|
|
def json(self):
|
|
return json.loads(self.content)
|
|
|
|
def mock_response(*args, **kwargs):
|
|
assert args[0] == AUTHENTICATED_USER_ENDPOINT
|
|
assert "Authorization" in kwargs["headers"]
|
|
assert kwargs["headers"]["Authorization"].startswith("token ")
|
|
assert "Accept" in kwargs["headers"]
|
|
return FakeResponse(b'{"login":"test","id":1}')
|
|
|
|
monkeypatch.setattr(httpx, "get", mock_response)
|
|
result = fetch_github_info("token")
|
|
assert result["login"] == "test"
|
|
assert result["id"] == 1
|