def file_check(phoneNumList,role_name): try: dblist = connectDb.getConnectInfo() dbconn = connectDb.connectDb(dblist[0]) cursor = dbconn.cursor() cursor.execute(sql) log_tables=cursor.fetchall() log_list = [] for log_table in log_tables: cursor.execute(check_sql % (log_table)) check_result=cursor.fetchall() check_list=[] for x in check_result: y=x[0].split("/") check_list.append(y[2]) check_list=set(check_list) if (len(check_list) <= 1): #print "S" pass else: #生成短信告警信息 log_list.append('check_time:%s,bill.%s be exception: %s, please check!!!!'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),log_table,check_list)) cursor.close() connectDb.closeConnect(dbconn) #是否发短信 if (len(log_list) < 1): pass else: #短信发送 message.message_send(log_list,phoneNumList) except Exception,e: with open(r'error.log','a') as error_log: print >> error_log,('%s %s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),' Excute ft_info_data SQL Faild:',e))
def insertlog(phoneNumList,role_name,M_INTERVAL): try: dblist = connectDb.getConnectInfo() #VOP库连接 dbconn = connectDb.connectDb(dblist[0]) dbconncr = dbconn.cursor() if compareExecTime.compareExecTime(M_INTERVAL,role_name,dbconncr) == True : # print "开始执行命令" dbconncr.execute("select monitor.billpro_fk_idseq.nextval from dual") result = dbconncr.fetchall() SEQ_FK = result[0][0] #采集数统计 rstlist = runCmd.runcmd("zhcjprod") cjcount = 0 for result in rstlist: #print result cjcount += int(result.split(";")[1]) rstlistA = runCmd.runcmd("acquire_A") rstlistB = runCmd.runcmd("acquire_B") acquirelist = rstlistA + rstlistB #分发数统计并入表 for acquire in acquirelist: mvno = acquire.split(";")[0].split("/")[5] prod = acquire.split(";")[0].split("/")[6] count = int(acquire.split(";")[1]) # print 'MVNO:%s,PROD:%s,COUNT:%s'%(mvno,prod,count) dbconncr.execute("insert into monitor.i_mv_billpro(MVNO, PROD, FILE_COUNT, INSERT_TIME, FLAG,SEQ_FK) values ('" + str(mvno) + "','" + str(prod) +"','" + str(count) + "',sysdate,'0','" + str(SEQ_FK) +"')") dbconncr.execute("insert into monitor.t_mot_billpro_log(BILLPRO_ID, CJFILE_COUNT, MVNO, YY_COUNT, SJ_COUNT, DX_COUNT, ZZ_COUNT, INSERT_TIME, SEQ_FK, FLAG) select monitor.billpro_idseq.nextval,'" + str(cjcount) + "',mvno,YY,SJ,DX,ZZ,sysdate,'" + str(SEQ_FK) +"','0' from (select mvno,sum(decode(prod,'YY',file_count,0)) YY,sum(decode(prod,'SJ',file_count,0)) SJ,sum(decode(prod,'DX',file_count,0)) DX,sum(decode(prod,'ZZ',file_count,0)) ZZ from monitor.i_mv_billpro where flag = '0' and SEQ_FK = '" + str(SEQ_FK) +"' group by mvno)") dbconncr.execute("delete from monitor.i_mv_billpro where flag = '0' and seq_fk = '"+ str(SEQ_FK) +"'") #入短信表 for phoneNum in phoneNumList: dbconncr.execute("""insert into monitor.sms_send_routine (SMS_ID, TEL_NUM, ROLE_NAME, CONTENT, STATUS, INSERT_TIME, SEND_TIME) select monitor.sms_send_routine_pk_seq.nextval,'""" + str(phoneNum) + """','bill_infor',CONTENT, '0', sysdate, null from (select sum(t.cjfile_count)/count(1) || '个文件未采集,话单分发-情况:'||to_char(wm_concat('【' || mb.mvno_business_name || ':YY'|| t.yy_count ||',DX'|| t.dx_count ||',SJ'||t.sj_count || '】')) CONTENT from monitor.t_mot_billpro_log t,dbvop.mvno_business mb where t.mvno = mb.mvno_business_mark and t.flag = '0' and t.seq_fk = '"""+ str(SEQ_FK) +"""' group by t.seq_fk)""") dbconncr.execute("update monitor.t_mot_billpro_log set flag = '2' where flag = '0' and seq_fk = '"+ str(SEQ_FK) +"'") dbconn.commit() dbconncr.close() connectDb.closeConnect(dbconn) else: dbconncr.close() connectDb.closeConnect(dbconn) except Exception,e: dbconn.rollback() dbconncr.close() connectDb.closeConnect(dbconn) with open(r'error.log','a') as error_log: print >> error_log,('%s insertlog Faild: %s'%(time.ctime(),e)) log_tables = [] log_tables.append('%s insertlog Faild: %s'%(time.ctime(),e)) message.message_send(log_tables,phoneList)
def test_message_unpin_after_leaving(): """ Testing that Access Error is raised when owner of channel leaves and attempts to unpin a message in that channel """ user1 = auth.auth_register("*****@*****.**", "password", "John", "Smith") chan = channels.channels_create(user1["token"], "General", True)['channel_id'] msg = "Welcome!" mess = message.message_send(user1["token"], chan, msg)['message_id'] message.message_pin(user1["token"], mess) channel.channel_leave(user1["token"], chan) with pytest.raises(AccessError): assert message.message_unpin(user1["token"], mess) other.clear()
def test_message_unpin_already_unpinned(): """ Testing that Input Error is raised when user attempts to unpin a message which is already unpinned """ user1 = auth.auth_register("*****@*****.**", "password", "John", "Smith") chan = channels.channels_create(user1["token"], "General", True)['channel_id'] msg1 = "Hello" mess1 = message.message_send(user1["token"], chan, msg1)['message_id'] message.message_pin(user1["token"], mess1) message.message_unpin(user1["token"], mess1) with pytest.raises(InputError): assert message.message_unpin(user1["token"], mess1) other.clear()
def test_message_pin_already_pinned(users): """ Testing that Input Error is raised when user is trying to pin a message which has already been pinned """ user1 = auth.auth_register("*****@*****.**", "iamyourfather", "Anakin", "Skywalker") chan = channels.channels_create(user1["token"], "Star Wars", True)['channel_id'] test_message1 = "Very proud of my new channel!" m_id1 = message.message_send(user1["token"], chan, test_message1)['message_id'] message.message_pin(user1["token"], m_id1) with pytest.raises(InputError): assert message.message_pin(user1["token"], m_id1) other.clear()
def test_send_valid(user1): """ Testing if a single message can be sent and be stored """ user1, chan = user1 message_exp = "Test 1 test 2 swiggity Swagg" message_id = message.message_send(user1["token"], chan['channel_id'], message_exp) message_from_channel = channel.channel_messages(user1["token"], chan['channel_id'], 0) assert message_exp == message_from_channel["messages"][0]["message"] assert user1["u_id"] == message_from_channel["messages"][0]["u_id"] assert message_id["message_id"] == message_from_channel["messages"][0][ "message_id"] other.clear()
def test_remove_not_owner_not_sender(user1): """ Tests that an error is raised when a person who is not the sender or owner is tries to remove a message """ user2, chan = user1 test_user2 = auth.auth_register("*****@*****.**", "password", "Bumble", "Bee") channel.channel_join(test_user2["token"], chan['channel_id']) message_exp = "Test 1 test 2 swiggity Swagg" message_id1 = message.message_send(user2["token"], chan['channel_id'], message_exp) with pytest.raises(AccessError): message.message_remove(test_user2["token"], message_id1["message_id"]) other.clear()
def test_message_react_invalid_reactid(): clear() test_user0 = create_one_test_user() # test_user0 creates 1 public channel channel_id = channels_create(test_user0['token'], "Public Channel", True) # test_user0 sends 1 message to public channel message0 = "inital message" message0_id = message_send(test_user0['token'], channel_id['channel_id'], message0) message_react(test_user0['token'], message0_id['message_id'], 1) with pytest.raises(InputError): assert message_unreact(test_user0['token'], message0_id['message_id'], 5)
def test_remove_flocker_owner_access(): ''' Testing for a valid message removed by a flockr owner. ''' clear() user = auth_register("*****@*****.**", "password", "First", "Last") user_1 = auth_register("*****@*****.**", "password", "First_1", "Last_1") channel_1 = channels_create(user_1.get('token'), 'channel_1', True) channel_join(user.get('token'), channel_1.get('channel_id')) message_info = message_send(user_1.get('token'), channel_1.get('channel_id'), 'Hello world') print(message_info) message_remove(user_1.get('token'), message_info.get('message_id')) message_search = search(user_1['token'], 'Hello world') assert message_search == {'messages': []}
def test_message_edit_flockrowner(): clear() test_user0, test_user1 = create_two_test_users() # test_user0 creates 1 public channel public_channel_id = channels_create(test_user1['token'], "Main Channel", True) # test_user1 joins public channel channel_join(test_user0['token'], public_channel_id['channel_id']) # test_user1 sends 1 message to public channel message0 = "inital message" message0_id = message_send(test_user1['token'], public_channel_id['channel_id'], message0) assert message_edit(test_user0['token'], message0_id['message_id'], 'edited message') == {}
def test_message_unpin_user_not_in_channel(): clear() user_01, user_02 = register_n_users(2) # Create a channel and send a message channel = channels_create(user_01["token"], "channel_01", is_public=True) message = message_send(user_01["token"], channel["channel_id"], "test") # Return messages in channel channel_msg = channel_messages(user_01["token"], channel["channel_id"], 0) assert channel_msg["messages"][0]["is_pinned"] == False message_pin(user_01["token"], message["message_id"]) assert channel_msg["messages"][0]["is_pinned"] == True # User_02 tries to unpin message with pytest.raises(AccessError): message_unpin(user_02["token"], message["message_id"])
def test_message_remove_works_private(): clear() test_user0 = create_one_test_user() # test_user0 creates 1 private channel private_channel_id = channels_create(test_user0['token'], "Private Channel", False) # test_user0 sends 1 message to public channel message0 = "Let's geddit" message0_id = message_send(test_user0['token'], private_channel_id['channel_id'], message0) # assert func works for private channel assert message_remove(test_user0['token'], message0_id['message_id']) == {}
def test_message_pin_alreadypinned(): clear() test_user0 = create_one_test_user() # test_user0 creates 1 public channel channel_id = channels_create(test_user0['token'], "Public Channel", True) # test_user0 sends 1 message to public channel message0 = "inital message" message0_id = message_send(test_user0['token'], channel_id['channel_id'], message0) message_pin(test_user0['token'], message0_id['message_id']) with pytest.raises(InputError): message_pin(test_user0['token'], message0_id['message_id'])
def test_message_unpin_not_owner(make_users): # setting up users and public channel owner_ab, user_cd = make_users new_ch = channels_create(owner_ab['token'], 'test_channel_public', True) channel_invite(owner_ab["token"], new_ch["channel_id"], user_cd["u_id"]) msg_id0 = message_send(owner_ab["token"], new_ch["channel_id"], "Random msg")["message_id"] message_pin(owner_ab["token"], msg_id0) # note that channel messages returns most recent messages first in list assert channel_messages(owner_ab["token"], new_ch["channel_id"], 0)["messages"][0]["is_pinned"] with pytest.raises(AccessError): message_unpin(user_cd["token"], msg_id0)
def test_owner_pin_from_outside_channel(): clear() auth_register("*****@*****.**", "password", "User_0", "User_last_0") user_1 = auth_register("*****@*****.**", "password", "User_1", "User_last_1") channel_1 = channels_create(user_1.get('token'), 'channel_1', True) message_info = message_send(user_1.get('token'), channel_1.get('channel_id'), 'Hello world') message_search = search(user_1['token'], 'Hello world') assert message_search['messages'][0].get('message') == 'Hello world' assert message_search['messages'][0].get('is_pinned') == False message_pin(user_1.get('token'), message_info.get('message_id')) message_search = search(user_1['token'], 'Hello world') assert message_search['messages'][0].get('message') == 'Hello world' assert message_search['messages'][0].get('is_pinned') == True
def test_message_pin_invalidtoken(): clear() test_user0 = create_one_test_user() # test_user0 creates 1 public channel channel_id = channels_create(test_user0['token'], "Public Channel", True) # test_user0 sends 1 message to public channel message0 = "inital message" message0_id = message_send(test_user0['token'], channel_id['channel_id'], message0) # raise error if user1 tries to pin user0's message with pytest.raises(AccessError): message_pin('hello', message0_id['message_id'])
def test_send_not_in_channel(users): """ Testing if a single message can be sent by someone not in the channel """ user1, user2, chan = users channel.channel_leave(user2['token'], chan['channel_id']) #The user has not joined the channel message_exp = "I'm not in the channel sad boi " with pytest.raises(AccessError): assert message.message_send(user2["token"], chan["channel_id"], message_exp) message_from_channel = channel.channel_messages(user1["token"], chan["channel_id"], 0) assert message_exp != message_from_channel["messages"] other.clear()
def test_remove_owner_channel_permissions(): clear() user01, user02, user03 = register_n_users(3) channels_create(user01["token"], "channel01", is_public=True) channel02 = channels_create(user02["token"], "channel02", is_public=True) channel_join(user03["token"], channel02["channel_id"]) message = message_send(user03["token"], channel02["channel_id"], "test message") message_remove(user02["token"], message["message_id"]) assert message["message_id"] not in [ x["message_id"] for x in database["channels"][channel02["channel_id"]] ["messages"].values() ]
def test_unreact_curren_user_not_react(): """ This is to test the situation where the user is not reacted to a existing message, but other user has reacted to the message """ clear() user_a, user_b = register_n_users(2) channel_a_id = channels_create(user_a["token"], "channel_a", True)["channel_id"] channel_join(user_b["token"], channel_a_id) message_id = message_send(user_a["token"], channel_a_id, "Hi, user_b")["message_id"] message_react(user_b["token"], message_id, 1) # user_a react to a message that he hasn't reacted with pytest.raises(InputError): message_unreact(user_a["token"], message_id, 1)
def test_message_pin_valid(): ''' Test: - Pinning a message normally Scenario: - Two users register (owner and user) - Owner creates a private channel and invites user - Owner and user send messages - Test checks that all messages are not pinned - Owner pins 1 message - Test checks that the message is pinned ''' clear() # Owner and User register f_owner = auth_register('*****@*****.**', 'bananayummy', 'John', 'Monkeyson') f_user = auth_register('*****@*****.**', 'ihatebananas', 'Steven', 'Stevenson') # Owner creates private channel f_channel = channels_create(f_owner['token'], 'Private Channel', False) # Owner invites f_user to channel channel_invite(f_owner['token'], f_channel['channel_id'], f_user['u_id']) # Owner and user send messages in f_channel (Private Channel) message_send(f_owner['token'], f_channel['channel_id'], 'hELLO wOORLD!') message_send(f_owner['token'], f_channel['channel_id'], 'hello?') m_id3 = message_send(f_user['token'], f_channel['channel_id'], 'pin this pls')['message_id'] message_send(f_owner['token'], f_channel['channel_id'], 'bye world') # Get messages in channel messages = channel_messages(f_owner['token'], f_channel['channel_id'], 0)['messages'] # Check that all messages are not pinned for message in messages: assert message['is_pinned'] is False # Owner pins a message message_pin(f_owner['token'], m_id3) # Update messages in channel messages = channel_messages(f_owner['token'], f_channel['channel_id'], 0)['messages'] # Check that the message is pinned for message in messages: if message['message_id'] == m_id3: assert message['is_pinned'] is True
def test_invalid_guess(): """ Tests an unsuccessful game of hangman, focusing on invalid guesses """ _creator, guesser, chan_id = start_hangman('froot loops') message.message_send(guesser['token'], chan_id, '/guess f') with pytest.raises(InputError): assert message.message_send(guesser['token'], chan_id, '/guess froot') assert message.message_send(guesser['token'], chan_id, '/guess') assert message.message_send(guesser['token'], chan_id, '/guess oo') assert message.message_send(guesser['token'], chan_id, '/guess ') assert message.message_send(guesser['token'], chan_id, '/guess ?') other.clear()
def test_message_pin_unauthorised_user(): clear() user_01, user_02 = register_n_users(2) # Create a channel and send a message channel = channels_create(user_01["token"], "channel_01", is_public=True) channel_join(user_01["token"], channel["channel_id"]) message = message_send(user_01["token"], channel["channel_id"], "test") # Return messages in channel channel_msg = channel_messages(user_01["token"], channel["channel_id"], 0) assert channel_msg["messages"][0]["is_pinned"] == False # Ensure user_02 cannot pin message channel_join(user_02["token"], channel["channel_id"]) with pytest.raises(AccessError): message_pin(user_02["token"], message["message_id"])
def test_message_send_valid(authUser, unAuthUser, channel_id): message_send(authUser['token'], channel_id, "Message 1") message_send(authUser['token'], channel_id, "Message 2") message_send(authUser['token'], channel_id, "Message 3!") assert channel.channel_messages( authUser['token'], channel_id, 0)['messages'][0]['message'] == "Message 3!" assert channel.channel_messages(authUser['token'], channel_id, 0)['messages'][1]['message'] == "Message 2" assert channel.channel_messages(authUser['token'], channel_id, 0)['messages'][2]['message'] == "Message 1"
def test_already_answer_answers(users): """ Will test if an error is raised when the kahio game answer tries to answer the question again """ user1, user2, chan = users message_exp = "/KAHIO/Question/ A/ 1" message.message_send(user1["token"], chan['channel_id'], message_exp) message.message_send(user2["token"], chan['channel_id'], "a") with pytest.raises(InputError): message.message_send(user2["token"], chan['channel_id'], "a") other.clear()
def test_message_unreact_user_did_not_react(): ''' test that an InputError is raised when the user unreacts to a message they did not react to ''' other.clear() owner = auth.auth_register("*****@*****.**", "password", "John", "Smith") user = auth.auth_register("*****@*****.**", "password", "Will", "Smith") channel_1 = channels.channels_create(owner['token'], "channel_1", True) channel.channel_join(user['token'], channel_1['channel_id']) message_sent = message.message_send(owner['token'], channel_1['channel_id'], 'owner message') message.message_react(owner['token'], message_sent['message_id'], 1) with pytest.raises(error.InputError): message.message_unreact(user['token'], message_sent['message_id'], 1)
def test_edit_message(): """ Remove_message always returns None, but we can test it by checking if the number of messages changes after remove_message is run. """ # Need user token so can't use user1 pytest fixture user = auth.auth_register("*****@*****.**", "in pajamas", "are", "coming") chan1 = channels.channels_create(user["token"], "down", True) mess1 = message.message_send(user["token"], chan1["channel_id"], "the stairs") assert data.get_message_num() == 1 new_message = "through the door" assert data.edit_message(chan1["channel_id"], mess1["message_id"],new_message) == None message_info = data.get_message(chan1["channel_id"], mess1["message_id"]) assert message_info["message"] == new_message assert data.get_message_num() == 1 other.clear()
def test_get_message(channel1): """ Given channel containing message and message_id, returns dictionary containing message info """ channel_id = channel1["channel_id"] message_text = "G\'day" user2 = auth.auth_register("*****@*****.**", "123password", "Elliot", "Rotensttein") channel.channel_join(user2["token"], channel_id) sent_message = message.message_send(user2["token"], channel_id, message_text) message_info = data.get_message(channel_id, sent_message["message_id"]) assert message_info["message_id"] == sent_message["message_id"] assert message_info["message"] == message_text assert message_info["u_id"] == user2["u_id"] other.clear()
def test_message_react_invalid_msgid(channels_fixture): ''' Test case for when message_id is not a valid message within a channel that the authorised user has joined ''' (server_data, channels_fixture) = channels_fixture # get details for user1 and channel 1 token = channels_fixture[1]["token"] channel_id = channels_fixture[1]["channels"][0]["channel_id"] invalid_message_id = -1 # send a message to channel 1 msgid = message_send(server_data, token, channel_id, 'invalid msg id')['message_id'] # try to react to the message with pytest.raises(InputError) as error_raise: message_react(server_data, token, invalid_message_id, 1)
def test_message_react_invalid_token(channels_fixture): ''' Test case for invalid token ''' (server_data, channels_fixture) = channels_fixture # get details for user1 and channel 1 token = channels_fixture[1]["token"] invalid_token = '12345' channel_id = channels_fixture[1]["channels"][0]["channel_id"] # send a message to channel 1 msgid = message_send(server_data, token, channel_id, 'invalid token')['message_id'] # try to react to the message with pytest.raises(AccessError) as error_raise: message_react(server_data, invalid_token, msgid, 1)
def test_message_remove_invalid_token(auth_fixture): ''' Test case when token is invalid ''' (server_data, auth_fixture) = auth_fixture # get user details token1 = auth_fixture[1]['token'] invalidtoken = '12345' # create channel with user1 channel_id = channels_create(server_data, token1, 'New Channel', True)['channel_id'] # send msg with user1 msg1 = message_send(server_data, token1, channel_id, 'Testing for invalid token!')['message_id'] with pytest.raises(AccessError) as error_raise: message_remove(server_data, invalidtoken, msg1)
def test_message_pin_channel_admin_pin(): clear() user_01, user_02 = register_n_users(2) # Create a channel channel = channels_create(user_01["token"], "channel_01", is_public=True) # User_02 sends a message channel_join(user_02["token"], channel["channel_id"]) message = message_send(user_02["token"], channel["channel_id"], "test") # Return messages in channel channel_msg = channel_messages(user_01["token"], channel["channel_id"], 0) assert channel_msg["messages"][0]["is_pinned"] == False # Owner of channel attempts to pin message message_pin(user_01["token"], message["message_id"]) assert channel_msg["messages"][0]["is_pinned"] == True
def test_message_pin_flockr_admin_pin(): clear() admin, user_01, user_02 = register_n_users(3, include_admin=True) print(database) # Create a channel and send a message channel = channels_create(user_01["token"], "channel_01", is_public=True) channel_join(user_02["token"], channel["channel_id"]) message = message_send(user_02["token"], channel["channel_id"], "test") # Return messages in channel channel_msg = channel_messages(user_01["token"], channel["channel_id"], 0) assert channel_msg["messages"][0]["is_pinned"] == False # Owner of flockr can pin any message channel_join(admin["token"], channel["channel_id"]) message_pin(admin["token"], message["message_id"]) assert channel_msg["messages"][0]["is_pinned"] == True
topCount=len(resPhone) if totalCount > 0: msg="%s:短信错单异常,大于100条的号码%s个共%s条,前%s名号码:" %(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),totalCount,totalSms,topCount) for res in resPhone: message='(号码:%s,数量:%s,转企:%s,省份:%s)' %res msgList.append(message) elif totalCount == 0: msg="%s:短信错单无异常,大于100条的号码%s个" %(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),totalCount) message=','.join(msgList) messageList=[msg+message] info='%s%s' % (msg,message) with open(r'./log/mainSms_info.log','a') as info_log: print >> info_log,('%s') %(info) return messageList except Exception,e: err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute mainSmsError.dealRes falied') with open(r'./log/mainSms_error.log','a') as error_log: print >> error_log,('%s %s') %(err,e) if __name__ == '__main__': phoneNumList=['13041230875','18611184461','13146074440','18611397905','13146096668','13120370754'] #phoneNumList=['13146096668'] try: resultlist=dealRes() if len(resultlist) != 0: message.message_send(resultlist,phoneNumList) except Exception,e: smserr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'短信发送失败') with open(r'./log/sms_error.log','a') as error_log: print >> error_log,('%s %s' % (smserr,e))