def test_nowrite(self, xom, blank_request): l = [] def wrapped_handler(request): l.append(xom.keyfs.get_current_serial()) return Response("") handler = tween_replica_proxy(wrapped_handler, {"xom": xom}) handler(blank_request()) assert l == [xom.keyfs.get_current_serial()]
def test_preserve_reason(self, makexom, blank_request, reqmock, monkeypatch): xom = makexom(["--master", "http://localhost"]) reqmock.mock("http://localhost/blankpath", code=200, reason="GOOD", headers={"X-DEVPI-SERIAL": "10"}) l = [] monkeypatch.setattr(xom.keyfs, "wait_tx_serial", lambda x: l.append(x)) handler = tween_replica_proxy(None, {"xom": xom}) response = handler(blank_request(method="PUT")) assert response.status == "200 GOOD"
def test_hop_headers(self, makexom, blank_request, reqmock, monkeypatch): xom = makexom(["--master", "http://localhost"]) reqmock.mock("http://localhost/blankpath", code=200, headers={ "Connection": "Keep-Alive, Foo", "Foo": "abc", "Keep-Alive": "timeout=30", "X-DEVPI-SERIAL": "0"}) monkeypatch.setattr(xom.keyfs, "wait_tx_serial", lambda x: x) handler = tween_replica_proxy(None, {"xom": xom}) response = handler(blank_request(method="PUT")) assert 'connection' not in response.headers assert 'foo' not in response.headers assert 'keep-alive' not in response.headers
def test_write_proxies_redirect(self, makexom, blank_request, reqmock, monkeypatch): xom = makexom(["--master", "http://localhost", "--outside-url=http://my.domain"]) reqmock.mock("http://localhost/blankpath", code=302, headers={"X-DEVPI-SERIAL": "10", "location": "http://localhost/hello"} ) l = [] monkeypatch.setattr(xom.keyfs, "wait_tx_serial", lambda x: l.append(x)) handler = tween_replica_proxy(None, {"xom": xom}) # normally the app is wrapped by OutsideURLMiddleware, since this is # not the case here, we have to set the host explicitly response = handler( blank_request(method="PUT", headers=dict(host='my.domain'))) assert response.headers.get("X-DEVPI-SERIAL") == "10" assert response.headers.get("location") == "http://my.domain/hello" assert l == [10]