Introduction
Introduction Statistics Contact Development Disclaimer Help
utils.py - toot - Unnamed repository; edit this file 'description' to name the …
Log
Files
Refs
LICENSE
---
utils.py (1276B)
---
1 import requests
2
3
4 class Expectations():
5 """Helper for mocking http requests"""
6 def __init__(self, requests=[], responses=[]):
7 self.requests = requests
8 self.responses = responses
9
10 def mock_prepare(self, request):
11 expected = self.requests.pop(0)
12 assert request.method == expected.method
13 assert request.url == expected.url
14 assert request.data == expected.data
15 assert request.headers == expected.headers
16 assert request.params == expected.params
17
18 def mock_send(self, *args, **kwargs):
19 return self.responses.pop(0)
20
21 def add(self, req, res):
22 self.requests.append(req)
23 self.responses.append(res)
24
25 def patch(self, monkeypatch):
26 monkeypatch.setattr(requests.Session, 'prepare_request', self.mo…
27 monkeypatch.setattr(requests.Session, 'send', self.mock_send)
28
29
30 class MockResponse:
31 def __init__(self, response_data={}, ok=True, is_redirect=False):
32 self.response_data = response_data
33 self.content = response_data
34 self.ok = ok
35 self.is_redirect = is_redirect
36
37 def raise_for_status(self):
38 pass
39
40 def json(self):
41 return self.response_data
42
43
44 def retval(val):
45 return lambda *args, **kwargs: val
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.