def test_get_server_version(self, options: Options, requests_mock): url = urljoin(options.url, Endpoint.ABOUT.s) options.autoload = True requests_mock.register_uri( "GET", f"{url}?format=text", content=bytes("foo bar baz\nversion: 42.1337.00", encoding="utf-8"), ) version = _get_server_version(options) assert requests_mock.called_once assert version == "42.1337.00"
def test_get_server_version_no_autoload(self, options: Options, requests_mock, caplog): url = urljoin(options.url, Endpoint.ABOUT.s) options.autoload = False requests_mock.register_uri("GET", f"{url}?format=text", text="foobarbaz") with caplog.at_level(logging.DEBUG): version = _get_server_version(options) assert not requests_mock.called_once assert ("Unable to get server version. Reason: `Autoload is disabled.`" in caplog.text) assert version == UNKNOWN_SERVER_VERSION
def test_get_server_version_not_decodable(self, options: Options, requests_mock, caplog): url = urljoin(options.url, Endpoint.ABOUT.s) options.autoload = True requests_mock.register_uri("GET", f"{url}?format=text", content=bytes("foobarbaz", encoding="utf-8")) with caplog.at_level(logging.DEBUG): version = _get_server_version(options) assert requests_mock.called_once assert ( "Unable to get server version. Reason: `list index out of range`" in caplog.text) assert version == UNKNOWN_SERVER_VERSION