def test_bind_phone_image_code_is_error(self): """ 测试请求接口图形验证码错误 :return: """ send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) image_code = Redis().get_image_captcha(settings.DEVICE_ID) num = random.randint(1111, 9999) phone = '1580101' + str(num) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': phone, 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 0) sms_code = MysqlOperation(mobile=phone).get_sms_code() bind_phone_api = BindPhoneApi(self.user_name) bind_phone_api.get({ 'phone': phone, 'code': sms_code, 'check_code': 1234 }) self.assertEqual(bind_phone_api.get_code(), 422107) self.assertEqual(bind_phone_api.get_response_message(), u'验证码错误,请重新输入')
def test_bind_phone_sms_code_error(self): """ 测试请求接口短信验证码错误 :return: """ send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) image_code = Redis().get_image_captcha(settings.DEVICE_ID) num = random.randint(1111, 9999) phone = '1580202' + str(num) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': phone, 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 0) bind_phone_api = BindPhoneApi(self.user_name) bind_phone_api.get({ 'phone': phone, 'code': '123u', 'check_code': image_code }) self.assertEqual(bind_phone_api.get_code(), 400104) self.assertEqual(bind_phone_api.get_response_message(), u'验证码错误,请重新获取短信验证码')
def test_register_sms_code_upper(self): """ 注册时验证码填写大写 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 0) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() upper_sms_code = (str(sms_code)).upper() register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': upper_sms_code, 'password': self.password, 'device_id': self.device_id, 'nickname': self.nickname }) self.assertEqual(register_api.get_code(), 0)
def test_e_register_sms_code_error(self): """ 测试请求注册接口手机验证码填写错误 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) SendSmsCodeApi().get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': '6666', 'password': self.password, 'device_id': self.device_id, 'nickname': self.nickname }) self.assertEqual(register_api.get_code(), 400104) self.assertEqual(register_api.get_response_message(), u'验证码错误,请重新获取短信验证码')
def test_c_register_password_null(self): """ 测试请求注册接口密码为空 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) SendSmsCodeApi().get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': sms_code, 'password': None, 'nickname': self.nickname }) self.assertEqual(register_api.get_code(), 422102) self.assertEqual(register_api.get_response_message(), u'密码不能为空')
def test_k_register_nickname_too_short(self): """ 测试请求注册接口昵称长度不足4位 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) SendSmsCodeApi().get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': sms_code, 'password': self.password, 'device_id': self.device_id, 'nickname': u'三个字' }) self.assertEqual(register_api.get_code(), 400131) self.assertEqual(register_api.get_response_message(), u'昵称长度必须为4-8位')
def test_i_register_nickname_sensitivity(self): """ 测试请求注册接口昵称中包含敏感词 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) SendSmsCodeApi().get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': sms_code, 'password': self.password, 'device_id': self.device_id, 'nickname': '习近平胡锦涛' }) self.assertEqual(register_api.get_code(), 422105) self.assertEqual(register_api.get_response_message(), u'昵称包含敏感词,请替换')
def test_g_register_nickname_exits(self): """ 测试请求注册接口填写已存在昵称 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) SendSmsCodeApi().get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': sms_code, 'password': self.password, 'nickname': '123456' }) self.assertEqual(register_api.get_code(), 422106) self.assertEqual(register_api.get_response_message(), u'昵称已存在请替换')
def test_h_register_nickname_wrongful(self): """ 测试请求注册接口填写不合法昵称 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) SendSmsCodeApi().get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() register_api = RegisterApi() register_api.get({ 'login_name': self.mobile, 'code': sms_code, 'password': self.password, 'device_id': self.device_id, 'nickname': 'wx_abcd' }) self.assertEqual(register_api.get_code(), 801061) self.assertEqual(register_api.get_response_message(), u'用户昵称不合法,快去换一个吧')
def test_a_send_register_sms_code_success(self): """ 测试发送注册短信验证码 """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 0) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() self.assertIsNotNone(sms_code) self.assertEqual(len(sms_code), 4)
def test_a_send_bind_sms_code_success(self): """ 测试发送绑定手机号短信验证码 """ send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) image_code = Redis().get_image_captcha(settings.DEVICE_ID) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': self.mobile2, 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 0) sms_code = MysqlGet(mobile=self.mobile2).get_sms_code() self.assertIsNotNone(sms_code) self.assertEqual(len(sms_code), 4)
def test_bind_phone_success(self): """ 测试绑定手机号成功 :return: """ send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) image_code = Redis().get_image_captcha(settings.DEVICE_ID) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': self.bind_mobile, 'check_code': image_code}) self.assertEqual(send_sms_code_api.get_code(),0) sms_code = MysqlOperation(mobile=self.bind_mobile).get_sms_code() bind_phone_api = BindPhoneApi(self.user_name) response = bind_phone_api.get({'phone': self.bind_mobile, 'code': sms_code,'check_code':image_code}) self.assertEqual(bind_phone_api.get_code(),0) identity_obj = json.loads(response.content)['result']['identity_obj'] self.assertEqual(self.bind_mobile,identity_obj['mobilephone']) self.assertEqual(self.bind_mobile,identity_obj['login_name'])
def test_d_send_register_sms_code_phone_null(self): """ 测试发送短信验证码手机号码为空 """ send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': None, 'check_code': '6666' }) self.assertEqual(send_sms_code_api.get_code(), 400101) self.assertEqual(send_sms_code_api.get_response_message(), u'手机号不能为空')
def test_c_send_register_sms_code_type_null(self): """ 测试发送短信验证码未定义类型 :return: """ send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': None, 'phone': self.mobile, 'check_code': '6666' }) self.assertEqual(send_sms_code_api.get_code(), 400111) self.assertEqual(send_sms_code_api.get_response_message(), u'短信类型不能为空')
def test_f_send_register_sms_code_check_code_error(self): """ 测试发送给短信验证码图形验证码输入错误 """ send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': '6666' }) self.assertEqual(send_sms_code_api.get_code(), 422107) self.assertEqual(send_sms_code_api.get_response_message(), u'验证码错误,请重新输入')
def test_e_send_register_sms_code_check_code_null(self): """ 测试发送短信验证码图形验证码为空 """ send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': None }) self.assertEqual(send_sms_code_api.get_code(), 422126) self.assertEqual(send_sms_code_api.get_response_message(), u'图形验证码不能为空')
def test_g_send_register_sms_code_check_code_not_send(self): """ 测试发送短信验证码未发送图形验证码 """ Redis().delete_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': '6666' }) self.assertEqual(send_sms_code_api.get_code(), 422107) self.assertEqual(send_sms_code_api.get_response_message(), u'验证码错误,请重新输入')
def test_i_send_register_sms_code_mobile_too_short(self): """ 测试发送短信验证码手机号不足11位 """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': '1309876', 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 400126) self.assertEqual(send_sms_code_api.get_response_message(), u'手机号格式不合法')
def test_j_send_register_sms_code_mobile_english(self): """ 测试发送短信验证码手机号码中带英文 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': 'abcdefg', 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 400126) self.assertEqual(send_sms_code_api.get_response_message(), u'手机号格式不合法')
def test_k_send_register_sms_code_mobile_exits(self): """ 测试用已经注册的手机号码获取注册类型短信验证码 :return: """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': self.device_id, 'type': 'register', 'phone': '15899999999', 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 400113) self.assertEqual(send_sms_code_api.get_response_message(), u'该手机号已经被注册')
def test_bind_phone_success(self): """ 测试完成绑定手机号任务 :return: """ task_list_api = TaskListApi(self.user_name) response = task_list_api.get() self.assertEqual(task_list_api.get_code(), 0) task_list = json.loads(response.content)['result']['task_list'] for x in task_list: if x['task_name'] == u'绑定手机': self.assertIsNone(x['user_task_obj']) task_notice_api = TaskNoticeApi(self.user_name) response = task_notice_api.get() self.assertEqual(task_notice_api.get_code(), 0) send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) image_code = Redis().get_image_captcha(settings.DEVICE_ID) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': self.bind_mobile, 'check_code': image_code }) self.assertEqual(send_sms_code_api.get_code(), 0) sms_code = MysqlOperation(mobile=self.bind_mobile).get_sms_code() bind_phone_api = BindPhoneApi(self.user_name) response = bind_phone_api.get({ 'phone': self.bind_mobile, 'code': sms_code, 'check_code': image_code }) self.assertEqual(bind_phone_api.get_code(), 0) identity_obj = json.loads(response.content)['result']['identity_obj'] self.assertEqual(self.bind_mobile, identity_obj['mobilephone']) self.assertEqual(self.bind_mobile, identity_obj['login_name']) while self.count < self.max_count: task_list_api = TaskListApi(self.bind_mobile) response = task_list_api.get() self.assertEqual(task_list_api.get_code(), 0) task_list = json.loads(response.content)['result']['task_list'] if task_list[0]['user_task_obj'] is not None: self.assertEqual(task_list[0]['user_task_obj']['user_id'], (self.user_id)) self.assertEqual( task_list[0]['user_task_obj']['task_behavior'], u'bind_mobile') self.assertEqual(task_list[0]['user_task_obj']['num'], 1) self.assertEqual(task_list[0]['user_task_obj']['status'], 2) break else: self.count += 1 time.sleep(self.time_sleep) self.assertLess(self.count, self.max_count) task_notice_api = TaskNoticeApi(self.bind_mobile) task_notice_api.get() self.assertEqual(task_notice_api.get_code(), 0) get_task_reward_api = GetTaskRewardApi(self.bind_mobile) response = get_task_reward_api.get({'behavior': 'bind_mobile'}) self.assertEqual(get_task_reward_api.get_code(), 0) self.assertEqual( json.loads(response.content)['result']['task_rewards']['diamond'], 5000) task_list = json.loads(response.content)['result']['task_list'] self.assertEqual(task_list[0]['user_task_obj']['status'], 3) identity_obj = json.loads(response.content)['result']['identity_obj'] self.assertEqual(identity_obj['diamond'], u'5000')
def test_register_success(self): """ 测试正常请求注册接口 """ ImageCodeApi().get({'device_id': self.device_id}) image_code = Redis().get_image_captcha(self.device_id) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({'device_id': self.device_id, 'type': 'register', 'phone': self.mobile, 'check_code': image_code}) self.assertEqual(send_sms_code_api.get_code(),0) sms_code = MysqlGet(mobile=self.mobile).get_sms_code() register_api = RegisterApi() response = register_api.get({'login_name': self.mobile, 'code': sms_code, 'password': self.password, 'device_id': self.device_id, 'nickname': self.nickname}) self.assertEqual(register_api.get_code(), 0) identity_obj = json.loads(response.content)['result']['identity_obj'] self.assertEqual(identity_obj['nickname'], self.nickname) for x in [identity_obj['login_name'], identity_obj['mobilephone']]: self.assertEqual(x, self.mobile) for x in [identity_obj['gold'], identity_obj['diamond'], identity_obj['ticket']]: self.assertEqual(x, 0) self.assertEqual(identity_obj['user_rank'], 1) self.assertEqual(identity_obj['user_experience'], 0) self.assertEqual(identity_obj['current_rank_user_need_total_experience'], 50000) for x in [identity_obj['anchor_rank'], identity_obj['anchor_experience']]: self.assertEqual(x, 0) self.assertEqual(identity_obj['current_rank_anchor_need_total_experience'], 1) self.assertEqual(identity_obj['sun_num'], 5) self.assertEqual(identity_obj['follow_num'], 0) for x in [identity_obj['introduction'], identity_obj['email'], identity_obj['small_head_url']]: self.assertEqual(x, u'') user_guard_obj = identity_obj['user_guard_obj'] self.assertEqual(user_guard_obj['user_id'], u'') self.assertEqual(user_guard_obj['expire_time'], u'') self.assertEqual(user_guard_obj['guard_rank'], 0) intimacy_obj = identity_obj['intimacy_obj'] for x in [intimacy_obj['intimacy_experience'], intimacy_obj['intimacy_rank'], intimacy_obj['intimacy_next_experience']]: self.assertEqual(x, 0) self.assertIsNone(intimacy_obj['intimacy_level_obj']) self.assertIsNone(identity_obj['user_signin_obj']) self.assertEqual(identity_obj['user_type'], 1) self.assertIsNotNone(identity_obj['identity']) self.assertEqual(identity_obj['identity'], identity_obj['user_sign']) self.assertIsNone(identity_obj['blacker_type']) for x in [identity_obj['guard_top_num'], identity_obj['has_followed']]: self.assertEqual(x, 0) self.assertEqual(identity_obj['sun_resumed_time'], 180) self.assertEqual(identity_obj['sun_max_num'], 50) self.assertEqual(identity_obj['chat_resumed_time'], 1) self.assertEqual(identity_obj['shout_resumed_time'], 5) for x in [identity_obj['today_is_sign'], identity_obj['signin_max_num'], identity_obj['noble_rank'], identity_obj['noble_rest_time_int']]: self.assertEqual(x, 0) for x in [identity_obj['signin_date'], identity_obj['noble_expiretime'], identity_obj['noble_rest_time_str']]: self.assertEqual(x, u'') self.assertEqual(identity_obj['if_receive_push'], 1) self.assertEqual(identity_obj['play_area'], -1) for x in [identity_obj['is_anchor'], identity_obj['sns_id'], identity_obj['sns_from'], identity_obj['has_plat_signin'], identity_obj['plat_signin_days']]: self.assertEqual(x, 0) self.assertEqual(identity_obj['left_rename_num'],1) self.assertEqual(identity_obj['status'],1) self.assertEqual(len(identity_obj['user_package']),0)
def test_bind_phone_failed_five_times(self): """ 测试绑定手机号当天只允许失败5次 :return: """ phone = None num = 1 flag = True image_code = None while flag: send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) image_code = Redis().get_image_captcha(settings.DEVICE_ID) phone = '133' + str(random.randint(11111111, 99999999)) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': phone, 'check_code': image_code }) if send_sms_code_api.get_code() in [400126, 400136]: continue else: bind_phone_api = BindPhoneApi(self.user_name) bind_phone_api.get({ 'phone': phone, 'code': 1234, 'check_code': image_code }) self.assertEqual(bind_phone_api.get_code(), 400104) self.assertEqual(bind_phone_api.get_response_message(), u'验证码错误,请重新获取短信验证码') num += 1 if num == 6: flag = False flag = True while flag: send_image_code_api = ImageCodeApi() send_image_code_api.get({'device_id': settings.DEVICE_ID}) phone = '130' + str(random.randint(11111111, 99999999)) image_code = Redis().get_image_captcha(settings.DEVICE_ID) send_sms_code_api = SendSmsCodeApi() send_sms_code_api.get({ 'device_id': settings.DEVICE_ID, 'type': 'bind', 'phone': phone, 'check_code': image_code }) if send_sms_code_api.get_code() in [400126, 400136]: continue else: self.assertEqual(send_sms_code_api.get_code(), 0) flag = False bind_phone_api = BindPhoneApi(self.user_name) bind_phone_api.get({ 'phone': phone, 'code': 1234, 'check_code': image_code }) self.assertEqual(bind_phone_api.get_code(), 400133) self.assertEqual(bind_phone_api.get_response_message(), u'您今日操作过多,请明天再试')