コード例 #1
0
def del_ticket_init():
    all_ticket = {}
    ticket_tmp = {}
    ticket_1 = []
    ticket_2 = []
    # 更新指定工单状态为关闭
    update_ticket_state_cmd = [
        delete_ticket, 'delete_ticket-init', 'post', {
            'ticket_id': 'xxxx'
        }
    ]
    # 获取所有安装工单
    get_ticket_1_by_home_cmd = [
        get_ticket_by_home, 'get_ticket_by_home-init', 'get', {
            'home_id': home_id,
            'service_type': 1
        }
    ]
    ret_get_ticket_1_by_home = run_case(get_ticket_1_by_home_cmd[0],
                                        get_ticket_1_by_home_cmd[1],
                                        get_ticket_1_by_home_cmd[2],
                                        get_ticket_1_by_home_cmd[3], False)

    # 获取所有售后工单
    get_ticket_1_by_home_cmd[3]['service_type'] = 2
    ret_get_ticket_2_by_home = run_case(get_ticket_1_by_home_cmd[0],
                                        get_ticket_1_by_home_cmd[1],
                                        get_ticket_1_by_home_cmd[2],
                                        get_ticket_1_by_home_cmd[3], False)

    # 格式化所有工单和状态
    for tmp in ret_get_ticket_1_by_home['home_ticket_list']:
        # 如果是测试用安装工单,跳过
        if tmp['ticket_id'] == install_ticket:
            continue
        ticket_tmp[tmp['ticket_id']] = tmp['ticket_state']
        ticket_1.append(ticket_tmp)
        ticket_tmp = {}
    for tmps in ret_get_ticket_2_by_home['home_ticket_list']:
        # 如果是测试用维修工单,跳过
        if tmps['ticket_id'] == fix_ticket:
            continue
        ticket_tmp[tmps['ticket_id']] = tmps['ticket_state']
        ticket_2.append(ticket_tmp)
        ticket_tmp = {}
    all_ticket.update({'install_ticket': ticket_1, 'fix_ticket': ticket_2})
    print(all_ticket)
    # 更新所有工单状态为关闭
    for ticket_tmp in all_ticket.keys():
        for ticket_tmp_2 in all_ticket[ticket_tmp]:
            for ticket_id_tmp in ticket_tmp_2.keys():
                if ticket_tmp_2[ticket_id_tmp] == 5:
                    continue
                else:
                    update_ticket_state_cmd[3]['ticket_id'] = ticket_id_tmp
                    run_case(update_ticket_state_cmd[0],
                             update_ticket_state_cmd[1],
                             update_ticket_state_cmd[2],
                             update_ticket_state_cmd[3], False)
    return
コード例 #2
0
def init_del_room():
    del_cmd_num = 5
    add_rooms_cmd = [
        add_rooms, 'add_rooms-init', 'post', {
            'home_id':
            home_id,
            'rooms': [{
                'room_id': get_string(3),
                'room_name': get_string(3),
                'room_description': '测试',
                'sp_state': '1',
                'install_state': '1'
            }]
        }
    ]
    search_home_cmd = [search_home_info, 'search_home_info-init', 'get', {}]
    ret_search_home = run_case(search_home_cmd[0], search_home_cmd[1],
                               search_home_cmd[2], search_home_cmd[3], False)
    for tmp_home in ret_search_home['home_list']:
        if tmp_home['home_name'] == 'OpenAPI':
            if len(tmp_home['rooms']) - 4 < del_cmd_num:
                for i in range(del_cmd_num - len(tmp_home['rooms']) + 4):
                    add_rooms_cmd[3]['rooms'][0]['room_id'] = add_rooms_cmd[3][
                        'rooms'][0]['room_name'] = get_string(3)
                    ret_add_rooms = run_case(add_rooms_cmd[0],
                                             add_rooms_cmd[1],
                                             add_rooms_cmd[2],
                                             add_rooms_cmd[3], False)
    print('初始化删除房间完成')
    return
