add hook feature:

1, setup_hook: call function before request
2, teardown_hook: call function after request
This commit is contained in:
debugtalk
2018-03-14 11:57:35 +08:00
parent c7a1a17b3c
commit 8c618d2325
8 changed files with 129 additions and 64 deletions

View File

@@ -1,6 +1,8 @@
from httprunner.client import HttpSession, prepare_kwargs
from httprunner.built_in import setup_hook_prepare_kwargs
from httprunner.client import HttpSession
from tests.base import ApiServerUnittest
class TestHttpClient(ApiServerUnittest):
def setUp(self):
super(TestHttpClient, self).setUp()
@@ -46,7 +48,7 @@ class TestHttpClient(ApiServerUnittest):
"b": 2
}
}
prepare_kwargs("POST", kwargs)
setup_hook_prepare_kwargs("POST", "/path", kwargs)
self.assertIn('"a": 1', kwargs["data"])
self.assertIn('"b": 2', kwargs["data"])
@@ -60,5 +62,5 @@ class TestHttpClient(ApiServerUnittest):
"b": 2
}
}
prepare_kwargs("POST", kwargs)
setup_hook_prepare_kwargs("POST", "/path", kwargs)
self.assertIsInstance(kwargs["data"], bytes)