/
NikolayIvkin
/
TheAlgorithms_Python
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms_Python
Код
Запросы
2
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
web_programming/test_fetch_github_info.py
27 строк
859 B
lawric1
Fixes: #3944 Authentication error; use tokens instead (#3949)
25 ноя 2020, 08:13
Не верифицирован
25 ноя 2020, 08:13
098f02b
Код
Авторство
О чём код?
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