|
3 | 3 | Unit tests for atlassian.rest_client module |
4 | 4 | """ |
5 | 5 |
|
| 6 | +import io |
6 | 7 | from datetime import datetime, timedelta |
7 | 8 | from types import SimpleNamespace |
8 | 9 |
|
@@ -184,6 +185,37 @@ def test_advanced_mode(self): |
184 | 185 | api = AtlassianRestAPI(url=f"{mockup_server()}/test", advanced_mode=True) |
185 | 186 | assert api.advanced_mode is True |
186 | 187 |
|
| 188 | + def test_request_rewinds_uploaded_file_before_retry(self): |
| 189 | + class RetryingSession: |
| 190 | + def __init__(self): |
| 191 | + self.verify = True |
| 192 | + self.payloads = [] |
| 193 | + self.responses = [ |
| 194 | + SimpleNamespace(status_code=503, headers={}, reason="Unavailable", text=""), |
| 195 | + SimpleNamespace(status_code=200, headers={}, reason="OK", text=""), |
| 196 | + ] |
| 197 | + |
| 198 | + def request(self, **kwargs): |
| 199 | + self.payloads.append(kwargs["files"]["file"][1].read()) |
| 200 | + return self.responses.pop(0) |
| 201 | + |
| 202 | + session = RetryingSession() |
| 203 | + api = AtlassianRestAPI( |
| 204 | + url="https://example.test", |
| 205 | + session=session, |
| 206 | + advanced_mode=True, |
| 207 | + retry_status_codes=[503], |
| 208 | + max_backoff_retries=1, |
| 209 | + backoff_factor=0, |
| 210 | + backoff_jitter=0, |
| 211 | + ) |
| 212 | + api.backoff_and_retry = True |
| 213 | + api.use_urllib3_retry = False |
| 214 | + |
| 215 | + api.request("POST", "attachment", files={"file": ("report.csv", io.BytesIO(b"small report"))}) |
| 216 | + |
| 217 | + assert session.payloads == [b"small report", b"small report"] |
| 218 | + |
187 | 219 | def test_kerberos_configuration(self): |
188 | 220 | """Test kerberos configuration""" |
189 | 221 | # Test that kerberos config is accepted without errors |
|
0 commit comments