def test_A(self): result = '{"status" : "OK","session_id" : "mn7andp2tt049iaeaskr28j9ch"}' analyzer = ResultAnalyzer(result, 200) status_ok = analyzer.is_status_ok() self.assertEqual(status_ok, True) session_id = analyzer.get_value("session_id") self.assertEqual(session_id, "mn7andp2tt049iaeaskr28j9ch") print("ResultAnalyzerTest Passed!")
def get_blob_length(self, blob_id: str) -> int: """ Gets the blob length. """ try: if blob_id is None: raise TypeError("blob_id is null!") action = "get_blob_length" dict_params: dict = {"blob_id": blob_id} url_withaction = self._url + action AceQLDebug.debug("urlWithaction: " + url_withaction) AceQLDebug.debug("dictParams : " + str(dict_params)) # r = requests.post('http://httpbin.org/post', data = {'key':'value'}) if self.__timeout is None: response = requests.post(url_withaction, headers=self.__headers, data=dict_params, proxies=self.__proxies, auth=self.__auth) else: response = requests.post(url_withaction, headers=self.__headers, data=dict_params, proxies=self.__proxies, auth=self.__auth, timeout=self.__timeout) self.__http_status_code = response.status_code result = response.text AceQLDebug.debug("result: " + result) result_analyzer = ResultAnalyzer(result, self.__http_status_code) if not result_analyzer.is_status_ok(): raise Error(result_analyzer.get_error_message(), result_analyzer.get_error_type(), None, None, self.__http_status_code) length_str = result_analyzer.get_value("length") AceQLDebug.debug("result: " + length_str + ":") return int(length_str) except Exception as e: if isinstance(e, Error): raise else: raise Error(str(e), 0, e, None, self.__http_status_code)
def __init__(self, *, url: str, username: str, password: str, database: str, connection_options: ConnectionOptions = None): if url is None: raise TypeError("url is null!") if database is None: raise TypeError("database is null!") if username is None: raise TypeError("username is null!") session_id: str = None proxies: dict = None auth: ProxyAuth = None gzip_result: bool = True timeout = None request_headers: dict = {} if connection_options is not None: if connection_options.session_id is not None: session_id = connection_options.session_id password = None proxies = connection_options.proxies auth = connection_options.auth gzip_result = connection_options.gzip_result timeout = connection_options.timeout request_headers = connection_options.request_headers self.__url = url self.__database = database self.__username = username self.__password = password self.__proxies = proxies self.__auth = auth self.__gzip_result = gzip_result self.__timeout = timeout self.__headers = request_headers self.__http_status_code = requests.codes.ok # Other self for other methods self.__pretty_printing = True #self.__temp_length = 0 ==> Done in AceQLBlobUploadApi #self.__total_length = 0 ==> ==> Done in AceQLBlobUploadApi self.__progress_indicator = None # url = c + "/database/" + database + "/username/" \ # + username + "/connect" + "?password="******"/session/" + session_id + "/get_connection" result = self.call_with_get_url(the_url) result_analyzer = ResultAnalyzer(result, self.__http_status_code) if not result_analyzer.is_status_ok(): raise Error(result_analyzer.get_error_message(), result_analyzer.get_error_type(), None, None, self.__http_status_code) connection_id = result_analyzer.get_value("connection_id") self.__url = url + "/session/" + session_id + "/connection/" + connection_id + "/" else: url = url + "/database/" + database + "/username/" \ + username + "/login" dict_params = { "password": password, "client_version": str(VersionValues.VERSION) } result = self.call_with_post_url(url, dict_params) result_analyzer = ResultAnalyzer(result, self.__http_status_code) if not result_analyzer.is_status_ok(): raise Error(result_analyzer.get_error_message(), result_analyzer.get_error_type(), None, None, self.__http_status_code) session_id = result_analyzer.get_value("session_id") connection_id = result_analyzer.get_value("connection_id") self.__url = url + "/session/" + session_id + "/connection/" + connection_id + "/" user_login_store.set_session_id(session_id) except Exception as e: if isinstance(e, Error): raise else: raise Error(str(e), 0, e, None, self.__http_status_code)