コード例 #3
0
def init_del_home():
    del_cmd_num = 3
    cant_del_home = 0
    add_home_cmd = [
        add_home, 'add_home-init', 'post', {
            'home_type': 2,
            'country': '中国',
            'city': '深圳',
            'zone': '南山区',
            'location': '深南大道',
            'block': '深南花园',
            'home_id': 'xxx',
            'home_name': 'xxx',
            'description': '深南花园描述'
        }
    ]
    search_home_cmd = [search_home_info, 'add_home-init', 'get', {}]
    ret_search_home = run_case(search_home_cmd[0], search_home_cmd[1],
                               search_home_cmd[2], search_home_cmd[3], False)
    for tmp in ret_search_home['home_list']:
        if tmp['home_name'] in ['OpenAPI', 'OpenAPI2'] or tmp['devices'] != []:
            cant_del_home += 1
    if len(ret_search_home['home_list']) - cant_del_home < del_cmd_num:
        for i in range(del_cmd_num - len(ret_search_home['home_list']) +
                       cant_del_home):
            add_home_cmd[3]['home_id'] = 'test01_' + get_string(3)
            add_home_cmd[3]['home_name'] = add_home_cmd[3]['home_id']
            ret_add_home = run_case(add_home_cmd[0], add_home_cmd[1],
                                    add_home_cmd[2], add_home_cmd[3], False)
    print("初始化删除房源完成")
    return
コード例 #4
0
def add_tenant_init(tenant_room=room_1001):
    add_tenant_cmd = [
        add_tenant, 'add_tenant_init', 'post', {
            'room_id': tenant_room,
            'tenant_name': get_string(5),
            'tenant_phone': phonenumber,
            'start_time': now_ms,
            'end_time': after_ms
        }
    ]
    get_room_tenant_cmd = [
        get_tenant_by_roomid, 'get_tenant_by_roomid_init', 'get', {
            'room_id': tenant_room
        }
    ]
    ret_get_room_tenant = run_case(get_room_tenant_cmd[0],
                                   get_room_tenant_cmd[1],
                                   get_room_tenant_cmd[2],
                                   get_room_tenant_cmd[3], False)
    if 'tenant_phone' in ret_get_room_tenant:
        return True
    else:
        ret_add_tenant = run_case(add_tenant_cmd[0], add_tenant_cmd[1],
                                  add_tenant_cmd[2], add_tenant_cmd[3], False)
        if 'tenant_phone' in ret_add_tenant:
            return True
        else:
            return False
コード例 #5
0
def empty_lock_password(ifhold = True):
    print('开始清空密码')
    fetch_passwords_cmd = [fetch_passwords, 'fetch_passwords-init', 'get', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid}]
    delete_password_cmd = [delete_password, 'delete_password-init', 'post',
                           {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid, 'password_id': 123}]
    ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
    for tmp in ret_fetch_passwords['passwords']:
        # 管理员密码
        if tmp == '999' or tmp == '3000':
            continue
        else:
            # 保留生效和冻结的密码
            if ifhold:
                if check_pwd_state(tmp, 2):
                    print(tmp, '属于生效密码,continue...')
                    continue
                elif check_pwd_state(tmp, 5):
                    print(tmp, '属于冻结密码,continue...')
                    continue
            print(tmp, '删除!')
            delete_password_cmd[3]['password_id'] = int(tmp)
            run_case(delete_password_cmd[0], delete_password_cmd[1], delete_password_cmd[2], delete_password_cmd[3], False)
    ret_fetch_passwords_2 = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
    print(ret_fetch_passwords_2['passwords'].keys())
    print('清空密码完成')
    return
コード例 #6
0
def init_home_date():
    all_home_id = []
    # 查询所有房源
    search_home_ret = run_case(search_home_info, 'search_home_info-init',
                               'get', {}, False)
    for tmp in search_home_ret['home_list']:
        if tmp['home_name'] == 'OpenAPI' or tmp[
                'home_name'] == 'OpenAPI2' or tmp['devices'] != []:
            continue
        all_home_id.append(tmp['home_id'])

    # 删除所有房源
    for tmp in all_home_id:
        if tmp == home_id or tmp == home_id_2:
            continue
        del_home_ret = run_case(del_home, 'del_home-init', 'post',
                                {'home_id': tmp}, False)

    # OpenAPI下只保留公区,1001,1002,1003房间
    for tmp in search_home_ret['home_list']:
        if tmp['home_name'] == 'OpenAPI':
            for tmp_room in tmp['rooms']:
                if tmp_room['room_id'] not in [
                        room_pub, room_1001, room_1002, room_1003
                ]:
                    ret = run_case(del_room, 'del_room-init', 'post', {
                        'home_id': home_id,
                        'room_id': tmp_room['room_id']
                    }, False)
    print("初始化房源完成")
    return
