Changeset ef2cbca


Ignore:
Timestamp:
2021-02-25T17:37:08Z (4 years ago)
Author:
/ <>
Children:
f6778cf
Parents:
3f783cf
Message:

more testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • .tests/test1.py

    r3f783cf ref2cbca  
    88        self.sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    99
    10     def sendRaw(self, msg):
     10    def sendRaw(self, msg, loud = True):
    1111        self.receive()
     12        if loud:
     13            print('FROM '+ self.nick + '|| ' + msg)
    1214        self.log += msg+'\r\n'
    1315        self.sck.send((msg+'\r\n').encode())
    1416
    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);)
    1719
    1820    def connect(self):
     
    2022            self.sck.connect(('127.0.0.1', 6667))
    2123        except:
    22             print("Connection failed")
     24            print("IRC connection failed for " + self.nick)
    2325            sys.exit(1)
     26       
     27        print("IRC connection established for " + self.nick)
    2428
    2529        self.sendRaw('USER ' + (self.nick + " ")*3)
     
    3438        self.receive()
    3539        if self.log.find('Logged in') == -1:
    36             print("Jabber Login failed")
     40            print("Jabber login failed for " + self.nick)
    3741            sys.exit(1)
     42        else:
     43            print("Jabber login successful for " + self.nick)
    3844
    3945    def receive(self):
     
    5359    def addJabberBuddy(self, nick):
    5460        self.sendPrivMsg("&bitlbee", "add 0 " + nick+"@localhost")
     61   
     62    def blockJabberBuddy(self, nick):
     63        self.sendPrivMsg("&bitlbee", "block " + nick)
    5564
    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       
     71def 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:
    6281
    6382def runTests():
     
    6887        cli.connect()
    6988        cli.jabberLogin()
    70     a, b = clis[0], clis[1]
    7189
    72     a.addJabberBuddy(b.nick)
    73     b.acceptJabberRequest()
    74     a.sendPrivMsg(b.nick, 'ohai qtie')
     90    clis[0].addJabberBuddy(clis[1].nick)
    7591
    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   
    84105
    85106if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.