def create(cls, username, password, gid, admin=False): # 配置普通用户信息 if admin: role = 2 join_group_id_list = [] # todo manage_group_id_list = [gid] else: role = 3 manage_group_id_list = [] # todo join_group_id_list = [gid] #"mobile": util.createPhone(), userinfo = { "domain": apiconf.BDP_DOMAIN, "username": username, "name": "name", "mobile": util.createPhone(), "email": "youxiang" + str(int(time.time())) + "@hotmail.com", "role": role, "sex": u"男", "position": "QAtest", "manage_group_id_list": manage_group_id_list, "join_group_id_list": join_group_id_list } uid = BdpSDK.instance().call_method_and_succ("usercreate", userinfo, ret_expr='["result"]') # 激活用户 # BdpSDK.instance().call_method_and_succ("userinit", uid, password, ret_expr='["result"]') Account.init_pwd(uid, password) return uid
def test_create_user(self): username = "******" + str(time.time()) password = "******" # 用户所属分组 pid = group.grouplist()[0]["group_id"] gid = group.create(username, pid) ginfo = group.groupinfo(gid) assert ginfo["group_name"] == username assert ginfo["group_id"] == gid assert ginfo["parent_group_id"] == pid # 测试创建普通用户 uid = Account.create(username, password, gid) uinfo = Account.subinfo(uid) assert uinfo['userid'] == uid assert uinfo['username'] == username assert uinfo['account_permission'] == 0 assert uinfo['role'] == 3 assert uinfo['manage_groups'] == [] # 测试冻结 sta = Account.userfrozen(uid, 1) with pytest.raises(AssertionError): Account.user_login(username, password) assert json.loads(BdpSDK.instance().raw_data)["status"] == "1029" # 测试解冻 Account.userfrozen(uid, 0) # res = Account.user_login(username, pw) # assert res["result"] is not None # 清除测试数据 Account.user_del(uid)
def test_create_adminuser(self): username = "******" + str(time.time()) password = "******" # 管理员管理分组 pid = group.grouplist()[0]["group_id"] gid = group.create(username, pid) ginfo = group.groupinfo(gid) assert ginfo["group_name"] == username assert ginfo["group_id"] == gid assert ginfo["parent_group_id"] == pid # 测试创建管理员 uid = Account.create(username, password, gid, admin=True) uinfo = Account.subinfo(uid) assert uinfo['userid'] == uid assert uinfo['username'] == username assert uinfo['account_permission'] == 0 assert uinfo['role'] == 2 assert uinfo['manage_groups'][0]['group_id'] == gid # 测试冻结 sta = Account.userfrozen(uid, 1) assert sta['status'] == "0" with pytest.raises(AssertionError): Account.user_login(username, password) assert json.loads(BdpSDK.instance().raw_data)["status"] == "1029" # 测试解冻 Account.userfrozen(uid, 0) # 清除数据 Account.user_del(uid)
def test_doubleusername(self): uid, gid = self._preuser() uinfo = Account.subinfo(uid) username = uinfo['username'] with pytest.raises(AssertionError): Account.create(username, "123qweasd", gid) assert json.loads(BdpSDK.instance().raw_data)["status"] == "8003" Account.user_del(uid)
def userfrozen(cls, sub_id_list, userfrozen): if not isinstance(sub_id_list, list): sub_id_list = [sub_id_list] sta = BdpSDK.instance().call_method_and_succ("userfrozen", sub_id_list, userfrozen, ret_expr='') return sta
def groupdel(cls, gid): openbdp = OpenbdpSdk.instance() openbdp.call_method_and_succ("openbdp_groupdel", gid) with pytest.raises(AssertionError): cls.groupinfo(gid) assert json.loads(BdpSDK.instance().raw_data)["status"] == "4"
def groupinfo(cls, gid): return BdpSDK.instance().call_method_and_succ("groupinfo", gid, ret_expr='["result"]')
def grouplist(cls): return BdpSDK.instance().call_method_and_succ("grouplist", ret_expr='["result"]')
def groupmodify(cls, gid, name=name, parent_group_id=pid): BdpSDK.instance().call_method_and_succ("groupmodify", gid, name=name, parent_group_id=parent_group_id, ret_expr='["result"]')
def create(cls, name, pid): id = BdpSDK.instance().call_method_and_succ("groupcreate", name, pid, ret_expr='["result"]') return id
def user_login(cls, username, password): return BdpSDK.instance().call_method_and_succ("login", username, password, apiconf.BDP_DOMAIN, ret_expr='')
def subinfo(cls, sub_id): result = BdpSDK.instance().call_method_and_succ("subinfo", sub_id, ret_expr='["result"]') return result
def reset_pwd(cls, uid): BdpSDK.instance().call_method_and_succ("user_reset_pwd", uid, ret_expr='["result"]')
def init_pwd(cls, uid, password): BdpSDK.instance().call_method_and_succ("userinit", uid, password, ret_expr='["result"]')
def getUid(self, username=apiconf.USER_NAME, password=apiconf.PASS_WORD): BdpSDK.instance().change_user(apiconf.BDP_DOMAIN, username, password) uid = BdpSDK.instance().call_method_and_succ( "userinfo", ret_expr='["result"]["user_id"]') self.user_id = uid return uid
def __init__(self): self.user_name = "" self.user_id = "" self.email = "" self.phone = "" self.bdp = BdpSDK.instance()
def __init__(self): self.bdp = BdpSDK.instance() self.name = "" self.g_id = "" self.p_id = ""
def user_del(cls, sub_id): openbdp = OpenbdpSdk.instance() openbdp.call_method_and_succ("openbdp_userdelete", sub_id) with pytest.raises(AssertionError): cls.subinfo(sub_id) assert json.loads(BdpSDK.instance().raw_data)["status"] == "1009"