mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
test case option error
This commit is contained in:
parent
e3499e4b99
commit
42ea9a2d49
@ -135,6 +135,17 @@ class TestScript:
|
||||
|
||||
assert await tctx.master.await_log("ValueError: Error!")
|
||||
assert await tctx.master.await_log("error.py")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_optionexceptions(self, tdata):
|
||||
with taddons.context() as tctx:
|
||||
sc = script.Script(
|
||||
tdata.path("mitmproxy/data/addonscripts/configure.py"),
|
||||
True,
|
||||
)
|
||||
tctx.master.addons.add(sc)
|
||||
tctx.configure(sc)
|
||||
assert await tctx.master.await_log("Options Error")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_addon(self, tdata):
|
||||
|
27
test/mitmproxy/data/addonscripts/configure.py
Normal file
27
test/mitmproxy/data/addonscripts/configure.py
Normal file
@ -0,0 +1,27 @@
|
||||
import typing
|
||||
|
||||
from mitmproxy import ctx
|
||||
from mitmproxy import exceptions
|
||||
|
||||
|
||||
class TestHeader:
|
||||
def load(self, loader):
|
||||
loader.add_option(
|
||||
name = "testheader",
|
||||
typespec = typing.Optional[int],
|
||||
default = None,
|
||||
help = "test header",
|
||||
)
|
||||
|
||||
def configure(self, updates):
|
||||
raise exceptions.OptionsError("Options Error")
|
||||
|
||||
def response(self, flow):
|
||||
if ctx.options.testheader is not None:
|
||||
flow.response.headers["testheader"] = str(ctx.options.testheader)
|
||||
|
||||
|
||||
addons = [
|
||||
TestHeader()
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user