コード例 #7
0
def del_all_tenant(tenant_room=[room_1001, room_1002, room_1003]):
    ret_b = False
    if isinstance(tenant_room, str):
        del_tenant_cmd = [
            delete_tenant, 'delete_tenant_init', 'post', {
                'room_id': tenant_room
            }
        ]
        ret = run_case(del_tenant_cmd[0], del_tenant_cmd[1], del_tenant_cmd[2],
                       del_tenant_cmd[3], False)
        if ret['ErrNo'] == 0 or ret['ErrNo'] == 15904:
            ret_b = True
    elif isinstance(tenant_room, list):
        for room_id in tenant_room:
            del_tenant_cmd = [
                delete_tenant, 'delete_tenant_init', 'post', {
                    'room_id': room_id
                }
            ]
            ret = run_case(del_tenant_cmd[0], del_tenant_cmd[1],
                           del_tenant_cmd[2], del_tenant_cmd[3], False)
            if ret['ErrNo'] == 0 or ret['ErrNo'] == 15904:
                ret_b = True
            if not ret_b:
                break
    # print(ret)
    if ret_b:
        print('删除租客完成')
        return True
    else:
        print('删除租客失败')
        return False
コード例 #8
0
def get_password_id(flag='center'):
    global retrytimes
    add_password_cmd = [add_password, 'add_password-init', 'post',
                        {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid,
                         'phonenumber': phonenumber, 'is_default': 0, 'is_send_location': False, 'password': '******',
                         'name': 'test', 'permission_begin': now_s, 'permission_end': after_s}]
    add_password_without_center_cmd = [add_password_without_center, 'add_password_without_center-init', 'post',
                                   {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid,
                                    'phonenumber': phonenumber, 'CMD': 1, 'name': get_string(4), 'is_send_msg': False, 'is_send_location': False,
                                    'permission_end': after_s}]
    fetch_passwords_cmd = [fetch_passwords, 'fetch_passwords-init', 'get', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid}]
    frozen_password_cmd = [frozen_password, 'frozen_password-init', 'post', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid, 'password_id': 1016}]
    ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
    for tmp in ret_fetch_passwords['passwords']:
        if tmp == '999' or tmp == '3000':
            continue
        elif int(tmp) < 3000:
            # 在线密码
            if flag == 'center':
                if check_pwd_state(tmp, 2) and check_operation_stage(tmp, 3):
                    return tmp
            # 冻结的在线密码
            elif flag == 'frozen_center':
                if check_pwd_state(tmp, 5) and check_operation_stage(tmp, 3):
                    return tmp
        elif int(tmp) > 3000:
            # 离线密码
            if flag == 'without_center':
                if check_pwd_state(tmp, 2) and check_operation_stage(tmp, 3):
                    return tmp
            # 冻结的离线密码
            elif flag == 'frozen_without_center':
                if check_pwd_state(tmp, 5) and check_operation_stage(tmp, 3):
                    return tmp
    retrytimes += 1
    if retrytimes > 5:
        return False
    print(retrytimes)
    # 如果不存在,则添加
    if flag == 'center':
        run_case(add_password_cmd[0], add_password_cmd[1], add_password_cmd[2], add_password_cmd[3], False)
        return get_password_id('center')
    elif flag == 'without_center':
        run_case(add_password_without_center_cmd[0], add_password_without_center_cmd[1], add_password_without_center_cmd[2], add_password_without_center_cmd[3], False)
        return get_password_id('without_center')
    elif flag == 'frozen_center':
        frozen_password_cmd[3]['password_id'] = int(get_password_id('center'))
        run_case(frozen_password_cmd[0], frozen_password_cmd[1], frozen_password_cmd[2], frozen_password_cmd[3], False)
        return get_password_id('frozen_center')
    elif flag == 'frozen_without_center':
        frozen_password_cmd[3]['password_id'] = int(get_password_id('without_center'))
        run_case(frozen_password_cmd[0], frozen_password_cmd[1], frozen_password_cmd[2], frozen_password_cmd[3], False)
        return get_password_id('frozen_without_center')
