Monkeypatch the actual urlopen call to emulate a HTTP Error 400.
(self, monkeypatch: MonkeyPatch)
| 90 | |
| 91 | @pytest.fixture |
| 92 | def mocked_urlopen_fail(self, monkeypatch: MonkeyPatch): |
| 93 | """Monkeypatch the actual urlopen call to emulate a HTTP Error 400.""" |
| 94 | calls = [] |
| 95 | |
| 96 | import urllib.error |
| 97 | import urllib.request |
| 98 | |
| 99 | def mocked(url, data): |
| 100 | calls.append((url, data)) |
| 101 | raise urllib.error.HTTPError(url, 400, "Bad request", {}, io.BytesIO()) |
| 102 | |
| 103 | monkeypatch.setattr(urllib.request, "urlopen", mocked) |
| 104 | return calls |
| 105 | |
| 106 | @pytest.fixture |
| 107 | def mocked_urlopen_invalid(self, monkeypatch: MonkeyPatch): |