Monkeypatch the actual urlopen calls done by the internal plugin function that connects to bpaste service.
(self, monkeypatch: MonkeyPatch)
| 127 | |
| 128 | @pytest.fixture |
| 129 | def mocked_urlopen(self, monkeypatch: MonkeyPatch): |
| 130 | """Monkeypatch the actual urlopen calls done by the internal plugin |
| 131 | function that connects to bpaste service.""" |
| 132 | calls = [] |
| 133 | |
| 134 | def mocked(url, data): |
| 135 | calls.append((url, data)) |
| 136 | |
| 137 | class DummyFile: |
| 138 | def read(self): |
| 139 | # part of html of a normal response |
| 140 | return b'View <a href="/raw/3c0c6750bd">raw</a>.' |
| 141 | |
| 142 | return DummyFile() |
| 143 | |
| 144 | import urllib.request |
| 145 | |
| 146 | monkeypatch.setattr(urllib.request, "urlopen", mocked) |
| 147 | return calls |
| 148 | |
| 149 | def test_pastebin_invalid_url(self, pastebin, mocked_urlopen_invalid) -> None: |
| 150 | result = pastebin.create_new_paste(b"full-paste-contents") |