コード例 #9
0
def check_pwd_state(password_id=1234, pwd_state=2):
    pwd_id_flag = False
    fetch_passwords_cmd = [fetch_passwords, 'fetch_passwords-init', 'get', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid}]
    for i in range(3):
        ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
        if not pwd_id_flag:
            for tmp in ret_fetch_passwords['passwords']:
                if tmp == str(password_id):
                    pwd_id_flag = True
                else:
                    continue
        if pwd_id_flag:
            try:
                if ret_fetch_passwords['passwords'][password_id]['pwd_state'] == pwd_state:
                    return True
                else:
                    if i == 2:
                        return False
                    else:
                        time.sleep(2)
                        continue
            except:
                pass
        else:
            return False
    return False
コード例 #10
0
def check_operation_stage(password_id=1234, operation_stage=3):
    # 判断传入的pwd_id是否存在
    pwd_id_flag = False
    fetch_passwords_cmd = [fetch_passwords, 'fetch_passwords-init', 'get', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid}]
    for i in range(10):
        ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
        if not pwd_id_flag:
            for tmp in ret_fetch_passwords['passwords']:
                if tmp == str(password_id):
                    pwd_id_flag = True
                else:
                    continue
        if pwd_id_flag:
            try:
                if ret_fetch_passwords['passwords'][password_id]['operation_stage'] == int(operation_stage):
                    return True
                else:
                    if i == 9:
                        return False
                    else:
                        time.sleep(1)
                        continue
            except:
                pass
        else:
            return False
    return False
コード例 #11
0
def test():
    frozen_password_id = []
    delete_password_id = []
    tmp_id = {}
    fetch_passwords_cmd = [fetch_passwords, 'fetch_passwords-init', 'get', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid}]
    delete_password_cmd = [delete_password, 'delete_password-init', 'post',
                           {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid, 'password_id': 123}]
    frozen_password_cmd = [frozen_password, 'frozen_password-init', 'post',
                           {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid, 'password_id': 1016}]
    unfrozen_password_cmd = [unfrozen_password, 'unfrozen_password-init', 'post',
                             {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid, 'password_id': 1016}]
    add_password_cmd = [add_password, 'add_password-init', 'post',
                        {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid,
                         'phonenumber': phonenumber, 'is_default': 0, 'is_send_location': True, 'password': '******',
                         'name': 'test', 'permission_begin': now_s, 'permission_end': after_s}]
    add_password_without_center_cmd = [add_password_without_center, 'add_password_without_center-init', 'post',
                                       {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid,
                                        'phonenumber': phonenumber, 'CMD': 1, 'name': 'test', 'is_send_msg': True, 'is_send_location': True,
                                        'permission_end': after_s}]
    # ret_frozen_password = run_case(frozen_password_cmd[0], frozen_password_cmd[1], frozen_password_cmd[2], frozen_password_cmd[3])
    # for i in range(2):
    #     run_case(add_password_cmd[0], add_password_cmd[1], add_password_cmd[2], add_password_cmd[3], True)
    for i in range(6):
        run_case(add_password_cmd[0], add_password_cmd[1], add_password_cmd[2], add_password_cmd[3], True)
        # run_case(add_password_without_center_cmd[0], add_password_without_center_cmd[1], add_password_without_center_cmd[2], add_password_without_center_cmd[3], True)
        time.sleep(2)

    ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
    for tmp in ret_fetch_passwords['passwords']:
        tmp_id.update(
            {tmp: {'pwd_state': ret_fetch_passwords['passwords'][tmp]['pwd_state'], 'operation_stage': ret_fetch_passwords['passwords'][tmp]['operation_stage']}})
    tmp_id = json.dumps(tmp_id, sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False)
    print(tmp_id)
    # print(ret_fetch_passwords['passwords']['1016']['pwd_state'])
    # print(ret_fetch_passwords['passwords']['1016']['operation_stage'])

    # ret_unfrozen_password = run_case(unfrozen_password_cmd[0], unfrozen_password_cmd[1], unfrozen_password_cmd[2], unfrozen_password_cmd[3])
    # for tmp in ret_fetch_passwords['passwords']:
    #     if tmp == '999':
    #         continue
    #     elif ret_fetch_passwords['passwords'][tmp]['pwd_state'] == 5:
    #         frozen_password_id.append(tmp)
    #     else:
    #         delete_password_id.append(tmp)
    # print(delete_password_id)
    # print(frozen_password_id)
    return
