def test_member_login_logout():
    login_code = '20000'
    login_req = UserTas1_pb2.LoginReq(
	    AccountType = 1111,     #required int32     账户类型 <- table userinfo
    	LoginCode = login_code, #optional string    登录号码
    	LoginPWD = '123',       #optional string    登录密码, 应该是密文,暂时不检查
        )
    conn.publish('entry', 'user_req', 0, login_req)

    sess_id, login_rsp = conn.expect('testuser_rsp', UserTas1_pb2.LoginRsp, 1.0)
    eq_(0, sess_id)
    eq_(0, login_rsp.RetCode)
    eq_(0, login_rsp.AccountType)        #int32 账户类型
    eq_(0, login_rsp.CustomerCode)       #int32 用户编号
    eq_(login_code, login_rsp.LoginCode) #string 登录号码
    eq_(1, login_rsp.AccountStatus)      #int32 用户状态
    eq_('1', login_rsp.AreaCode)         #string 用户所属机构
    eq_('1', login_rsp.MemberCode)       #string 用户所属会员的会员代码
    eq_(int(login_code), login_rsp.Header.AccountId)

    logout_req = UserTas1_pb2.LogoutReq(Header = common_pb2.MessageHead(AccountId=int(login_code)),)
    conn.publish('entry', 'user_req', 0, logout_req)
    sess_id, logout_rsp = conn.expect('testuser_rsp', UserTas1_pb2.LogoutRsp, 1.0)
    eq_(0, sess_id)
    eq_(0, logout_rsp.RetCode)
Esempio n. 2
0
def test_login_invalid_funcode_and_token_check():
    clear_queue()
    login_code = '20002'
    login_req = UserTas1_pb2.LoginReq(
        Header = common_pb2.MessageHead(FunCode=100100),
	    AccountType = 1,
    	LoginCode = login_code,
    	LoginPWD = '123',
        )
    conn.publish('entry', 'user_req', 0, login_req)
    rsp_sess_id, login_rsp = conn.expect('testuser_rsp', UserTas1_pb2.LoginRsp, 1.0)
    eq_(0, rsp_sess_id)

    login_code = '20003'
    account_id, token = login(1, login_code, '123')
    print 'account_id=', account_id, 'type=', type(account_id)
    req = UserTas1_pb2.TokenCheckReq(
        #Header = common_pb2.MessageHead(AccountId=int(login_code)),
        Header = common_pb2.MessageHead(AccountId=account_id),
        Token = token,
        )
    conn.publish('entry', 'user_req', 0, req)
    sess_id, rsp_data = conn.expect('testuser_rsp', UserTas1_pb2.TokenCheckRsp, 1.0)
    eq_(0, sess_id)
    eq_(0, rsp_data.RetCode)
    eq_(1, rsp_data.Status)
Esempio n. 3
0
def logout(account_id):
    logout_req = UserTas1_pb2.LogoutReq(
        Header = common_pb2.MessageHead(AccountId=account_id),
        )
    conn.publish('entry', 'user_req', 0, logout_req)
    sess_id, logout_rsp = conn.expect('testuser_rsp', UserTas1_pb2.LogoutRsp, 1.0)
    eq_(0, sess_id)
Esempio n. 4
0
def test_user_req_publish():  #pass
    recv_conn = msgbus.Connection('sc', '192.168.31.160', 5679, 'XBCHEN',
                                  'guest', 'guest')
    recv_chan = recv_conn.channel()
    recv_chan.exchange_declare(exchange='entry', exchange_type='direct')
    recv_chan.queue_declare(queue='user_req', durable=True)
    recv_chan.queue_bind(queue='user_req',
                         exchange='entry',
                         routing_key='user_req')
    consumer_tag = recv_conn.basic_consume(recv_chan, 'user_req')
    print 'consumer_tag = ', consumer_tag

    protobuf_data = UserTas1_pb2.P2LStatusSync()
    protobuf_data.Header.FunCode = 131632
    protobuf_data.ProxyID = 1
    protobuf_data.SessinIDStart = 268435456
    protobuf_data.SessinIDEnd = 536870911
    app_msg = msgbus.encode(131632, 0, protobuf_data)
    for i in range(6):
        proxy.chan_publish.basic_publish('entry', 'user_req', app_msg)

    try:
        while True:
            recv_conn.expect(recv_chan, 0, protobuf_data, 1.0)
    except Queue.Empty as e:
        pass
