MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / test_simple

Method test_simple

test/mitmproxy/addons/test_maplocal.py:144–172  ·  view source on GitHub ↗
(self, tmpdir)

Source from the content-addressed store, hash-verified

142 tctx.configure(ml, map_local=["/foo/.+/three"])
143
144 def test_simple(self, tmpdir):
145 ml = MapLocal()
146
147 with taddons.context(ml) as tctx:
148 tmpfile = tmpdir.join("foo.jpg")
149 tmpfile.write("foo")
150 tctx.configure(ml, map_local=["|//example.org/images|" + str(tmpdir)])
151 f = tflow.tflow()
152 f.request.url = b"https://example.org/images/foo.jpg"
153 ml.request(f)
154 assert f.response.content == b"foo"
155
156 tmpfile = tmpdir.join("images", "bar.jpg")
157 tmpfile.write("bar", ensure=True)
158 tctx.configure(ml, map_local=["|//example.org|" + str(tmpdir)])
159 f = tflow.tflow()
160 f.request.url = b"https://example.org/images/bar.jpg"
161 ml.request(f)
162 assert f.response.content == b"bar"
163
164 tmpfile = tmpdir.join("foofoobar.jpg")
165 tmpfile.write("foofoobar", ensure=True)
166 tctx.configure(
167 ml, map_local=["|example.org/foo/foo/bar.jpg|" + str(tmpfile)]
168 )
169 f = tflow.tflow()
170 f.request.url = b"https://example.org/foo/foo/bar.jpg"
171 ml.request(f)
172 assert f.response.content == b"foofoobar"
173
174 async def test_nonexistent_files(self, tmpdir, monkeypatch, caplog):
175 caplog.set_level("INFO")

Callers

nothing calls this directly

Calls 6

requestMethod · 0.95
MapLocalClass · 0.90
contextMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
configureMethod · 0.45

Tested by

no test coverage detected