Exemplo n.º 1
0
 def test_inp_file_success(self, mock_get):
     mock_get.side_effect = self.mock_http_get
     http_client: HttpClient = HttpClient('http://test.com/a/')
     status_code = http_client.get('b/c/file.idx')
     assert status_code == 200
     content = next(http_client.inp())
     assert content == '123'
Exemplo n.º 2
0
 def test_inp_url_success(self, mock_get):
     mock_get.side_effect = self.mock_http_get
     http_client: HttpClient = HttpClient()
     status_code = http_client.get('http://test.com/a/b/c')
     assert status_code == 200
     content = next(http_client.inp())
     assert content == 'abc'
Exemplo n.º 3
0
def cli(ctx, url):
    parsed: ParseResult = urlparse(url)
    client: HttpClient = HttpClient(parsed._replace(path="/").geturl())  
    
    code: int = client.get(parsed.path)
    if code != 200:
        ctx.log(f"The response code is {code}")
    else:
        for i in client.inp():
            ctx.log(i)

    client.close()
Exemplo n.º 4
0
 def inp(self, bufsize: int = 2048) -> Iterator[str]:
     client: HttpClient = HttpClient()
     status_code: int = client.get(self.__url)
     yield from client.inp(bufsize=bufsize) if status_code == 200 else ()
     client.close()
Exemplo n.º 5
0
 def exists(self) -> bool:
     client: HttpClient = HttpClient()
     return client.head(self.__url) == 200
Exemplo n.º 6
0
 def test_inp_file_failure(self, mock_get):
     mock_get.side_effect = self.mock_http_get
     http_client: HttpClient = HttpClient('http://test.com/x/')
     status_code = http_client.get('b/c/file.idx')
     assert status_code == 404