def mk(self): s = state.State() o = options.Options(stickycookie=".*") m = master.FlowMaster(o, None, s) sc = stickycookie.StickyCookie() m.addons.add(o, sc) return s, m, sc
def test_stream(self): with tutils.tmpdir() as tdir: p = os.path.join(tdir, "foo") def r(): r = FlowReader(open(p, "rb")) return list(r.stream()) s = state.State() o = options.Options(outfile=(p, "wb")) m = master.FlowMaster(o, None, s) sa = filestreamer.FileStreamer() m.addons.add(sa) f = tutils.tflow(resp=True) m.request(f) m.response(f) m.addons.remove(sa) assert r()[0].response m.options.outfile = (p, "ab") m.addons.add(sa) f = tutils.tflow() m.request(f) m.addons.remove(sa) assert not r()[1].response
def test_addon(self): s = state.State() o = options.Options() m = master.FlowMaster(o, None, s) sc = script.Script(tutils.test_data.path("data/addonscripts/addon.py")) m.addons.add(sc) assert sc.ns.event_log == [ 'scriptstart', 'addonstart', 'addonconfigure' ]
def test_simple(self): s = state.State() o = options.Options(scripts=[]) m = master.FlowMaster(o, None, s) sc = script.ScriptLoader() m.addons.add(sc) assert len(m.addons) == 1 o.update( scripts=[tutils.test_data.path("data/addonscripts/recorder.py")]) assert len(m.addons) == 2 o.update(scripts=[]) assert len(m.addons) == 1
def test_duplicate_flow(self): s = state.State() o = options.Options() fm = master.FlowMaster(o, None, s) fm.addons.add( script.Script( tutils.test_data.path("data/addonscripts/duplicate_flow.py"))) f = tutils.tflow() fm.request(f) assert fm.state.flow_count() == 2 assert not fm.state.view[0].request.is_replay assert fm.state.view[1].request.is_replay
def test_concurrent(self): s = state.State() m = master.FlowMaster(options.Options(), None, s) sc = script.Script( tutils.test_data.path("data/addonscripts/concurrent_decorator.py")) m.addons.add(m.options, sc) f1, f2 = tutils.tflow(), tutils.tflow() self.invoke(m, "request", f1) self.invoke(m, "request", f2) start = time.time() while time.time() - start < 5: if f1.reply.acked and f2.reply.acked: return raise ValueError("Script never acked")
def test_concurrent(self): s = state.State() m = master.FlowMaster(options.Options(), None, s) sc = script.Script( tutils.test_data.path("data/addonscripts/concurrent_decorator.py")) m.addons.add(sc) f1, f2 = tutils.tflow(), tutils.tflow() m.request(f1) m.request(f2) start = time.time() while time.time() - start < 5: if f1.reply.state == f2.reply.state == "committed": return raise ValueError("Script never acked")
def test_simple(self): s = state.State() o = options.Options(anticomp=True) m = master.FlowMaster(o, None, s) sa = anticomp.AntiComp() m.addons.add(o, sa) f = tutils.tflow(resp=True) m.request(f) f = tutils.tflow(resp=True) f.request.headers["Accept-Encoding"] = "foobar" m.request(f) assert f.request.headers["Accept-Encoding"] == "identity"
def test_simple(self): s = state.State() o = options.Options() m = master.FlowMaster(o, None, s) sc = script.Script( tutils.test_data.path("data/addonscripts/recorder.py")) m.addons.add(sc) assert sc.ns.call_log == [("solo", "start", (), {}), ("solo", "configure", (o, o.keys()), {})] sc.ns.call_log = [] f = tutils.tflow(resp=True) m.request(f) recf = sc.ns.call_log[0] assert recf[1] == "request"
def test_simple(self): s = state.State() o = options.Options(stickyauth=".*") m = master.FlowMaster(o, None, s) sa = stickyauth.StickyAuth() m.addons.add(sa) f = tutils.tflow(resp=True) f.request.headers["authorization"] = "foo" m.request(f) assert "address" in sa.hosts f = tutils.tflow(resp=True) m.request(f) assert f.request.headers["authorization"] == "foo"
def test_simple(self): s = state.State() o = options.Options(anticache = True) m = master.FlowMaster(o, None, s) sa = anticache.AntiCache() m.addons.add(o, sa) f = tutils.tflow(resp=True) self.invoke(m, "request", f) f = tutils.tflow(resp=True) f.request.headers["if-modified-since"] = "test" f.request.headers["if-none-match"] = "test" self.invoke(m, "request", f) assert "if-modified-since" not in f.request.headers assert "if-none-match" not in f.request.headers
def test_run_once(self): s = state.State() o = options.Options(scripts=[]) m = master.FlowMaster(o, None, s) sl = script.ScriptLoader() m.addons.add(o, sl) f = tutils.tflow(resp=True) with m.handlecontext(): sc = sl.run_once( tutils.test_data.path("data/addonscripts/recorder.py"), [f]) evts = [i[1] for i in sc.ns.call_log] assert evts == [ 'start', 'request', 'responseheaders', 'response', 'done' ] with m.handlecontext(): tutils.raises("file not found", sl.run_once, "nonexistent", [f])
def test_simple(self): s = state.State() o = options.Options(replacements=[ ("~q", "foo", "bar"), ("~s", "foo", "bar"), ]) m = master.FlowMaster(o, None, s) sa = replace.Replace() m.addons.add(o, sa) f = tutils.tflow() f.request.content = b"foo" self.invoke(m, "request", f) assert f.request.content == b"bar" f = tutils.tflow(resp=True) f.response.content = b"foo" self.invoke(m, "response", f) assert f.response.content == b"bar"
def test_dupes(self): s = state.State() o = options.Options(scripts=["one", "one"]) m = master.FlowMaster(o, None, s) sc = script.ScriptLoader() tutils.raises(exceptions.OptionsError, m.addons.add, o, sc)