From 50c07034249a07f25172230b689c4c6da1b63c2d Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Fri, 19 May 2017 09:45:30 +0800 Subject: [web] Add _tflow.js generator in test_app.py --- test/mitmproxy/tools/web/test_app.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index 2b6181d3..dc5fe733 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -1,5 +1,6 @@ import json as _json from unittest import mock +import os import tornado.testing from tornado import httpclient @@ -12,7 +13,6 @@ from mitmproxy.test import tflow from mitmproxy.tools.web import app from mitmproxy.tools.web import master as webmaster - def json(resp: httpclient.HTTPResponse): return _json.loads(resp.body.decode()) @@ -275,3 +275,13 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): # trigger on_close by opening a second connection. ws_client2 = yield websocket.websocket_connect(ws_url) ws_client2.close() + + def test_generate_tflow_js(self): + tflow_json = _json.dumps( + app.flow_to_json(tflow.tflow(resp=True, err=True)), indent=4, sort_keys=True + ) + web_root = os.path.join(os.getcwd(), 'web') + tflow_path = os.path.join(web_root, 'src/js/__tests__/ducks/_tflow.js') + content = """export default function(){{\n return {tflow_json}\n}}""".format(tflow_json=tflow_json) + with open(tflow_path, 'w') as f: + f.write(content) -- cgit v1.2.3 From 369e1f1eeebf94951c592ac712f84086e0bc7b41 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Fri, 19 May 2017 09:56:52 +0800 Subject: [web] Fix minior lint problem. --- test/mitmproxy/tools/web/test_app.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index dc5fe733..8a81e0e0 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -13,6 +13,7 @@ from mitmproxy.test import tflow from mitmproxy.tools.web import app from mitmproxy.tools.web import master as webmaster + def json(resp: httpclient.HTTPResponse): return _json.loads(resp.body.decode()) -- cgit v1.2.3 From 2c38fddea5eae0fe60822ee2fcf2565889f258b9 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sun, 21 May 2017 20:59:19 +0800 Subject: [web] TFlow minor improved. --- test/mitmproxy/tools/web/test_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index 8a81e0e0..f6072efb 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -281,7 +281,8 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): tflow_json = _json.dumps( app.flow_to_json(tflow.tflow(resp=True, err=True)), indent=4, sort_keys=True ) - web_root = os.path.join(os.getcwd(), 'web') + here = os.path.abspath(os.path.dirname(__file__)) + web_root = os.path.join(here, os.pardir, os.pardir, os.pardir, os.pardir, 'web') tflow_path = os.path.join(web_root, 'src/js/__tests__/ducks/_tflow.js') content = """export default function(){{\n return {tflow_json}\n}}""".format(tflow_json=tflow_json) with open(tflow_path, 'w') as f: -- cgit v1.2.3 From 2935ff5f3ac01124b8c4c3d2688964ddaba12f4d Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 22 May 2017 08:53:59 +0800 Subject: [web] Set some value as constant, so _tflow.js would not change. --- test/mitmproxy/tools/web/test_app.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index f6072efb..5427b995 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -278,9 +278,15 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): ws_client2.close() def test_generate_tflow_js(self): - tflow_json = _json.dumps( - app.flow_to_json(tflow.tflow(resp=True, err=True)), indent=4, sort_keys=True - ) + _tflow = app.flow_to_json(tflow.tflow(resp=True, err=True)) + # Set some value as constant, so that _tflow.js would not change every time. + _tflow['client_conn']['id'] = "4a18d1a0-50a1-48dd-9aa6-d45d74282939" + _tflow['id'] = "d91165be-ca1f-4612-88a9-c0f8696f3e29" + _tflow['error']['timestamp'] = 1495370312.4814785 + _tflow['response']['timestamp_end'] = 1495370312.4814625 + _tflow['response']['timestamp_start'] = 1495370312.481462 + _tflow['server_conn']['id'] = "f087e7b2-6d0a-41a8-a8f0-e1a4761395f8" + tflow_json = _json.dumps(_tflow, indent=4, sort_keys=True) here = os.path.abspath(os.path.dirname(__file__)) web_root = os.path.join(here, os.pardir, os.pardir, os.pardir, os.pardir, 'web') tflow_path = os.path.join(web_root, 'src/js/__tests__/ducks/_tflow.js') -- cgit v1.2.3