def test_default_user_agent(self): con = AIOHttpConnection() self.assertEqual( con._get_default_user_agent(), "elasticsearch-py/%s (Python %s)" % (__versionstr__, python_version()), )
def test_keep_alive_is_on_by_default(self): con = AIOHttpConnection() assert { "connection": "keep-alive", "content-type": "application/json", "user-agent": con._get_default_user_agent(), } == con.headers
def test_http_auth_list(self): con = AIOHttpConnection(http_auth=["username", "secret"]) assert { "authorization": "Basic dXNlcm5hbWU6c2VjcmV0", "content-type": "application/json", "connection": "keep-alive", "user-agent": con._get_default_user_agent(), } == con.headers
def test_http_auth_tuple(self): con = AIOHttpConnection(http_auth=("username", "secret")) self.assertEqual( { "authorization": "Basic dXNlcm5hbWU6c2VjcmV0", "content-type": "application/json", "connection": "keep-alive", "user-agent": con._get_default_user_agent(), }, con.headers, )
async def test_aiohttp_connection(self): # Defaults conn = AIOHttpConnection("httpbin.org", port=443, use_ssl=True) user_agent = conn._get_default_user_agent() status, data = await self.httpbin_anything(conn) assert status == 200 assert data["method"] == "GET" assert data["headers"] == { "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": user_agent, } # http_compress=False conn = AIOHttpConnection("httpbin.org", port=443, use_ssl=True, http_compress=False) status, data = await self.httpbin_anything(conn) assert status == 200 assert data["method"] == "GET" assert data["headers"] == { "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": user_agent, } # http_compress=True conn = AIOHttpConnection("httpbin.org", port=443, use_ssl=True, http_compress=True) status, data = await self.httpbin_anything(conn) assert status == 200 assert data["headers"] == { "Accept-Encoding": "gzip,deflate", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": user_agent, } # Headers conn = AIOHttpConnection( "httpbin.org", port=443, use_ssl=True, http_compress=True, headers={"header1": "value1"}, ) status, data = await self.httpbin_anything(conn, headers={ "header2": "value2", "header1": "override!" }) assert status == 200 assert data["headers"] == { "Accept-Encoding": "gzip,deflate", "Content-Type": "application/json", "Host": "httpbin.org", "Header1": "override!", "Header2": "value2", "User-Agent": user_agent, }