[web] Update tests.

This commit is contained in:
Matthew Shao 2017-07-26 15:16:23 +08:00
parent c3cb77adce
commit 4282dc1ac4
5 changed files with 20 additions and 41 deletions

View File

@ -12,7 +12,7 @@ from .. import tservers
class TestDumpMaster(tservers.MasterTest): class TestDumpMaster(tservers.MasterTest):
def mkmaster(self, flt, **opts): def mkmaster(self, flt, **opts):
o = options.Options(view_filter=flt, verbosity=-1, flow_detail=0, **opts) o = options.Options(view_filter=flt, verbosity='error', flow_detail=0, **opts)
m = dump.DumpMaster(o, proxy.DummyServer(), with_termlog=False, with_dumper=False) m = dump.DumpMaster(o, proxy.DummyServer(), with_termlog=False, with_dumper=False)
return m return m

View File

@ -264,16 +264,7 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
assert self.put_json("/options", {"anticache": "foo"}).code == 400 assert self.put_json("/options", {"anticache": "foo"}).code == 400
def test_option_dump(self): def test_option_dump(self):
resp = self.fetch("/options/dump") assert self.fetch("/options/dump", method="POST").code == 200
assert b"http2: false" in resp.body
assert self.fetch("/options/dump", method="POST", body=b"http2: true").code == 200
j = json(self.fetch("/options"))
assert j["http2"]["value"]
resp = self.fetch("/options/dump", method="POST", body=b"wtf: true")
assert resp.code == 400
assert resp.body == b"'Unknown options: wtf'"
def test_err(self): def test_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f: with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f:

View File

@ -117,7 +117,7 @@ exports[`Modal Component should render correctly 2`] = `
name="choiceOption" name="choiceOption"
onChange={[Function]} onChange={[Function]}
onKeyDown={[Function]} onKeyDown={[Function]}
selected="b" value="b"
> >
<option <option
value="a" value="a"
@ -246,34 +246,7 @@ exports[`Modal Component should render correctly 2`] = `
</div> </div>
<div <div
className="modal-footer" className="modal-footer"
> />
<button
className="btn btn-default"
onClick={[Function]}
type="button"
>
<i
className="fa fa-download"
/>
Download
</button>
<a
className="btn btn-primary"
href="#"
onClick={[Function]}
title={undefined}
>
<i
className="fa fa-fw fa-upload"
/>
Load
<input
className="hidden"
onChange={[Function]}
type="file"
/>
</a>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -18,7 +18,7 @@ exports[`BooleanOption Component should render correctly 1`] = `
exports[`ChoiceOption Component should render correctly 1`] = ` exports[`ChoiceOption Component should render correctly 1`] = `
<select <select
onChange={[Function]} onChange={[Function]}
selected="a" value="a"
> >
<option <option
value="a" value="a"

View File

@ -49,3 +49,18 @@ describe('sendUpdate', () => {
]) ])
}) })
}) })
describe('dump', () => {
it('should dump options', () => {
global.fetch = jest.fn()
store.dispatch(OptionsActions.dump())
expect(fetch).toBeCalledWith(
'/options/dump?_xsrf=undefined',
{
credentials: "same-origin",
method: "POST"
}
)
})
})