当前位置: 首页>>代码示例>>Python>>正文


Python clients.HttpSession类代码示例

本文整理汇总了Python中locust.clients.HttpSession的典型用法代码示例。如果您正苦于以下问题:Python HttpSession类的具体用法?Python HttpSession怎么用?Python HttpSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HttpSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_purchase

    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"],
                )
            ),
        )
开发者ID:hooplab,项目名称:docker-locust,代码行数:28,代码来源:ticket_release.py

示例2: test_slow_redirect

 def test_slow_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect?url=/redirect?delay=0.5"
     r = s.get(url)
     stats = global_stats.get(url, method="GET")
     self.assertEqual(1, stats.num_requests)
     self.assertGreater(stats.avg_response_time, 500)
开发者ID:Broadroad,项目名称:locust,代码行数:7,代码来源:test_client.py

示例3: test_slow_redirect

 def test_slow_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect?url=/redirect?delay=0.5"
     r = s.get(url)
     stats = global_stats.get(url, method="GET")
     assert 1 == stats.num_requests
     assert stats.avg_response_time > 500
开发者ID:sanga,项目名称:locust,代码行数:7,代码来源:test_client.py

示例4: create_purchase

    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)
开发者ID:hooplab,项目名称:docker-locust,代码行数:9,代码来源:initialize_only.py

示例5: test_post_redirect

 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
开发者ID:sanga,项目名称:locust,代码行数:9,代码来源:test_client.py

示例6: test_options

 def test_options(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.options("/request_method")
     self.assertEqual(200, r.status_code)
     self.assertEqual("", r.content.decode())
     self.assertEqual(
         set(["OPTIONS", "DELETE", "PUT", "GET", "POST", "HEAD"]),
         set(r.headers["allow"].split(", ")),
     )
开发者ID:alexandrul,项目名称:locust,代码行数:9,代码来源:test_client.py

示例7: test_post_redirect

 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)
开发者ID:Broadroad,项目名称:locust,代码行数:9,代码来源:test_client.py

示例8: test_streaming_response

 def test_streaming_response(self):
     """
     Test a request to an endpoint that returns a streaming response
     """
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.get("/streaming/30")
     
     # verify that the time reported includes the download time of the whole streamed response
     self.assertGreater(global_stats.get("/streaming/30", method="GET").avg_response_time, 250)
     global_stats.clear_all()
     
     # verify that response time does NOT include whole download time, when using stream=True
     r = s.get("/streaming/30", stream=True)
     self.assertGreater(global_stats.get("/streaming/30", method="GET").avg_response_time, 0)
     self.assertLess(global_stats.get("/streaming/30", method="GET").avg_response_time, 250)
     
     # download the content of the streaming response (so we don't get an ugly exception in the log)
     _ = r.content
开发者ID:Broadroad,项目名称:locust,代码行数:18,代码来源:test_client.py

示例9: create_purchase

    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']
        )))
开发者ID:hooplab,项目名称:docker-locust,代码行数:20,代码来源:complete_purchase.py

示例10: test_connection_error

 def test_connection_error(self):
     s = HttpSession("http://localhost:1")
     r = s.get("/", timeout=0.1)
     self.assertEqual(r.status_code, 0)
     self.assertEqual(None, r.content)
     self.assertRaises(RequestException, r.raise_for_status)
开发者ID:Broadroad,项目名称:locust,代码行数:6,代码来源:test_client.py

示例11: test_connection_error

 def test_connection_error(self):
     s = HttpSession("http://localhost:1")
     r = s.get("/", timeout=0.1)
     assert r.status_code == 0
     assert None == r.content
     raises(RequestException, r.raise_for_status)
开发者ID:sanga,项目名称:locust,代码行数:6,代码来源:test_client.py

示例12: create_purchase

 def create_purchase(self):
     session = HttpSession(self.base_url)
     reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)
开发者ID:hooplab,项目名称:docker-locust,代码行数:3,代码来源:reserve_only.py

示例13: post

 def post(self):
   session = HttpSession(self.base_url)
   reservation_response = session.post('/prod/insert-product', data=body)
开发者ID:hooplab,项目名称:docker-locust,代码行数:3,代码来源:insert_product.py

示例14: test_delete

 def test_delete(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.delete("/request_method")
     self.assertEqual(200, r.status_code)
     self.assertEqual("DELETE", r.content.decode())
开发者ID:alexandrul,项目名称:locust,代码行数:5,代码来源:test_client.py

示例15: test_cookie

 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())
开发者ID:alexandrul,项目名称:locust,代码行数:6,代码来源:test_client.py


注:本文中的locust.clients.HttpSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。