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'
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'
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()
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()
def exists(self) -> bool: client: HttpClient = HttpClient() return client.head(self.__url) == 200
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