Esempio n. 1
0
    def get(self, device_id, access_token, *args, **kwargs):
        name = device_id.split('@')[0]
        regHttpRpc = ServiceMgrCacher().get_connection(US_REGISTER,protocol=PT_HTTPS)
        result=get_users(regHttpRpc, access_token, [name])

        device_id_ls = [ device_id ]

        user_info_ls = result['user_info_ls'][0]

        if user_info_ls['type'] != DEVICE_USER:
            roster = UserService().get_roster(name)
            roster_list = parse_ros_dic(roster, name=True)
            regHttpRpc = ServiceMgrCacher().get_connection(US_REGISTER,protocol=PT_HTTPS)
            result = get_users(regHttpRpc, access_token, roster_list)

            if 'user_info_ls' not in result:
                return []

            user_info_ls = result['user_info_ls']
            device_id_ls = [ user_info['jid']  for user_info in user_info_ls ]

        rpc_client = ServiceMgrCacher().get_connection(US_DEVICE_DA)

        return_ls = []

        for device_id in device_id_ls:
            result_ls = query_task(rpc_client, device_id, '')
            for result in result_ls:
                param_time = result['time']
                result['date'], result['time'] =  param_time.split(' ')
            return_ls.extend(result_ls)
        return return_ls
    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)))
Esempio n. 3
0
    def get(self, username, access_token, *args, **kwargs):
        roster = UserService().get_roster(username)
        roster_list = parse_ros_dic(roster, name=True)

        if not roster_list:
            return []

        regHttpRpc = ServiceMgrCacher().get_connection(US_REGISTER, protocol=PT_HTTPS)
        result = get_users(regHttpRpc, access_token, roster_list)

        if result['result'] == error_code.ERROR_SUCCESS:
            return result['user_info_ls']
        else:
            self.set_status(444,'error code:%s'%result['result'])
            return result
    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)))