Source

xnet-hacks / tests / mocksupport.py


class MockResponse:
    def __init__(self, status, data):
        self.status = status
        self._data = data

    def read(self):
        x = self._data
        self._data = ""
        return x

class MockConnGet:
    hostspec = '<testing>'
    def __init__(self, url, data):
        self._url = url
        self._data = data

    def GET(self, url, body=None, headers={}):
        assert url == self._url
        return MockResponse(200, self._data)

class MockConnPost:
    hostspec = '<testing>'
    def __init__(self, url, responsedata, status=201):
        self._url = url
        self._responsedata = responsedata
        self._status = status

    def POST(self, url, body=None, headers={}):
        assert url == self._url
        self._body = body
        return MockResponse(self._status, self._responsedata)