forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fetch_github_info.py
27 lines (20 loc) · 859 Bytes
/
test_fetch_github_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
importjson
importrequests
from .fetch_github_infoimportAUTHENTICATED_USER_ENDPOINT, fetch_github_info
deftest_fetch_github_info(monkeypatch):
classFakeResponse:
def__init__(self, content) ->None:
assertisinstance(content, (bytes, str))
self.content=content
defjson(self):
returnjson.loads(self.content)
defmock_response(*args, **kwargs):
assertargs[0] ==AUTHENTICATED_USER_ENDPOINT
assert"Authorization"inkwargs["headers"]
assertkwargs["headers"]["Authorization"].startswith("token ")
assert"Accept"inkwargs["headers"]
returnFakeResponse(b'{"login":"test","id":1}')
monkeypatch.setattr(requests, "get", mock_response)
result=fetch_github_info("token")
assertresult["login"] =="test"
assertresult["id"] ==1