From 7ac5fbea1450705b2ac1c2e520188fd89b3e3ac7 Mon Sep 17 00:00:00 2001 From: Kevin Lloyd Bernal Date: Fri, 26 Aug 2022 17:47:09 +0800 Subject: [PATCH] Rename the http_client variable to http (#85) --- docs/intro/advanced-tutorial.rst | 8 ++++---- tests/test_downloader.py | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/intro/advanced-tutorial.rst b/docs/intro/advanced-tutorial.rst index 5fda40ed..b893d7ea 100644 --- a/docs/intro/advanced-tutorial.rst +++ b/docs/intro/advanced-tutorial.rst @@ -49,7 +49,7 @@ Suppose we have the following Page Object: @attr.define class ProductPage(web_poet.ItemWebPage): - http_client: web_poet.HttpClient + http: web_poet.HttpClient async def to_item(self): item = { @@ -59,7 +59,7 @@ Suppose we have the following Page Object: } # Simulates clicking on a button that says "View All Images" - response: web_poet.HttpResponse = await self.http_client.get( + response: web_poet.HttpResponse = await self.http.get( f"https://api.example.com/v2/images?id={item['product_id']}" ) item["images"] = response.css(".product-images img::attr(src)").getall() @@ -111,7 +111,7 @@ This basically acts as a switch to update the behavior of the Page Object: @attr.define class ProductPage(web_poet.ItemWebPage): - http_client: web_poet.HttpClient + http: web_poet.HttpClient page_params: web_poet.PageParams async def to_item(self): @@ -123,7 +123,7 @@ This basically acts as a switch to update the behavior of the Page Object: # Simulates clicking on a button that says "View All Images" if self.page_params.get("enable_extracting_all_images") - response: web_poet.HttpResponse = await self.http_client.get( + response: web_poet.HttpResponse = await self.http.get( f"https://api.example.com/v2/images?id={item['product_id']}" ) item["images"] = response.css(".product-images img::attr(src)").getall() diff --git a/tests/test_downloader.py b/tests/test_downloader.py index 0386ed43..d0c76e08 100644 --- a/tests/test_downloader.py +++ b/tests/test_downloader.py @@ -134,10 +134,10 @@ def test_additional_requests_success(): @attr.define class ItemPage(ItemWebPage): - http_client: HttpClient + http: HttpClient async def to_item(self): - response = await self.http_client.request( + response = await self.http.request( server.root_url, body=b"bar", ) @@ -171,11 +171,11 @@ def test_additional_requests_bad_response(): @attr.define class ItemPage(ItemWebPage): - http_client: HttpClient + http: HttpClient async def to_item(self): try: - await self.http_client.request( + await self.http.request( server.root_url, body=b"400", ) @@ -218,11 +218,11 @@ def test_additional_requests_connection_issue(): @attr.define class ItemPage(ItemWebPage): - http_client: HttpClient + http: HttpClient async def to_item(self): try: - await self.http_client.request( + await self.http.request( server.root_url, body=b"0.002", ) @@ -257,11 +257,11 @@ def test_additional_requests_ignored_request(): @attr.define class ItemPage(ItemWebPage): - http_client: HttpClient + http: HttpClient async def to_item(self): try: - await self.http_client.request( + await self.http.request( server.root_url, body=b"ignore", ) @@ -314,11 +314,11 @@ def test_additional_requests_unhandled_downloader_middleware_exception(): @attr.define class ItemPage(ItemWebPage): - http_client: HttpClient + http: HttpClient async def to_item(self): try: - await self.http_client.request( + await self.http.request( server.root_url, body=b"raise", ) @@ -368,14 +368,14 @@ def test_additional_requests_dont_filter(): @attr.define class ItemPage(ItemWebPage): - http_client: HttpClient + http: HttpClient async def to_item(self): - response1 = await self.http_client.request( + response1 = await self.http.request( server.root_url, body=b"a", ) - response2 = await self.http_client.request( + response2 = await self.http.request( server.root_url, body=b"a", )