コード例 #12
0
def search_all_home():
    # result = send_request(access_token, 'post', {'client_id': '8a2dd447f145c30ec642c818', 'client_secret': 'c103ebd29d15f981146df864456e51541e740052'})
    search_home_ret = run_case(search_home_info, 'search_home_info_init',
                               'get', {
                                   'offset': 0,
                                   'count': 20
                               })
    # search_home_json = json.dumps(search_home_ret.json(), sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False)
    # print(search_home_json)
    return
コード例 #13
0
def get_id(flag='home_id', home_id_=home_id):
    ret_id = ''
    search_home_cmd = [search_home_info, 'search_home-init', 'get', {}]
    add_home_cmd = [
        add_home, 'add_home-init', 'post', {
            'home_type': 2,
            'country': '中国',
            'city': '深圳',
            'zone': '南山区',
            'location': '深南大道',
            'block': '深南花园',
            'home_id': 'test01_' + get_string(3),
            'home_name': 'test01_' + get_string(3),
            'description': '深南花园描述'
        }
    ]
    ret_search_home = run_case(search_home_cmd[0], search_home_cmd[1],
                               search_home_cmd[2], search_home_cmd[3], False)
    for tmp in ret_search_home['home_list']:
        if flag == 'home_id':
            # 排除测试房源和房源名称包含test_01的房源
            if tmp['home_id'] not in [home_id, home_id_2]:
                # 房源存在设备,继续
                if tmp['devices']:
                    continue
                ret_id = tmp['home_id']
                break
        elif flag == 'room_id':
            if tmp['home_id'] == home_id_:
                for tmp_room in tmp['rooms']:
                    # 排除公区和测试用的room_id
                    if tmp_room['room_id'] != home_id_ and tmp_room[
                            'room_id'] not in [
                                room_1001, room_1002, room_1003
                            ]:
                        # 如果房间存在绑定设备,继续
                        if tmp_room['sp_state'] == 2:
                            continue
                        ret_id = tmp_room['room_id']
                        break
    if not ret_id:
        if flag == 'home_id':
            tmp_home_id = add_home_test(1)
            print('tmp_home_id: ', tmp_home_id)
            if tmp_home_id:
                ret_id = tmp_home_id[0]
        elif flag == 'room_id':
            tmp_room_id = add_room_test(home_id_, 1)
            print('home_id: ', home_id_)
            print('tmp_room_id: ', tmp_room_id)
            if tmp_room_id:
                ret_id = tmp_room_id[0]
    return ret_id
コード例 #14
0
def init_delete_frozen_password():
    password_id = []
    add_password_cmd = [add_password, 'add_password-init', 'post',
                        {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid,
                         'phonenumber': phonenumber, 'is_default': 0, 'is_send_location': False, 'password': '******',
                         'name': 'test', 'permission_begin': now_s, 'permission_end': after_s}]
    fetch_passwords_cmd = [fetch_passwords, 'fetch_passwords-init', 'get', {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid}]
    delete_password_cmd = [delete_password, 'delete_password-init', 'post',
                           {'home_id': home_id, 'room_id': room_1001, 'uuid': lock_uuid, 'password_id': 123}]
    ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
    with open(param_path + 'delete_password_cmd') as fl:
        del_pwd_num = len(fl.readlines())
    with open(param_path + 'frozen_password_cmd') as fl:
        del_pwd_num += len(fl.readlines())
    # 统计非管理员和非冻结的密码,如果大于需要的密码数,直接返回,否则,补齐后返回
    for tmp in ret_fetch_passwords['passwords']:
        if tmp == '999':
            continue
        try:
            if ret_fetch_passwords['passwords'][tmp]['pwd_state'] == 2:
                password_id.append(tmp)
            else:
                delete_password_cmd[3]['password_id'] = int(tmp)
                run_case(delete_password_cmd[0], delete_password_cmd[1], delete_password_cmd[2], delete_password_cmd[3], False)
        except:
            pass
    if len(password_id) < del_pwd_num:
        for i in range(del_pwd_num - len(password_id)):
            ret_add_password_cmd = run_case(add_password_cmd[0], add_password_cmd[1], add_password_cmd[2], add_password_cmd[3], False)
            while check_operation_stage(ret_add_password_cmd['id'], 2) or check_operation_stage(ret_add_password_cmd['id'], 3):
                break
            password_id.append(ret_add_password_cmd['id'])
    ret_fetch_passwords = run_case(fetch_passwords_cmd[0], fetch_passwords_cmd[1], fetch_passwords_cmd[2], fetch_passwords_cmd[3], False)
    if len(ret_fetch_passwords['passwords']) - 1 >= del_pwd_num:
        print('初始化删除密码完成')
    else:
        print('初始化删除密码失败')
        print('need: '+str(del_pwd_num)+'\nactural: '+str(len(ret_fetch_passwords['passwords'])-1))
    return password_id
