def edit_api_key(canTrade, canWithdraw, email): config = get_config() url = "https://" + config.get("host") + "/v1/user/api-keys/update" token = login(email) headers = get_headers(token) secretKey = check_bind_ga(email) if secretKey is None: ga = "" print("GA为空,请先绑定GA~~") else: print(secretKey) ga = get_totp_token(secretKey) userid = get_user_id_by_email(email) apikey = get_api_key_by_userid(userid) print(apikey) description = "test_add_api_key_edited_" + time.strftime( "%Y-%m-%d_%H_%M_%S") payload = { "description": description, "ga": ga, "apiKey": apikey, "canRead": True, "canTrade": canTrade, "canWithdraw": canWithdraw, "ipRestriction": "*" } response = requests.request("POST", url, data=json.dumps(payload), headers=headers) if "success" != response.json()["status"]: print("edit api key fail, response= " + response.text) else: print("edit api key success, response= " + response.text) return response
def test_sign_in_success(self): """ email 正确, password 正确, 登录成功""" email = "*****@*****.**" password = hmac_password(email, b"Password01") secretKey = check_bind_ga(email) if secretKey is None: ga = "" else: ga = ga_auth.get_totp_token(secretKey) payload = {"email": email, "password": password, "ga": ga} response = requests.request("POST", self.url, headers=self.headers, data=json.dumps(payload)) # response = login(email) self.assertEqual("success", response.json()['status']) self.assertIsNotNone(response.json()['data'])
def test_login_email_correct_and_pw_incorrect(self): """ email正确, password不正确, 登录不成功""" email = "*****@*****.**" password = hmac_password(email, b"Password01") secretKey = check_bind_ga(email) if secretKey is None: ga = "" else: ga = ga_auth.get_totp_token(secretKey) payload = {"email": email, "password": password + "error", "ga": ga} response = requests.request("POST", self.url, data=json.dumps(payload), headers=self.headers) self.assertEqual(200, response.status_code) self.assertEqual("fail", response.json()['status']) self.assertEqual("PARAMETER_INVALID", response.json()['code'])