def test_login_invalid_login_code():
    clear_queue()
    login_req = UserTas1_pb2.LoginReq(
	    AccountType = 1, #required int32  int32 账户类型 <- table userinfo
    	LoginCode = '66666', #optional string   string 登录号码
    	LoginPWD = '123', #optional string  string 登录密码, 应该是密文,暂时不检查
        )
    conn.publish('entry', 'user_req', 0, login_req)

    exp_login_rsp = UserTas1_pb2.LoginRsp(
        Header = common_pb2.MessageHead(
            FunCode = 131294,
	        RequestID = 0,
	        AccountId = 0,
            ),
    	RetCode = 2,
	    )
    conn.expect2('testuser_rsp', 0, exp_login_rsp, 1.0)
Esempio n. 6
0
def publish_main(bus_ip, bus_port, vhost, username, password):
    conn = msgbus.Connection(bus_ip, bus_port, vhost, username, password, funcode_dict.funcode_dict)
    t0 = time.time()
    for account_id in range(20000, 21000):
        logout_req = UserTas1_pb2.LogoutReq(Header = common_pb2.MessageHead(AccountId=account_id))
        conn.publish('entry', 'user_rsp', 0, logout_req)
        time.sleep(0.01) # 发送速度太快,造成消息队列拥塞和丢包?
    dt = time.time() - t0
    print 'all sent in %f, speed=%f'%(dt, 1000/dt)
def test_login_invalid_password():
    clear_queue()
    login_code = '20001'
    req_data = UserTas1_pb2.LoginReq(
	    AccountType = 1, #required int32  int32 账户类型 <- table userinfo
    	LoginCode = login_code, #optional string   string 登录号码
    	LoginPWD = 'aaaaaa', #optional string  string 登录密码, 应该是密文,暂时不检查
        )
    conn.publish('entry', 'user_req', 0, req_data)

    exp_login_rsp = UserTas1_pb2.LoginRsp(
        Header = common_pb2.MessageHead(
            FunCode = 131294,
	        RequestID = 0,
	        AccountId = int(login_code),
            ),
    	RetCode = 3,
	    )
    conn.expect2('testuser_rsp', 0, exp_login_rsp, 1.0)
Esempio n. 8
0
def setup():
    global conn
    conn = msgbus.Connection(bus_ip, bus_port, vhost, username, password, funcode_dict.funcode_dict)
    conn.bind_queue('entry', 'testuser_rsp', routing_key='user_rsp')
    for account_id in range(20000, 20100):
        logout_req = UserTas1_pb2.LogoutReq(Header = common_pb2.MessageHead(AccountId=account_id))
        conn.publish('entry', 'user_rsp', 0, logout_req)
        time.sleep(0.01) # 发送速度太快,造成消息队列拥塞和丢包?
    clear_queue()
    print 'setup() complete'
def test_token_check_invalid():
    clear_queue()
    login_code = '20004'
    account_id, token = login(conn, 1, login_code, '123')
    req = UserTas1_pb2.TokenCheckReq(
        Header = common_pb2.MessageHead(AccountId=account_id),
        Token = 'aaaaaaa',
        )
    conn.publish('entry', 'user_req', 0, req)
    sess_id, rsp_data = conn.expect('testuser_rsp', UserTas1_pb2.TokenCheckRsp, 1.0)
    eq_(0, sess_id)
    eq_(9, rsp_data.RetCode)
Esempio n. 10
0
def step_login_logout(sess_id, account_type, login_code, password):
    req_data = UserTas1_pb2.LoginReq(
	    AccountType = account_type,
    	LoginCode = login_code,
    	LoginPWD = password,
        )
    conn.publish('entry', 'user_req', sess_id, req_data)

    rsp_sess_id, rsp_data = conn.expect('testuser_rsp', UserTas1_pb2.LoginRsp, 1.0)
    eq_(sess_id, rsp_sess_id)
    eq_(0, rsp_data.RetCode)

    logout_req = UserTas1_pb2.LogoutReq(
        Header = common_pb2.MessageHead(AccountId=rsp_data.Header.AccountId),
        )
    conn.publish('entry', 'user_req', 1, logout_req)
    rsp_sess_id, logout_rsp = conn.expect('testuser_rsp', UserTas1_pb2.LogoutRsp, 1.0)
    print 'logout_rsp='
    print logout_rsp
    eq_(sess_id, rsp_sess_id)
    eq_(0, logout_rsp.RetCode)