コード例 #15
0
def add_room_test(home_id_test=home_id, count=5):
    room_ids = []
    add_rooms_cmd = [
        add_rooms, 'add_rooms-test', 'post', {
            'home_id':
            home_id_test,
            'rooms': [{
                'room_id': 'test',
                'room_name': 'test',
                'room_description': '测试',
                'sp_state': '1',
                'install_state': '1'
            }]
        }
    ]
    for i in range(count):
        add_rooms_cmd[3]['rooms'][0]['room_id'] = add_rooms_cmd[3]['rooms'][0][
            'room_name'] = 'room_id_' + get_string(3)
        ret_add_rooms = run_case(add_rooms_cmd[0], add_rooms_cmd[1],
                                 add_rooms_cmd[2], add_rooms_cmd[3], False)
        room_ids.append(add_rooms_cmd[3]['rooms'][0]['room_id'])
    return room_ids
コード例 #16
0
def add_home_test(count=3):
    home_ids = []
    add_home_cmd = [
        add_home, 'add_home-test', 'post', {
            'home_type': 2,
            'country': '中国',
            'city': '深圳',
            'zone': '南山区',
            'location': '深南大道',
            'block': '深南花园',
            'home_id': 'xxx',
            'home_name': 'xxx',
            'description': '深南花园描述'
        }
    ]
    for i in range(count):
        add_home_cmd[3]['home_id'] = 'test_' + get_string(3)
        add_home_cmd[3]['home_name'] = add_home_cmd[3]['home_id']
        ret_add_home = run_case(add_home_cmd[0], add_home_cmd[1],
                                add_home_cmd[2], add_home_cmd[3], False)
        home_ids.append(ret_add_home['home_id'])
    return home_ids
