本文整理汇总了Python中netlib.tutils.tflow函数的典型用法代码示例。如果您正苦于以下问题:Python tflow函数的具体用法?Python tflow怎么用?Python tflow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tflow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ignore_payload_params
def test_ignore_payload_params(self):
s = serverplayback.ServerPlayback()
s.configure(
options.Options(
server_replay_ignore_payload_params=["param1", "param2"]
),
[]
)
r = tutils.tflow(resp=True)
r.request.headers["Content-Type"] = "application/x-www-form-urlencoded"
r.request.content = b"paramx=x¶m1=1"
r2 = tutils.tflow(resp=True)
r2.request.headers["Content-Type"] = "application/x-www-form-urlencoded"
r2.request.content = b"paramx=x¶m1=1"
# same parameters
assert s._hash(r) == s._hash(r2)
# ignored parameters !=
r2.request.content = b"paramx=x¶m1=2"
assert s._hash(r) == s._hash(r2)
# missing parameter
r2.request.content = b"paramx=x"
assert s._hash(r) == s._hash(r2)
# ignorable parameter added
r2.request.content = b"paramx=x¶m1=2"
assert s._hash(r) == s._hash(r2)
# not ignorable parameter changed
r2.request.content = b"paramx=y¶m1=1"
assert not s._hash(r) == s._hash(r2)
# not ignorable parameter missing
r2.request.content = b"param1=1"
assert not s._hash(r) == s._hash(r2)
示例2: test_ignore_content
def test_ignore_content(self):
s = serverplayback.ServerPlayback()
s.configure(options.Options(server_replay_ignore_content=False), [])
r = tutils.tflow(resp=True)
r2 = tutils.tflow(resp=True)
r.request.content = b"foo"
r2.request.content = b"foo"
assert s._hash(r) == s._hash(r2)
r2.request.content = b"bar"
assert not s._hash(r) == s._hash(r2)
s.configure(options.Options(server_replay_ignore_content=True), [])
r = tutils.tflow(resp=True)
r2 = tutils.tflow(resp=True)
r.request.content = b"foo"
r2.request.content = b"foo"
assert s._hash(r) == s._hash(r2)
r2.request.content = b"bar"
assert s._hash(r) == s._hash(r2)
r2.request.content = b""
assert s._hash(r) == s._hash(r2)
r2.request.content = None
assert s._hash(r) == s._hash(r2)
示例3: test_server_playback_full
def test_server_playback_full(self):
state = flow.State()
s = serverplayback.ServerPlayback()
o = options.Options(refresh_server_playback = True, keepserving=False)
m = mastertest.RecordingMaster(o, None, state)
m.addons.add(s)
f = tutils.tflow()
f.response = netlib.tutils.tresp(content=f.request.content)
s.load([f, f])
tf = tutils.tflow()
assert not tf.response
m.request(tf)
assert tf.response == f.response
tf = tutils.tflow()
tf.request.content = b"gibble"
assert not tf.response
m.request(tf)
assert not tf.response
assert not s.stop
s.tick()
assert not s.stop
tf = tutils.tflow()
m.request(tutils.tflow())
assert s.stop
示例4: test_ignore_host
def test_ignore_host(self):
sp = serverplayback.ServerPlayback()
sp.configure(options.Options(server_replay_ignore_host=True), [])
r = tutils.tflow(resp=True)
r2 = tutils.tflow(resp=True)
r.request.host = "address"
r2.request.host = "address"
assert sp._hash(r) == sp._hash(r2)
r2.request.host = "wrong_address"
assert sp._hash(r) == sp._hash(r2)
示例5: test_server_playback_kill
def test_server_playback_kill(self):
state = flow.State()
s = serverplayback.ServerPlayback()
o = options.Options(refresh_server_playback = True, replay_kill_extra=True)
m = mastertest.RecordingMaster(o, None, state)
m.addons.add(s)
f = tutils.tflow()
f.response = netlib.tutils.tresp(content=f.request.content)
s.load([f])
f = tutils.tflow()
f.request.host = "nonexistent"
m.request(f)
assert f.reply.value == exceptions.Kill
示例6: test_load_with_server_replay_nopop
def test_load_with_server_replay_nopop(self):
s = serverplayback.ServerPlayback()
s.configure(options.Options(server_replay_nopop=True), [])
r = tutils.tflow(resp=True)
r.request.headers["key"] = "one"
r2 = tutils.tflow(resp=True)
r2.request.headers["key"] = "two"
s.load([r, r2])
assert s.count() == 2
s.next_flow(r)
assert s.count() == 2
示例7: test_post_json
def test_post_json(self):
req_post.content = '{"name": "example", "email": "[email protected]"}'
req_post.headers = Headers(content_type="application/json")
flow = tutils.tflow(req=req_post)
result = dedent("""
import requests
url = 'http://address/path'
headers = {
'content-type': 'application/json',
}
json = {
"name": "example",
"email": "[email protected]"
}
response = requests.request(
method='POST',
url=url,
headers=headers,
json=json,
)
print(response.text)
""").strip()
assert flow_export.python_code(flow) == result
示例8: test_patch
def test_patch(self):
flow = tutils.tflow(req=req_patch)
result = ' ' + """
@task()
def path(self):
url = self.locust.host + '/path'
headers = {
'header': 'qvalue',
'content-length': '7',
}
params = {
'query': 'param',
}
data = '''content'''
self.response = self.client.request(
method='PATCH',
url=url,
headers=headers,
params=params,
data=data,
)
""".strip() + '\n'
assert flow_export.locust_task(flow) == result
示例9: test_patch
def test_patch(self):
flow = tutils.tflow(req=req_patch)
result = dedent("""
import requests
url = 'http://address/path'
headers = {
'header': 'qvalue',
'content-length': '7',
}
params = {
'query': 'param',
}
data = '''content'''
response = requests.request(
method='PATCH',
url=url,
headers=headers,
params=params,
data=data,
)
print(response.text)
""").strip()
assert flow_export.python_code(flow) == result
示例10: test_headers
def test_headers(self):
s = serverplayback.ServerPlayback()
s.configure(options.Options(server_replay_use_headers=["foo"]), [])
r = tutils.tflow(resp=True)
r.request.headers["foo"] = "bar"
r2 = tutils.tflow(resp=True)
assert not s._hash(r) == s._hash(r2)
r2.request.headers["foo"] = "bar"
assert s._hash(r) == s._hash(r2)
r2.request.headers["oink"] = "bar"
assert s._hash(r) == s._hash(r2)
r = tutils.tflow(resp=True)
r2 = tutils.tflow(resp=True)
assert s._hash(r) == s._hash(r2)
示例11: test_post
def test_post(self):
req_post.content = '''content'''
req_post.headers = ''
flow = tutils.tflow(req=req_post)
result = """
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
def on_start(self):
''' on_start is called when a Locust start before any task is scheduled '''
self.path()
@task()
def path(self):
url = self.locust.host + '/path'
data = '''content'''
self.response = self.client.request(
method='POST',
url=url,
data=data,
)
### Additional tasks can go here ###
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 1000
max_wait = 3000
""".strip()
assert flow_export.locust_code(flow) == result
示例12: test_contentview
def test_contentview(get_content_view):
get_content_view.side_effect = ContentViewException(""), ("x", iter([]))
o = dump.Options(flow_detail=4, verbosity=3)
m = dump.DumpMaster(None, o, StringIO())
m.echo_flow(tutils.tflow())
assert "Content viewer failed" in m.outfile.getvalue()
示例13: test_get
def test_get(self):
flow = tutils.tflow(req=req_get)
result = """
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
def on_start(self):
''' on_start is called when a Locust start before any task is scheduled '''
self.path()
@task()
def path(self):
url = self.locust.host + '/path'
headers = {
'header': 'qvalue',
'content-length': '7',
}
self.response = self.client.request(
method='GET',
url=url,
headers=headers,
)
### Additional tasks can go here ###
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 1000
max_wait = 3000
""".strip()
assert flow_export.locust_code(flow) == result
示例14: test_hash
def test_hash(self):
s = serverplayback.ServerPlayback()
s.configure(options.Options(), [])
r = tutils.tflow()
r2 = tutils.tflow()
assert s._hash(r)
assert s._hash(r) == s._hash(r2)
r.request.headers["foo"] = "bar"
assert s._hash(r) == s._hash(r2)
r.request.path = "voing"
assert s._hash(r) != s._hash(r2)
r.request.path = "path?blank_value"
r2.request.path = "path?"
assert s._hash(r) != s._hash(r2)
示例15: test_error
def test_error(self):
cs = StringIO()
o = dump.Options(flow_detail=1)
m = dump.DumpMaster(None, o, outfile=cs)
f = tutils.tflow(err=True)
m.handle_request(f)
assert m.handle_error(f)
assert "error" in cs.getvalue()