def test_get_users(self): user_name = random_str() password = random_str() register(RgstHttpRpc, "", user_name, password, 1, "rdm1", urllib.quote(Signer().gen_sign("", user_name, password, 1, "rdm1"))) token = LoginGetToken(RgstHttpRpc, user_name, password) result = get_users(RgstHttpRpc, token, [user_name]) self.assertTrue(result['user_info_ls'][0]['user_name'] == user_name) cancel(RgstHttpRpc, "", user_name, password, urllib.quote(Signer().gen_sign("", user_name, password)))
def test_wechat_user_login(self): user_name = random_str() password = random_str() register(RgstHttpRpc, "", user_name, password, enum.WECHAT_USER, "TEST1", urllib.quote(Signer().gen_sign("", user_name, password, enum.WECHAT_USER, "TEST1"))) result = login(RgstHttpRpc, user_name, password, type=enum.WECHAT_USER) assert result["result"] == error_code.ERROR_SUCCESS LoginGetToken(RgstHttpRpc, user_name, password) LoginGetTokenUser(RgstHttpRpc, user_name, password) cancel(RgstHttpRpc, "", user_name, password, urllib.quote(Signer().gen_sign("", user_name, password)), enum.WECHAT_USER)
def test_sign(self): user_name = random_str() password = random_str() register_result = register(RgstHttpRpc, "", user_name, password, enum.DEVICE_USER, "TEST1", urllib.quote(Signer().gen_sign("", user_name, password, enum.DEVICE_USER, "TEST1"))) assert "sign" not in register_result login_result = login(RgstHttpRpc, user_name, password, type=enum.DEVICE_USER) assert "sign" not in login_result
def test_register_reregister(self): user_name = "random_str111" password = "******" relogin_times = 2 for _ in xrange(relogin_times): result = register(RgstHttpRpc, "", user_name, password, 1, "rdm1", urllib.quote(Signer().gen_sign("", user_name, password, 1, "rdm1"))) self.assertTrue(result['result'] == error_code.ERROR_SUCCESS) result = cancel(RgstHttpRpc, "", user_name, password, urllib.quote(Signer().gen_sign("", user_name, password))) self.assertTrue(result['result'] == error_code.ERROR_SUCCESS)
def MakeSureAccountExist(http_rpc=ServiceMgrCacher().get_connection(ST_REGISTER, protocol=PT_HTTPS)): register( http_rpc, "", DUserName1, DPassword1, DType1, "device1", urllib.quote(Signer().gen_sign("", DUserName1, DPassword1, DType1, "device1")), "10000001", ) register( http_rpc, "", DUserName2, DPassword2, DType2, "device2", urllib.quote(Signer().gen_sign("", DUserName2, DPassword2, DType2, "device2")), "10000001", )
def test_device_user_register_not_device_type(self): user_name = random_str() password = random_str() result = register(RgstHttpRpc, "", user_name, password, enum.DEVICE_USER, "TEST1", urllib.quote(Signer().gen_sign("", user_name, password, enum.DEVICE_USER, "TEST1"))) assert result["result"] == error_code.ERROR_PARAMS_ERROR
def test_user_banding_eachother(self): user_name2 = random_str() password2 = random_str() user_name3 = random_str() password3 = random_str() # register register(RgstHttpRpc, "", user_name2, password2, 1, "rdm2", urllib.quote(Signer().gen_sign("", user_name2, password2, 1, "rdm2"))) register(RgstHttpRpc, "", user_name3, password3, 1, "rdm3", urllib.quote(Signer().gen_sign("", user_name3, password3, 1, "rdm3"))) # banding banding_result = set_user_banding(RgstHttpRpc, user_name2, [user_name3]) self.assertTrue(banding_result.get("result", error_code.ERROR_SUCCESS) == error_code.ERROR_SUCCESS) # get banding user_name2 banding_result = get_user_banding(RgstHttpRpc, user_name2) self.assertTrue(user_name3 == banding_result['roster_item'][0]['nickname']) # get banding user_name3 banding_result = get_user_banding(RgstHttpRpc, user_name3) self.assertTrue(user_name2 == banding_result['roster_item'][0]['nickname']) # unbanding unbanding_result = set_user_unbanding(RgstHttpRpc, user_name2, [user_name3]) self.assertTrue(unbanding_result.get("result", error_code.ERROR_SUCCESS) == error_code.ERROR_SUCCESS) # get banding user_name2 banding_result = get_user_banding(RgstHttpRpc, user_name2) self.assertTrue(not banding_result['roster_item']) # get banding user_name3 banding_result = get_user_banding(RgstHttpRpc, user_name3) self.assertTrue(not banding_result['roster_item']) # cancel cancel(RgstHttpRpc, "", user_name2, password2, urllib.quote(Signer().gen_sign("", user_name2, password2))) cancel(RgstHttpRpc, "", user_name3, password3, urllib.quote(Signer().gen_sign("", user_name3, password3)))
def make_xmpp_relation(user_ls, add_roster=False, del_roster=False): """ xmpp用户关系设置 :param user_ls:用户列表 :param add_roster: 是否添加用户之间为roster关系 :param del_roster: 是否删除用户之间的roster关系 :return: [(jid1, jid_pass1),,,,] """ from lib.device_type import choice_device_type jid_ls = [] # register/login user http_rpc = ServiceMgrCacher().get_connection(ST_REGISTER, protocol=PT_HTTPS) for user in user_ls: login_result = login(http_rpc, user, user, enum.DEVICE_USER) if login_result.get('result', None) != error_code.ERROR_SUCCESS: regiger_result = register(http_rpc, "", user, user, enum.DEVICE_USER, user, device_type=choice_device_type()) assert regiger_result.get('result', None) == error_code.ERROR_SUCCESS login_result = login(http_rpc, user, user, enum.DEVICE_USER) assert login_result.get('result', None) == error_code.ERROR_SUCCESS jid_ls.append((login_result['user_info']['jid'], user)) # add/del roster for idx, user in enumerate(user_ls): next_idx = idx + 1 while next_idx < len(user_ls): if add_roster: try: UserService().add_roster(user_ls[idx], user_ls[next_idx]) except: pass try: UserService().add_roster(user_ls[next_idx], user_ls[idx]) except: pass if del_roster: try: UserService().del_roster(user_ls[idx], user_ls[next_idx]) except: pass try: UserService().del_roster(user_ls[next_idx], user_ls[idx]) except: pass next_idx += 1 return jid_ls
def _gen_jid(self): args = ArgumentParser().args user_name = passwd = "_".join([get_cur_ip(), str(args.tcp_port), str(args.http_port)]) http_rpc = ServiceMgrCacher().get_connection(US_REGISTER, protocol=PT_HTTPS) assert http_rpc login_result = login(http_rpc, user_name, passwd, enum.ADMIN_USER) if login_result.get("result", None) != error_code.ERROR_SUCCESS: regiger_result = register(http_rpc, "", user_name, passwd, enum.ADMIN_USER, des="bridge_auto_created") assert regiger_result.get("result", None) == error_code.ERROR_SUCCESS login_result = login(http_rpc, user_name, passwd, enum.ADMIN_USER) assert login_result.get("result", None) == error_code.ERROR_SUCCESS self.__jid = login_result["user_info"]["jid"] self.__jid_pwd = login_result["user_info"]["jid_pwd"]
def wcmt_me_subscribe(*args, **kwargs): """ wechat message event: subscribe/关注 :param args: :param kwargs: :return: """ """ 由于openfire不支持用户名大写:有大写的话,roster关系表会转化成小写 所以将openid转化为小写 """ result = register(ServiceMgrCacher().get_connection(US_REGISTER, protocol=PT_HTTPS), "", kwargs['body']['FromUserName'].lower(), WECHAT_PASSWORD, enum.WECHAT_USER, WECHAT_ACCOUNT_DES) assert result['result'] == ERROR_SUCCESS
def RgstTestUsers(http_rpc=ServiceMgrCacher().get_connection(ST_REGISTER, protocol=PT_HTTPS)): register( http_rpc, "", UserName1, Password1, enum.ADMIN_USER, "TEST1", urllib.quote(Signer().gen_sign("", UserName1, Password1, enum.ADMIN_USER, "TEST1")), ) register( http_rpc, "", UserName2, Password2, enum.ADMIN_USER, "TEST2", urllib.quote(Signer().gen_sign("", UserName2, Password2, enum.ADMIN_USER, "TEST2")), ) register( http_rpc, "", UserName3, Password3, enum.ADMIN_USER, "TEST3", urllib.quote(Signer().gen_sign("", UserName3, Password3, enum.ADMIN_USER, "TEST3")), ) register( http_rpc, "", UserName4, Password4, enum.ADMIN_USER, "TEST4", urllib.quote(Signer().gen_sign("", UserName4, Password4, enum.ADMIN_USER, "TEST4")), )
def test_device_user_get_users_device_type(self): user_name = random_str() password = random_str() dtype = choice_device_type() result = register(RgstHttpRpc, "", user_name, password, enum.DEVICE_USER, "TEST1", urllib.quote(Signer().gen_sign("", user_name, password, enum.DEVICE_USER, "TEST1")), device_type=dtype) assert result["result"] == error_code.ERROR_SUCCESS token = LoginGetToken(RgstHttpRpc, user_name, password) result = get_users(RgstHttpRpc, token, [user_name]) self.assertTrue(int(result['user_info_ls'][0]['device_type']['code']) == int(dtype)) cancel(RgstHttpRpc, "", user_name, password, urllib.quote(Signer().gen_sign("", user_name, password)))
def test_register_cancel_user(self): user_name = random_str() password = random_str() register(RgstHttpRpc, "", user_name, password, 1, "rdm1", urllib.quote(Signer().gen_sign("", user_name, password, 1, "rdm1"))) user_name2 = random_str() password2 = random_str() register(RgstHttpRpc, "", user_name2, password2, 1, "rdm2", urllib.quote(Signer().gen_sign("", user_name2, password2, 1, "rdm2"))) user_name3 = random_str() password3 = random_str() register(RgstHttpRpc, "", user_name3, password3, 1, "rdm3", urllib.quote(Signer().gen_sign("", user_name3, password3, 1, "rdm3"))) cancel(RgstHttpRpc, "", user_name, password, urllib.quote(Signer().gen_sign("", user_name, password))) cancel(RgstHttpRpc, "", user_name2, password2, urllib.quote(Signer().gen_sign("", user_name2, password2))) cancel(RgstHttpRpc, "", user_name3, password3, urllib.quote(Signer().gen_sign("", user_name3, password3)))
def test_user_banding_userls(self): user_name = random_str() password = random_str() user_name2 = random_str() password2 = random_str() user_name3 = random_str() password3 = random_str() # register register(RgstHttpRpc, "", user_name, password, 1, "rdm1", urllib.quote(Signer().gen_sign("", user_name, password, 1, "rdm1"))) register(RgstHttpRpc, "", user_name2, password2, 1, "rdm2", urllib.quote(Signer().gen_sign("", user_name2, password2, 1, "rdm2"))) register(RgstHttpRpc, "", user_name3, password3, 1, "rdm3", urllib.quote(Signer().gen_sign("", user_name3, password3, 1, "rdm3"))) # get banding banding_result = get_user_banding(RgstHttpRpc, user_name) self.assertTrue(not banding_result['roster_item']) # banding banding_result = set_user_banding(RgstHttpRpc, user_name, [user_name2, user_name3]) self.assertTrue(banding_result.get("result", error_code.ERROR_SUCCESS) == error_code.ERROR_SUCCESS) # get banding banding_result = get_user_banding(RgstHttpRpc, user_name) banding_nickname_ls = [roster_item['nickname'] for roster_item in banding_result['roster_item']] self.assertTrue(user_name2 in banding_nickname_ls) self.assertTrue(user_name3 in banding_nickname_ls) # unbanding unbanding_result = set_user_unbanding(RgstHttpRpc, user_name, [user_name2, user_name3]) self.assertTrue(unbanding_result.get("result", error_code.ERROR_SUCCESS) == error_code.ERROR_SUCCESS) # get banding banding_result = get_user_banding(RgstHttpRpc, user_name) self.assertRaises(not banding_result['roster_item']) # cancel cancel(RgstHttpRpc, "", user_name, password, urllib.quote(Signer().gen_sign("", user_name, password))) cancel(RgstHttpRpc, "", user_name2, password2, urllib.quote(Signer().gen_sign("", user_name2, password2))) cancel(RgstHttpRpc, "", user_name3, password3, urllib.quote(Signer().gen_sign("", user_name3, password3)))