本文整理汇总了Python中locust.clients.HttpSession.post方法的典型用法代码示例。如果您正苦于以下问题:Python HttpSession.post方法的具体用法?Python HttpSession.post怎么用?Python HttpSession.post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类locust.clients.HttpSession
的用法示例。
在下文中一共展示了HttpSession.post方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_purchase
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def create_purchase(self):
session = HttpSession(self.base_url)
# self.client.post('/api/v0.9/reservation/', reservation_body)
reservation_response = session.post("/api/v0.9/reservation/", data=reservation_body)
if reservation_response.status_code != 201:
return
if reservation_response.status_code == 409:
raise StopLocust("No available tickets.")
checkout_response = session.post("/api/v0.9/reservation/_checkout", data=checkout_body)
if checkout_response.status_code != 200:
return
purchase = checkout_response.json()["purchase"]
completion_response = session.post(
"/api/v0.9/purchases/_complete",
json.dumps(
dict(
purchase_id=purchase["purchase_id"],
hash=purchase["completion_params"]["hash"],
processor=purchase["completion_params"]["processor"],
payment_ref=purchase["completion_params"]["order_ref"],
)
),
)
示例2: create_purchase
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def create_purchase(self):
session = HttpSession(self.base_url)
# self.client.post('/api/v0.9/reservation/', reservation_body)
reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)
if reservation_response.status_code != 201:
return
checkout_response = session.post('/api/v0.9/reservation/_checkout', data=checkout_body)
示例3: test_post_redirect
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def test_post_redirect(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
url = "/redirect"
r = s.post(url)
self.assertEqual(200, r.status_code)
post_stats = global_stats.get(url, method="POST")
get_stats = global_stats.get(url, method="GET")
self.assertEqual(1, post_stats.num_requests)
self.assertEqual(0, get_stats.num_requests)
示例4: test_post_redirect
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def test_post_redirect(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
url = "/redirect"
r = s.post(url)
assert 200 == r.status_code
post_stats = global_stats.get(url, method="POST")
get_stats = global_stats.get(url, method="GET")
assert 1 == post_stats.num_requests
assert 0 == get_stats.num_requests
示例5: create_purchase
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def create_purchase(self):
session = HttpSession(self.base_url)
# self.client.post('/api/v0.9/reservation/', reservation_body)
reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)
if reservation_response.status_code != 201:
return
checkout_response = session.post('/api/v0.9/reservation/_checkout', data=checkout_body)
if checkout_response.status_code != 200:
return
purchase = checkout_response.json()['purchase']
completion_response = session.post('/api/v0.9/purchases/_complete', json.dumps(dict(
purchase_id=purchase['purchase_id'],
hash=purchase['completion_params']['hash'],
processor=purchase['completion_params']['processor'],
payment_ref=purchase['completion_params']['order_ref']
)))
示例6: post
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def post(self):
session = HttpSession(self.base_url)
reservation_response = session.post('/prod/insert-product', data=body)
示例7: test_cookie
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def test_cookie(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
r = s.post("/set_cookie?name=testcookie&value=1337")
self.assertEqual(200, r.status_code)
r = s.get("/get_cookie?name=testcookie")
self.assertEqual('1337', r.content.decode())
示例8: create_purchase
# 需要导入模块: from locust.clients import HttpSession [as 别名]
# 或者: from locust.clients.HttpSession import post [as 别名]
def create_purchase(self):
session = HttpSession(self.base_url)
reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)