|
10 | 10 | # See the License for the specific language governing permissions and
|
11 | 11 | # limitations under the License.
|
12 | 12 |
|
| 13 | +import itertools |
| 14 | + |
13 | 15 | import celery.exceptions
|
14 | 16 | import pretend
|
15 | 17 | import pytest
|
@@ -188,9 +190,17 @@ def test_purge_key_ok(self, monkeypatch):
|
188 | 190 | "Fastly-Key": "an api key",
|
189 | 191 | "Fastly-Soft-Purge": "1",
|
190 | 192 | },
|
191 |
| - ) |
| 193 | + ), |
| 194 | + pretend.call( |
| 195 | + "https://api.fastly.com/service/the-service-id/purge/one", |
| 196 | + headers={ |
| 197 | + "Accept": "application/json", |
| 198 | + "Fastly-Key": "an api key", |
| 199 | + "Fastly-Soft-Purge": "1", |
| 200 | + }, |
| 201 | + ), |
192 | 202 | ]
|
193 |
| - assert response.raise_for_status.calls == [pretend.call()] |
| 203 | + assert response.raise_for_status.calls == [pretend.call(), pretend.call()] |
194 | 204 |
|
195 | 205 | @pytest.mark.parametrize("result", [{"status": "fail"}, {}])
|
196 | 206 | def test_purge_key_unsuccessful(self, monkeypatch, result):
|
@@ -218,3 +228,42 @@ def test_purge_key_unsuccessful(self, monkeypatch, result):
|
218 | 228 | )
|
219 | 229 | ]
|
220 | 230 | assert response.raise_for_status.calls == [pretend.call()]
|
| 231 | + |
| 232 | + @pytest.mark.parametrize( |
| 233 | + "result", [[{"status": "ok"}, {"status": "fail"}], [{"status": "ok"}, {}]] |
| 234 | + ) |
| 235 | + def test_purge_key_second_unsuccessful(self, monkeypatch, result): |
| 236 | + cacher = fastly.FastlyCache( |
| 237 | + api_key="an api key", service_id="the-service-id", purger=None |
| 238 | + ) |
| 239 | + |
| 240 | + _result = itertools.cycle(result) |
| 241 | + response = pretend.stub( |
| 242 | + raise_for_status=pretend.call_recorder(lambda: None), |
| 243 | + json=lambda: next(_result), |
| 244 | + ) |
| 245 | + requests_post = pretend.call_recorder(lambda *a, **kw: response) |
| 246 | + monkeypatch.setattr(requests, "post", requests_post) |
| 247 | + |
| 248 | + with pytest.raises(fastly.UnsuccessfulPurgeError): |
| 249 | + cacher.purge_key("one") |
| 250 | + |
| 251 | + assert requests_post.calls == [ |
| 252 | + pretend.call( |
| 253 | + "https://api.fastly.com/service/the-service-id/purge/one", |
| 254 | + headers={ |
| 255 | + "Accept": "application/json", |
| 256 | + "Fastly-Key": "an api key", |
| 257 | + "Fastly-Soft-Purge": "1", |
| 258 | + }, |
| 259 | + ), |
| 260 | + pretend.call( |
| 261 | + "https://api.fastly.com/service/the-service-id/purge/one", |
| 262 | + headers={ |
| 263 | + "Accept": "application/json", |
| 264 | + "Fastly-Key": "an api key", |
| 265 | + "Fastly-Soft-Purge": "1", |
| 266 | + }, |
| 267 | + ), |
| 268 | + ] |
| 269 | + assert response.raise_for_status.calls == [pretend.call(), pretend.call()] |
0 commit comments