| 2580 | |
| 2581 | |
| 2582 | class RedirectSession(SessionRedirectMixin): |
| 2583 | def __init__(self, order_of_redirects): |
| 2584 | self.redirects = order_of_redirects |
| 2585 | self.calls = [] |
| 2586 | self.max_redirects = 30 |
| 2587 | self.cookies = {} |
| 2588 | self.trust_env = False |
| 2589 | |
| 2590 | def send(self, *args, **kwargs): |
| 2591 | self.calls.append(SendCall(args, kwargs)) |
| 2592 | return self.build_response() |
| 2593 | |
| 2594 | def build_response(self): |
| 2595 | request = self.calls[-1].args[0] |
| 2596 | r = requests.Response() |
| 2597 | r.url = request.url |
| 2598 | |
| 2599 | try: |
| 2600 | r.status_code = int(self.redirects.pop(0)) |
| 2601 | except IndexError: |
| 2602 | r.status_code = 200 |
| 2603 | |
| 2604 | r.headers = CaseInsensitiveDict({"Location": "/"}) |
| 2605 | r.raw = self._build_raw() |
| 2606 | r.request = request |
| 2607 | return r |
| 2608 | |
| 2609 | def _build_raw(self): |
| 2610 | string = StringIO.StringIO("") |
| 2611 | setattr(string, "release_conn", lambda *args: args) |
| 2612 | return string |
| 2613 | |
| 2614 | |
| 2615 | def test_json_encodes_as_bytes(): |
no outgoing calls