本文整理匯總了Python中locust.HttpLocust方法的典型用法代碼示例。如果您正苦於以下問題:Python locust.HttpLocust方法的具體用法?Python locust.HttpLocust怎麽用?Python locust.HttpLocust使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類locust
的用法示例。
在下文中一共展示了locust.HttpLocust方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_it_renders_a_locustfile_template
# 需要導入模塊: import locust [as 別名]
# 或者: from locust import HttpLocust [as 別名]
def test_it_renders_a_locustfile_template(self):
a_name = "some_task"
a_request = MagicMock(spec=Request)
a_request.method = HttpMethod.GET
a_request.url = MagicMock(spec=SplitResult)
a_request.url.scheme = "some_scheme"
a_request.url.hostname = "some_hostname"
a_request.url.path = "some_path"
a_request.url.geturl()
a_request.url.geturl.return_value = "some_url"
a_request.headers = {"a": "b"}
a_request.name = None
task = Task(a_name, a_request)
scenario = Scenario(name="SomeScenario", children=[task], origin=None)
scenario_group = Scenario(
name="ScenarioGroup", children=[scenario], weight=2, origin=None
)
script = locustfile([scenario_group])
expected = string.Template(
f"""
# File automatically generated by Transformer v{__version__}:
# https://github.com/zalando-incubator/Transformer
import re
from distutils.version import LooseVersion
from locust import __version__
LOCUST_MAJOR_VERSION = LooseVersion(__version__).version[0]
if LOCUST_MAJOR_VERSION >= 1:
from locust import HttpUser
from locust import SequentialTaskSet
from locust import TaskSet
from locust import task
HttpLocust = HttpUser
TaskSequence = SequentialTaskSet
def seq_task(_):
return task
else:
from locust import HttpLocust
from locust import TaskSequence
from locust import TaskSet
from locust import seq_task
from locust import task
class ScenarioGroup(TaskSet):
@task(1)
class SomeScenario(TaskSequence):
@seq_task(1)
def some_task(self):
response = self.client.get(url='some_url', name='some_url', timeout=$TIMEOUT, allow_redirects=False, headers={{'a': 'b'}})
class LocustForScenarioGroup(HttpLocust):
if LOCUST_MAJOR_VERSION >= 1:
tasks = [ScenarioGroup]
else:
task_set = ScenarioGroup
weight = 2
min_wait = 0
max_wait = 10
"""
).safe_substitute({"TIMEOUT": TIMEOUT})
assert expected.strip() == script.strip()