def test_logout(self): """ 检查可以正确退出 """ mobile = config.get_login("Mobile") valid = config.get_login("Valid") api_in = config.get_url("Login") api_out = config.get_url("Logout") request_in = ConfigRequest() request_in.set_url(api_in) request_in.set_data({"mobile":mobile, "valid": valid}) response = request_in.post() authorization = response.get('token') request_out = ConfigRequest() request_out.set_url(api_out) request_out.set_headers({"Authorization": "Bearer " + authorization}) response = request_out.get() logger.info("Bearer " + authorization) logger.info(response) self.assertEqual(response.get("code"), 0)
def test_qr_code(self): """ 检查返回正确的qr二维码 """ # get login token api_login = config.get_url("Login") request_sign_in = ConfigRequest() data = { "mobile": config.get_login("Mobile"), "valid": config.get_login("Valid") } request_sign_in.set_data(data) request_sign_in.set_url(api_login) response_sign_in = request_sign_in.post() self.assertNotEqual(response_sign_in, None) self.assertNotEqual(response_sign_in.get("token"), None) # get qr code api_qr_code = config.get_url("QR_Code") token = response_sign_in.get("token") headers = {"Authorization": "Bearer {}".format(token)} request_qr_code = ConfigRequest() request_qr_code.set_headers(headers) request_qr_code.set_url(api_qr_code) response_qr_code = request_qr_code.get() self.assertGreater(len(response_qr_code.get("qr_code")), 2566) self.assertEqual(len(response_qr_code.get("invitation")), 6)
def test_points_management(self): """ 检查积分管理接口 """ # get login token api_login = config.get_url("Login") request_sign_in = ConfigRequest() data = { "mobile": config.get_login("Mobile"), "valid": config.get_login("Valid") } request_sign_in.set_data(data) request_sign_in.set_url(api_login) response_sign_in = request_sign_in.post() self.assertNotEqual(response_sign_in, None) self.assertNotEqual(response_sign_in.get("token"), None) d_type_enum = { 'register': 0, 'bindWeChat': 888, # 绑定we Chat 'invitation': 2000, # 邀请用户积分 'effective': 2000, # 有效用户积分 'shareNews': 80, # 分享积分 'shareFocus': 80, # 分享脱壳关注 'shareCoin': 80, # 分享币体检 'shareWeChat': 80, # 微信 qq二维码 链接分享 分享统一的注册地址 'shareToken': 80, # 币种分享 'shareMarket': 80, # 交易对分享 } api_points_management = config.get_url("points_management") token = response_sign_in.get("token") headers = {"Authorization": "Bearer {}".format(token)} for type_get_point in d_type_enum: self.reset_point_and_point_status_shared_count() request_share = ConfigRequest() request_share.set_url(api_points_management) request_share.set_headers(headers) request_share.set_data({"type": type_get_point}) response = request_share.post() self.assertEqual( response.get("data").get("point"), d_type_enum.get(type_get_point)) self.assertEqual( response.get("data").get("point_status_shared").get("count"), 1)
def test_my_points(self): """ 检查返回正确用户积分信息 """ # get login token api_login = config.get_url("Login") request_sign_in = ConfigRequest() data = { "mobile": config.get_login("Mobile"), "valid": config.get_login("Valid") } request_sign_in.set_data(data) request_sign_in.set_url(api_login) response_sign_in = request_sign_in.post() self.assertNotEqual(response_sign_in, None) self.assertNotEqual(response_sign_in.get("token"), None) # get examine result api_my_points = config.get_url("my_points") token = response_sign_in.get("token") headers = {"Authorization": "Bearer {}".format(token)} request = ConfigRequest() request.set_headers(headers) request.set_url(api_my_points) response = request.get() # get user infomation from mongodb bcf = BcfMongo() user_info = bcf.get_user_info(data.get("mobile")) self.assertEqual(response.get("mobile"), user_info.get("mobile")) self.assertEqual(response.get("invitation"), user_info.get("invitation")) self.assertEqual(response.get("point"), user_info.get("point")) self.assertEqual(type(response.get("invitationCoun")), int) self.assertEqual(type(response.get("effectiveCoun")), int) self.assertEqual(type(response.get("invitationScore")), int) self.assertEqual(type(response.get("effectctiveScore")), int) self.assertEqual( requests.get(response.get("regiserURL")).status_code, 200)
def test_examine(self): """ 检查返回正确examine结果 """ # get login token api_login = config.get_url("Login") request_sign_in = ConfigRequest() data = { "mobile": config.get_login("Mobile"), "valid": config.get_login("Valid") } request_sign_in.set_data(data) request_sign_in.set_url(api_login) response_sign_in = request_sign_in.post() self.assertNotEqual(response_sign_in, None) self.assertNotEqual(response_sign_in.get("token"), None) # get examine result api_examine = config.get_url("examine") token = response_sign_in.get("token") headers = {"Authorization": "Bearer {}".format(token)} params_examine = {"type": "examine"} params_share = {"type": "share"} request_examine = ConfigRequest() request_examine.set_headers(headers) request_examine.set_params(params_share) request_examine.set_url(api_examine) response_examine = request_examine.get() count = response_examine.get("examine_status").get("count") # Ur examine count will add 1 time if u share request_examine.get() request_examine.get() response_examine = request_examine.get() count += 3 self.assertEqual( response_examine.get("examine_status").get("count"), count) # ur examine count will reduce 1 time if u examine for c in range(1, count + 1): request_examine = ConfigRequest() request_examine.set_headers(headers) request_examine.set_params(params_examine) request_examine.set_url(api_examine) response_examine = request_examine.get() self.assertEqual( response_examine.get("examine_status").get("count"), count - c) self.assertEqual(response_examine.get("hasExamine"), True) request_examine = ConfigRequest() request_examine.set_headers(headers) request_examine.set_params(params_examine) request_examine.set_url(api_examine) response_examine = request_examine.get() self.assertEqual( response_examine.get("examine_status").get("count"), 0) self.assertEqual(response_examine.get("hasExamine"), False)