mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
* fixes #3944 authentication error * Fixes: #3944 authentication error * Fixed docstring failure in pre-commit, Fixed request.get params to GitHub REST API standards * run black formatter * Add USER_TOKEN constant and checks if empty, removes deprecated docstring * Add descriptive dict type hint, change headers format to f-string * Add Accept header * Fix pre-commit error * Fix pre-commit error * Add test for fetch_github_info * Remove test function from main file * Create test_fetch_github_info.py * Update test_fetch_github_info.py * Update test_fetch_github_info.py * No need to cover __name__ == __main__ block Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
27
web_programming/test_fetch_github_info.py
Normal file
27
web_programming/test_fetch_github_info.py
Normal file
@ -0,0 +1,27 @@
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
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(requests, "get", mock_response)
|
||||
result = fetch_github_info("token")
|
||||
assert result["login"] == "test"
|
||||
assert result["id"] == 1
|
Reference in New Issue
Block a user