Changeset ef2cbca
- Timestamp:
- 2021-02-25T17:37:08Z (4 years ago)
- Children:
- f6778cf
- Parents:
- 3f783cf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
.tests/test1.py
r3f783cf ref2cbca 8 8 self.sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 9 9 10 def sendRaw(self, msg ):10 def sendRaw(self, msg, loud = True): 11 11 self.receive() 12 if loud: 13 print('FROM '+ self.nick + '|| ' + msg) 12 14 self.log += msg+'\r\n' 13 15 self.sck.send((msg+'\r\n').encode()) 14 16 15 def sendPrivMsg(self, recip, msg ):16 self.sendRaw('PRIVMSG '+recip+' :'+msg )17 def sendPrivMsg(self, recip, msg, loud = True): 18 self.sendRaw('PRIVMSG '+recip+' :'+msg, loud);) 17 19 18 20 def connect(self): … … 20 22 self.sck.connect(('127.0.0.1', 6667)) 21 23 except: 22 print(" Connection failed")24 print("IRC connection failed for " + self.nick) 23 25 sys.exit(1) 26 27 print("IRC connection established for " + self.nick) 24 28 25 29 self.sendRaw('USER ' + (self.nick + " ")*3) … … 34 38 self.receive() 35 39 if self.log.find('Logged in') == -1: 36 print("Jabber Login failed")40 print("Jabber login failed for " + self.nick) 37 41 sys.exit(1) 42 else: 43 print("Jabber login successful for " + self.nick) 38 44 39 45 def receive(self): … … 53 59 def addJabberBuddy(self, nick): 54 60 self.sendPrivMsg("&bitlbee", "add 0 " + nick+"@localhost") 61 62 def blockJabberBuddy(self, nick): 63 self.sendPrivMsg("&bitlbee", "block " + nick) 55 64 56 def acceptJabberRequest(self): 57 recent = self.receive() 58 if recent.find("not in your buddy list") == -1: 59 print("No request found") 60 return 61 self.sendPrivMsg("&bitlbee", "yes") 65 def unblockJabberBuddy(self, nick): 66 self.sendPrivMsg("&bitlbee", "allow " + nick) 67 68 def renameJabberBuddy(self, oldnick, newnick) 69 self.sendPrivMsg("&bitlbee", "rename " + oldnick + " " + newnick) 70 71 def testSendMessage(sender, receiver, message, shouldreceive = True): 72 sender.sendPrivMsg(b.nick, message) 73 msginhere = receiver.receive() 74 received = !(msginhere.find(message) == -1) 75 if shouldreceive ^ received: 76 print('Test failed: Message from ' + sender.nick + ' to ' + receiver.nick) 77 print('Sender Log:' + a.log) 78 print('Receiver Log:' + b.log) 79 sys.exit(1) 80 else: 62 81 63 82 def runTests(): … … 68 87 cli.connect() 69 88 cli.jabberLogin() 70 a, b = clis[0], clis[1]71 89 72 a.addJabberBuddy(b.nick) 73 b.acceptJabberRequest() 74 a.sendPrivMsg(b.nick, 'ohai qtie') 90 clis[0].addJabberBuddy(clis[1].nick) 75 91 76 a.receive() 77 b.receive() 78 if b.log.find('ohai qtie') == -1: 79 print('Message not coming through') 80 print('Sender Log:' + a.log) 81 print('Receiver Log:' + b.log) 82 sys.exit(1) 83 print("Message test successful") 92 print("Test: Send message") 93 testSendMessage(clis[0],clis[1]),'ohai <3') 94 testSendMessage(clis[1],clis[0]),'uwu *pounces*') 95 print("Test passed") 96 97 print("Test: Block/Unblock") 98 clis[0].blockJabberBuddy(clis[1].nick) 99 testSendMessage(clis[1],clis[0]),'m-meow?', shouldreceive = False) 100 clis[0].unblockJabberBuddy(clis[1].nick) 101 testSendMessage(clis[1],clis[0]),'*purrs*') 102 print("Test passed") 103 104 84 105 85 106 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.