def test_download_exception(monkeypatch): """If requests raises an exception itself, that exception is not escaped.""" def raise_exception(_): raise requests.RequestException() monkeypatch.setattr(requests, "get", raise_exception) with pytest.raises(requests.RequestException): download_license("hello world")
def test_download_404(monkeypatch): """If the server returns a 404, there is no license text.""" monkeypatch.setattr(requests, "get", lambda _: MockResponse(status_code=404)) with pytest.raises(requests.RequestException): download_license("does-not-exist")
def test_download(monkeypatch): """A straightforward test: Request license text, get license text.""" monkeypatch.setattr(requests, "get", lambda _: MockResponse("hello", 200)) result = download_license("0BSD") assert result == "hello"