def test5_not_enough_deposits(self): """ Navigate to a web page """ response = http_requests.get(url_http(), allow_redirects=True) expect_ok(response) assert "Welcome to FOP" in response.text username['username1'] = self.username[0] response = http_requests.post(url_http() + "username", headers=None, data=username) assert response.json()["is_successful"], response.json() """ First answer if enterprise or platinum""" response = http_requests.post(url_http(), data=PlatinumClientChoice) assert response.status_code == 200 """ Next answer yes to the checking account question""" response = http_requests.post(url_http(), data=CheckingAcctYES) assert response.status_code == 200 """ Next question is if the customer has $200, 000 or more in deposits, for this test answer NO """ response = http_requests.post(url_http(), data=DepositsNO) assert response.json()["Free Overdraft Protection Denied."], response.json()
def create_reserve_account(cls, name: str, currency: global_common.Currency, profile_id: int) -> None: from wise.models import AccountType parameters: Dict[str, Any] = { "currency": currency.value, "type": AccountType.ReserveAccount.value, "name": name } headers = constants.HEADERS.copy() headers["X-idempotence-uuid"] = str(uuid.uuid4()) http_requests.post(cls.endpoint_create_account.replace("{profile_id}", str(profile_id)), parameters=parameters, headers=headers)
def get_cloud_messages(self, args): #ret = cache.get('get_cloud_messages') #if ret: return public.returnMsg(True,'同步成功1!') data = {} data['version'] = public.version() data['os'] = self.os sUrl = public.GetConfigValue('home') + '/api/wpanel/get_messages' import http_requests http_requests.DEFAULT_TYPE = 'src' info = http_requests.post(sUrl, data).json() # info = json.loads(public.httpPost(sUrl,data)) for x in info: count = public.M('messages').where('level=? and msg=?', ( x['level'], x['msg'], )).count() if count: continue pdata = { "level": x['level'], "msg": x['msg'], "state": 1, "expire": int(time.time()) + (int(x['expire']) * 86400), "addtime": int(time.time()) } public.M('messages').insert(pdata) #cache.set('get_cloud_messages',3600) return public.returnMsg(True, '同步成功!')
def HttpPost(url, data, timeout=6, headers={}): """ 发送POST请求 @url 被请求的URL地址(必需) @data POST参数,可以是字符串或字典(必需) @timeout 超时时间默认60秒 return string """ if is_local(): return False home = 'www.bt.cn' host_home = 'data/home_host.pl' old_url = url if url.find(home) != -1: if os.path.exists(host_home): headers['host'] = home url = url.replace(home, readFile(host_home)) import http_requests res = http_requests.post(url, data=data, timeout=timeout, headers=headers) if res.status_code == 0: WriteLog('请求错误', res.text) if old_url.find(home) != -1: return http_post_home(old_url, data, timeout, res.text) if headers: return False return res.text return res.text
def call(cls, profile_id: int, source_currency: str, target_currency: str, target_amount: float) -> "Quote": parameters: Dict[str, Any] = { "profile": profile_id, "sourceCurrency": source_currency, "targetCurrency": target_currency, "targetAmount": target_amount, "payOut": "BALANCE" } response: Response = http_requests.post(cls.endpoint.replace("{profile_id}", str(profile_id)), parameters=parameters, headers=constants.HEADERS) return common.get_model_from_response(response, cls) # type: ignore
def call(cls, target_account_id: int, quote_uuid: str, reference: str) -> "Transfer": parameters: Dict[str, Any] = { "targetAccount": target_account_id, "quoteUuid": quote_uuid, "customerTransactionId": str(uuid.uuid4()), "details": {"reference": reference} } response: Response = http_requests.post(cls.endpoint, parameters=parameters, headers=constants.HEADERS) return common.get_model_from_response(response, cls) # type: ignore
def test4_no_checking(self): """ Navigate to a web page """ response = http_requests.get(url_http(), allow_redirects=True) expect_ok(response) assert "Welcome to FOP" in response.text username['username1'] = self.username[0] response = http_requests.post(url_http() + "username", headers=None, data=username) assert response.json()["is_successful"], response.json() """ First answer if enterprise or platinum""" response = http_requests.post(url_http(), data=EntClientChoice) assert response.status_code == 200 """ Next answer NO to the checking account question for this test""" response = http_requests.post(url_http(), data=CheckingAcctNO) assert response.json()["Free Overdraft Protection Denied."], response.json()
def test4_name_with_ext_char(self): """ Navigate to a web page """ response = http_requests.get(url_http(), allow_redirects=True) expect_ok(response) assert "Welcome to FOP" in response.text username['username4'] = self.username[3] response = http_requests.post(url_http() + "username", headers=None, data=username) assert response.json()["is_successful"], response.json()
def test10_name_with_alphanumeric(self): """ Navigate to a web page """ response = http_requests.get(url_http(), allow_redirects=True) expect_ok(response) assert "Welcome to FOP" in response.text username['username10'] = self.username[9] response = http_requests.post(url_http() + "username", headers=None, data=username) assert_equal(response.json()['error']['user_help'], 'Invalid username')
def test8_name_with_max_stringlength128_plus_one(self): """ Navigate to a web page """ response = http_requests.get(url_http(), allow_redirects=True) expect_ok(response) assert "Welcome to FOP" in response.text username['username8'] = self.username[7] response = http_requests.post(url_http() + "username", headers=None, data=username) assert_equal(response.json()['error']['user_help'], 'Invalid username')
def send_message(username: str, message_text: str, is_html: bool = False) -> None: if username[0:1] != "@": username = "******" + username parameters = {"chat_id": username, "text": message_text} if is_html: parameters.update({"parse_mode": "HTML"}) global url response = http_requests.post(url, parameters) if response.status_code >= 300: logger.error("Telegram message sending failed: " + response.json()["description"])
def call(cls, profile_id: int, source_balance_id: int, target_balance_id: int, amount: float, quote_id: str, currency: str) -> "IntraAccountTransfer": parameters: Dict[str, Any] = { "profileId": profile_id, "sourceBalanceId": source_balance_id, "targetBalanceId": target_balance_id, } if quote_id is None: parameters["amount"] = {"value": amount, "currency": currency} else: parameters["quoteId"] = quote_id headers = constants.HEADERS.copy() headers["X-idempotence-uuid"] = str(uuid.uuid4()) response: Response = http_requests.post(cls.endpoint.replace("{profile_id}", str(profile_id)), parameters=parameters, headers=headers) return common.get_model_from_response(response, cls) # type: ignore
def __makecall(self, args, un, key, origin, kwargs): platform = 'Python' args = json.dumps(args, cls=self.__plotlyJSONEncoder) kwargs = json.dumps(kwargs, cls=self.__plotlyJSONEncoder) url = 'https://plot.ly/clientresp' payload = {'platform': platform, 'version': __version__, 'args': args, 'un': un, 'key': key, 'origin': origin, 'kwargs': kwargs} r = http_requests.post(url, data=payload) r.raise_for_status() r = json.loads(r.text) if 'error' in r and r['error'] != '': print(r['error']) if 'warning' in r and r['warning'] != '': warnings.warn(r['warning']) if 'message' in r and r['message'] != '' and self.verbose: print(r['message']) return r
def make_signed_acme_request(self, url, payload): headers = {"User-Agent": self.User_Agent} payload = self.stringfy_items(payload) if payload in ["GET_Z_CHALLENGE", "DOWNLOAD_Z_CERTIFICATE"]: response = requests.get(url, timeout=self.ACME_REQUEST_TIMEOUT, headers=headers,verify=False) else: payload64 = self.calculate_safe_base64(json.dumps(payload)) protected = self.get_acme_header(url) protected64 = self.calculate_safe_base64(json.dumps(protected)) signature = self.sign_message(message="{0}.{1}".format(protected64, payload64)) # bytes signature64 = self.calculate_safe_base64(signature) # str data = json.dumps( {"protected": protected64, "payload": payload64, "signature": signature64} ) headers.update({"Content-Type": "application/jose+json"}) response = requests.post( url, data=data.encode("utf8"), timeout=self.ACME_REQUEST_TIMEOUT, headers=headers ,verify=False ) return response
def signup(un, email): ''' Remote signup to plot.ly and plot.ly API Returns: :param r with r['tmp_pw']: Temporary password to access your plot.ly acount :param r['api_key']: A key to use the API with Full docs and examples at https://plot.ly/API :un: <string> username :email: <string> email address ''' payload = {'version': __version__, 'un': un, 'email': email, 'platform':'Python'} r = http_requests.post('https://plot.ly/apimkacct', data=payload) r.raise_for_status() r = json.loads(r.text) if 'error' in r and r['error'] != '': print(r['error']) if 'warning' in r and r['warning'] != '': warnings.warn(r['warning']) if 'message' in r and r['message'] != '': print(r['message']) return r
def test2_end_to_end_successful_platinum_client(self): """ Navigate to a web page """ response = http_requests.get(url_http(), allow_redirects=True) expect_ok(response) assert "Welcome to FOP" in response.text username['username1'] = self.username[0] response = http_requests.post(url_http() + "username", headers=None, data=username) assert response.json()["is_successful"], response.json() """ First answer if enterprise or platinum""" response = http_requests.post(url_http(), data=PlatinumClientChoice) assert response.status_code == 200 """ Next answer yes to the checking account question""" response = http_requests.post(url_http(), data=CheckingAcctYES) assert response.status_code == 200 """ Next question is if the customer has $200, 000 or more in deposits """ response = http_requests.post(url_http(), data=DepositsYES) assert response.status_code == 200 """ Next question is - does the customer already have overdraft protection? """ """ For this test answer NO""" response = http_requests.post(url_http(), data=OverdraftProtectionNO) assert response.status_code == 200 """ and final question is - does the customer have fewer than five overdrafts in the last 12 months? """ response = http_requests.post(url_http(), data=OverdraftFewerYES) assert response.status_code == 200 """ Post a submit and verify success message""" response = http_requests.post(url_http(), data=submit) assert response.json()["You have been approved for Free Overdraft Protection."], response.json()
def call(cls, profile_id: int, transfer_id: int) -> "Fund": response: Response = http_requests.post(cls.endpoint.replace("{profile_id}", str(profile_id)).replace("{transfer_id}", str(transfer_id)), parameters={"type": "BALANCE"}, headers=constants.HEADERS) return common.get_model_from_response(response, cls) # type: ignore