Пример #1
0
class App(object):
    def __init__(self, forward_url, record_file_path):
        forwarder = Forwarder(forward_url)
        self.recorder = HTTPRecorder(record_file_path)
        forwarder.on_forward_complete(lambda req, res: self.recorder.record_http(req, res))
        self._app = forwarder

    def run(self, host, port):
        self.recorder.start_service()
        try:
            run_simple(host, port, self._app, use_debugger=DEBUG, use_reloader=DEBUG)
        finally:
            self.recorder.close()
Пример #2
0
def test_http_recorder():
    _, filepath = tempfile.mkstemp()
    formatter = Formatter()
    recorder = HTTPRecorder(filepath)
    try:
        recorder.start_service()
        recorder.record_http(req, res)
    finally:
        recorder.close()

    with open(filepath, 'r') as readable:
        request, response = formatter.read_record(readable)
        assert req.__dict__ == request.__dict__
        assert res.__dict__ == response.__dict__

    os.remove(filepath)
Пример #3
0
def test_http_recorder():
    _, filepath = tempfile.mkstemp()
    formatter = Formatter()
    recorder = HTTPRecorder(filepath)
    try:
        recorder.start_service()
        recorder.record_http(req, res)
    finally:
        recorder.close()

    with open(filepath, 'r') as readable:
        request, response = formatter.read_record(readable)
        assert req.__dict__ == request.__dict__
        assert res.__dict__ == response.__dict__

    os.remove(filepath)
Пример #4
0
 def __init__(self, forward_url, record_file_path):
     forwarder = Forwarder(forward_url)
     self.recorder = HTTPRecorder(record_file_path)
     forwarder.on_forward_complete(lambda req, res: self.recorder.record_http(req, res))
     self._app = forwarder