mirror of
https://github.com/ihabunek/toot.git
synced 2025-10-21 19:44:16 -04:00
Use http methods instead of requests directly
This commit is contained in:
@@ -1,3 +1,31 @@
|
||||
import requests
|
||||
|
||||
|
||||
class Expectations():
|
||||
"""Helper for mocking http requests"""
|
||||
def __init__(self, requests=[], responses=[]):
|
||||
self.requests = requests
|
||||
self.responses = responses
|
||||
|
||||
def mock_prepare(self, request):
|
||||
expected = self.requests.pop(0)
|
||||
assert request.method == expected.method
|
||||
assert request.url == expected.url
|
||||
assert request.data == expected.data
|
||||
assert request.headers == expected.headers
|
||||
assert request.params == expected.params
|
||||
|
||||
def mock_send(self, *args, **kwargs):
|
||||
return self.responses.pop(0)
|
||||
|
||||
def add(self, req, res):
|
||||
self.requests.append(req)
|
||||
self.responses.append(res)
|
||||
|
||||
def patch(self, monkeypatch):
|
||||
monkeypatch.setattr(requests.Session, 'prepare_request', self.mock_prepare)
|
||||
monkeypatch.setattr(requests.Session, 'send', self.mock_send)
|
||||
|
||||
|
||||
class MockResponse:
|
||||
def __init__(self, response_data={}, ok=True, is_redirect=False):
|
||||
|
||||
Reference in New Issue
Block a user