def test_login_invalid_funcode():
    clear_queue()
    login_code = '20002'
    login_req = UserTas1_pb2.LoginReq(
        Header = common_pb2.MessageHead(FunCode=100100),
	    AccountType = 1,
    	LoginCode = login_code,
    	LoginPWD = '123',
        )
    conn.publish('entry', 'user_req', 0, login_req)

    exp_login_rsp = UserTas1_pb2.LoginRsp(
        Header = common_pb2.MessageHead(
            FunCode = 131294,
	        RequestID = 0,
	        AccountId = int(login_code),
            ),
    	RetCode = 12,
	    )
    rsp_sess_id, login_rsp = conn.expect('testuser_rsp', UserTas1_pb2.LoginRsp, 1.0)
    eq_(0, rsp_sess_id)
    assert_not_equal(0, login_rsp.RetCode)
def test_token_check():
    login_code = '20003'
    account_id, token = login(conn, 1, login_code, '123')
    print 'account_id=', account_id, 'type=', type(account_id)
    req = UserTas1_pb2.TokenCheckReq(
        #Header = common_pb2.MessageHead(AccountId=int(login_code)),
        Header = common_pb2.MessageHead(AccountId=account_id),
        Token = token,
        )
    conn.publish('entry', 'user_req', 0, req)
    sess_id, rsp_data = conn.expect('testuser_rsp', UserTas1_pb2.TokenCheckRsp, 1.0)
    eq_(0, sess_id)
    eq_(0, rsp_data.RetCode)
    eq_(1, rsp_data.Status)
Esempio n. 13
0
def login(account_type, login_code, password):
    req_data = UserTas1_pb2.LoginReq(
	    AccountType = account_type, #required int32 // int32 账户类型 <- table userinfo
    	LoginCode = login_code, #optional string  // string 登录号码
    	LoginPWD = password, #optional string // string 登录密码, 应该是密文,暂时不检查
        )
    conn.publish('entry', 'user_req', 0, req_data)

    sess_id, rsp_data = conn.expect('testuser_rsp', UserTas1_pb2.LoginRsp, 1.0)
    print 'login_rsp='
    print rsp_data
    eq_(0, sess_id)
    eq_(0, rsp_data.RetCode)
    global account_id
    account_id = rsp_data.Header.AccountId
    return account_id, rsp_data.Token
def login(conn, account_type, login_code, password):
    conn.clear_queue_before_tests('testuser_rsp')
    req_data = UserTas1_pb2.LoginReq(
	    AccountType = account_type,
    	LoginCode = login_code,
    	LoginPWD = password,
        )
    conn.publish('entry', 'user_req', 0, req_data)

    sess_id, rsp_data = conn.expect('testuser_rsp', UserTas1_pb2.LoginRsp, 1.0)
    print 'login_rsp='
    print rsp_data
    eq_(0, sess_id)
    eq_(0, rsp_data.RetCode)
    global account_id
    account_id = rsp_data.Header.AccountId
    return account_id, rsp_data.Token
Esempio n. 15
0
def test_self_performance():
    t0 = time.time()
    for account_id in range(20000, 22000):
        logout_req = UserTas1_pb2.LogoutReq(Header = common_pb2.MessageHead(AccountId=account_id))
        conn.publish('entry', 'user_rsp', 0, logout_req)
        time.sleep(0.01) # 发送速度太快,造成消息队列拥塞和丢包?
    dt = time.time() - t0
    print 'all sent in %f, speed=%f'%(dt, 1000/dt)

    t0, i = time.time(), 0
    breaktime = t0 + 5.0
    while time.time() < breaktime:
        if conn.ch.basic.get('testuser_rsp'):
            breaktime = time.time() + 5.0
            i += 1
            if 0==i%100:
                print 'got at %f'%(time.time()-t0)
        else:
            time.sleep(0.01)
            #print 'sleep'
    dt = time.time()-t0-5
    print 'total %d got in %s, speed=%f'%(i, dt, i/dt)