def test_collect_invalid_timeout(self): with pytest.raises(ConfigurationError, match=r"^Configuration error .*"): parser = configparser.ConfigParser() parser.read_string('''[section] url=nourl timeout=xx''') NetworkMixin.collect_init_args(parser['section'])
def test_password_missing(self) -> None: with pytest.raises(ConfigurationError, match=r"^Username and.*"): parser = configparser.ConfigParser() parser.read_string( """ [section] url=ok username=xxx """ ) NetworkMixin.collect_init_args(parser["section"])
def test_collect_timeout(self): parser = configparser.ConfigParser() parser.read_string('''[section] url=nourl timeout=42''') args = NetworkMixin.collect_init_args(parser['section']) assert args['timeout'] == 42
def test_invalid_authentication(self, datadir, serve_protected) -> None: with pytest.raises(TemporaryCheckError): NetworkMixin( serve_protected(datadir / "data.txt")[0], 5, username="******", password="******", ).request()
def test_collect_default_timeout(self) -> None: parser = configparser.ConfigParser() parser.read_string( """ [section] url=nourl """ ) args = NetworkMixin.collect_init_args(parser["section"]) assert args["timeout"] == 5
def test_collect_missing_url(self) -> None: with pytest.raises(ConfigurationError, match=r"^Lacks 'url'.*"): parser = configparser.ConfigParser() parser.read_string("[section]") NetworkMixin.collect_init_args(parser["section"])
def test_file_url(self) -> None: NetworkMixin("file://" + __file__, 5).request()
def test_authentication(self, datadir, serve_protected) -> None: url, username, password = serve_protected(datadir / "data.txt") NetworkMixin(url, 5, username=username, password=password).request()
def test_exception_404(self, httpserver) -> None: with pytest.raises(TemporaryCheckError): NetworkMixin(httpserver.url_for("/does/not/exist"), timeout=5).request()
def test_smoke(self, datadir, serve_file) -> None: response = NetworkMixin(serve_file(datadir / "data.txt"), timeout=5).request() assert response is not None assert response.text == "iamhere\n"
def test_request(self, datadir, serve_file) -> None: reply = NetworkMixin( serve_file(datadir / "xml_with_encoding.xml"), 5, ).request() assert reply is not None assert reply.status_code == 200
def test_invalid_authentication(self, stub_auth_server): with pytest.raises(TemporaryCheckError): NetworkMixin(stub_auth_server.resource_address('data.txt'), 5, username='******', password='******').request()
def test_authentication(self, stub_auth_server): NetworkMixin(stub_auth_server.resource_address('data.txt'), 5, username='******', password='******').request()
def test_exception_404(self, stub_server): with pytest.raises(TemporaryCheckError): NetworkMixin(stub_server.resource_address('doesnotexist'), timeout=5).request()
def test_smoke(self, stub_server): response = NetworkMixin(stub_server.resource_address('data.txt'), timeout=5).request() assert response is not None assert response.text == 'iamhere\n'
def test_request(self, stub_server): address = stub_server.resource_address('xml_with_encoding.xml') reply = NetworkMixin(address, 5).request() assert reply is not None assert reply.status_code == 200
def test_requests_exception(self, mocker) -> None: with pytest.raises(TemporaryCheckError): mock_method = mocker.patch("requests.Session.get") mock_method.side_effect = requests.exceptions.ReadTimeout() NetworkMixin("url", timeout=5).request()
def test_file_url(self): NetworkMixin('file://' + __file__, 5).request()