コード例 #17
0
def get_ticket_id(ticket='fix', ticket_state=1):
    all_install_ticket_id = []
    all_fix_ticket_id = []
    # 获取所有安装工单
    get_ticket_1_by_home_cmd = [
        get_ticket_by_home, 'get_ticket_by_home-init', 'get', {
            'home_id': home_id,
            'service_type': 1
        }
    ]
    update_ticket_state_cmd = [
        update_ticket_state, 'update_ticket_state-init', 'post', {
            'ticket_id': 'xxx',
            'ticket_state': ticket_state
        }
    ]
    ret_get_ticket_1_by_home = run_case(get_ticket_1_by_home_cmd[0],
                                        get_ticket_1_by_home_cmd[1],
                                        get_ticket_1_by_home_cmd[2],
                                        get_ticket_1_by_home_cmd[3], False)
    for tmp in ret_get_ticket_1_by_home['home_ticket_list']:
        if tmp['ticket_id'] == install_ticket:
            continue
        all_install_ticket_id.append({
            'ticket_id': tmp['ticket_id'],
            'ticket_state': tmp['ticket_state']
        })
    # all_install_ticket_id_json = json.dumps(all_install_ticket_id, sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False)
    # print(all_install_ticket_id_json)

    # 获取所有售后工单
    get_ticket_1_by_home_cmd[3]['service_type'] = 2
    ret_get_ticket_2_by_home = run_case(get_ticket_1_by_home_cmd[0],
                                        get_ticket_1_by_home_cmd[1],
                                        get_ticket_1_by_home_cmd[2],
                                        get_ticket_1_by_home_cmd[3], False)
    for tmp2 in ret_get_ticket_2_by_home['home_ticket_list']:
        if tmp2['ticket_id'] == fix_ticket:
            continue
        all_fix_ticket_id.append({
            'ticket_id': tmp2['ticket_id'],
            'ticket_state': tmp2['ticket_state']
        })
    # all_fix_ticket_id_json = json.dumps(all_fix_ticket_id, sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False)
    # print(all_fix_ticket_id_json)

    # 增加工单
    add_ticket_1_cmd = [
        add_ticket, 'add_ticket-init', 'post', {
            'home_id': home_id,
            'service_target': 2,
            'service_type': 1,
            'room_ids': [home_id, room_1001],
            'subscribe': {
                'date': now_ms,
                'time': 100,
                'name': 'lifc_test',
                'phone': '18566260535',
                'note': 'test'
            }
        }
    ]
    if ticket == 'install':
        if len(all_install_ticket_id) == 0:
            ret_add_ticket_1 = run_case(add_ticket_1_cmd[0],
                                        add_ticket_1_cmd[1],
                                        add_ticket_1_cmd[2],
                                        add_ticket_1_cmd[3], False)
            update_ticket_state_cmd[3]['ticket_state'] = ticket_state
            update_ticket_state_cmd[3]['ticket_id'] = ret_add_ticket_1[
                'ticket_id']
            update_ticket_1 = run_case(update_ticket_state_cmd[0],
                                       update_ticket_state_cmd[1],
                                       update_ticket_state_cmd[2],
                                       update_ticket_state_cmd[3], False)
            if ret_add_ticket_1['ticket_id'] != None:
                return ret_add_ticket_1['ticket_id']
        else:
            for tmp_install in all_install_ticket_id:
                if tmp_install['ticket_state'] == ticket_state:
                    return tmp_install['ticket_id']
            update_ticket_state_cmd[3]['ticket_state'] = ticket_state
            update_ticket_state_cmd[3]['ticket_id'] = all_install_ticket_id[0][
                'ticket_id']
            update_ticket_1 = run_case(update_ticket_state_cmd[0],
                                       update_ticket_state_cmd[1],
                                       update_ticket_state_cmd[2],
                                       update_ticket_state_cmd[3], False)
            return all_install_ticket_id[0]['ticket_id']
    elif ticket == 'fix':
        if len(all_fix_ticket_id) == 0:
            add_ticket_1_cmd[3]['service_type'] = 2
            ret_add_ticket_2 = run_case(add_ticket_1_cmd[0],
                                        add_ticket_1_cmd[1],
                                        add_ticket_1_cmd[2],
                                        add_ticket_1_cmd[3], False)
            update_ticket_state_cmd[3]['ticket_state'] = ticket_state
            update_ticket_state_cmd[3]['ticket_id'] = ret_add_ticket_2[
                'ticket_id']
            update_ticket_1 = run_case(update_ticket_state_cmd[0],
                                       update_ticket_state_cmd[1],
                                       update_ticket_state_cmd[2],
                                       update_ticket_state_cmd[3], False)
            if ret_add_ticket_2['ticket_id'] != None:
                return ret_add_ticket_2['ticket_id']
        else:
            for tmp_fix in all_fix_ticket_id:
                if tmp_fix['ticket_state'] == ticket_state:
                    return tmp_fix['ticket_id']
            update_ticket_state_cmd[3]['ticket_state'] = ticket_state
            update_ticket_state_cmd[3]['ticket_id'] = all_fix_ticket_id[0][
                'ticket_id']
            update_ticket_1 = run_case(update_ticket_state_cmd[0],
                                       update_ticket_state_cmd[1],
                                       update_ticket_state_cmd[2],
                                       update_ticket_state_cmd[3], False)
            return all_fix_ticket_id[0]['ticket_id']
    else:
        raise AssertionError('错误的ticket: %s' % ticket)
    return