def testFilesDeclinePath(self): fileData = self._generateData() self.gotDecline = False # Send the file (client2->client1) msnContact = msn.MSNContact(userHandle='*****@*****.**', caps=msn.MSNContact.MSNC1) fileSend, d = self.client2.sendFile(msnContact, "myfile.txt", len(fileData)) def accepted((yes, )): self.failUnless((not yes), "Failed to understand a decline.") self.gotDecline = True def failed(): raise "TransferError" d.addCallback(accepted) d.addErrback(failed) # Let the request get pushed to client1 self._loop(10) # Decline the file fileReceive = self.client1.fileReceive fileReceive.reject() # Let the decline get pushed to client2 self._loop(10) self.failUnless((self.gotDecline), "Failed to understand a decline, ignored.")
def testUserRemovedMe(self): self.client.factory.contacts = msn.MSNContactList() contact = msn.MSNContact(userHandle='*****@*****.**') contact.addToList(msn.REVERSE_LIST) self.client.factory.contacts.addContact(contact) self.client.lineReceived("REM 0 RL [email protected]") self.failUnless(self.client.state == 'USERREMOVEDME', "Failed to remove user from reverse list")
def testRemContactAL(self): self.client.factory.contacts = msn.MSNContactList() self.client.factory.contacts.addContact( msn.MSNContact(userGuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", userHandle="*****@*****.**", screenName="Some guy", lists=msn.ALLOW_LIST)) self.client.doRemContactAL() self.failUnless(self.loop.doSteps(10), 'Failed to disconnect') self.failUnless((self.client.test == 'PASS'), 'Failed to remove contact from allow list')
def testAsyncPhoneChange(self): c = msn.MSNContact(userHandle='*****@*****.**') self.client.factory.contacts = msn.MSNContactList() self.client.factory.contacts.addContact(c) self.client.makeConnection(StringIOWithoutClosing()) self.client.lineReceived("BPR 101 [email protected] PHH 123%20456") c = self.client.factory.contacts.getContact('*****@*****.**') self.failUnless(self.client.state == 'GOTPHONE', "Did not fire phone change callback") self.failUnless(c.homePhone == '123 456', "Did not update the contact's phone number") self.failUnless(self.client.factory.contacts.version == 101, "Did not update list version")
def testFilesHappyChunkedPath(self): fileData = self._generateData() self.gotFile = False # Send the file (client2->client1) msnContact = msn.MSNContact(userHandle='*****@*****.**', caps=msn.MSNContact.MSNC1) fileSend, d = self.client2.sendFile(msnContact, "myfile.txt", len(fileData)) def accepted((yes, )): if yes: fileSend.write(fileData[:len(fileData) / 2]) fileSend.write(fileData[len(fileData) / 2:]) fileSend.close() else: raise "TransferDeclined" def failed(): raise "TransferError" d.addCallback(accepted) d.addErrback(failed) # Let the request get pushed to client1 self._loop(10) # Receive the file def finished(data): self.gotFile = (data == fileData) fileBuffer = msn.StringBuffer(finished) fileReceive = self.client1.fileReceive self.failUnless((fileReceive.filename == "myfile.txt" and fileReceive.filesize == len(fileData)), "Filename or length wrong.") fileReceive.accept(fileBuffer) # Lets transfer!! self._loop(10) self.failUnless((self.gotFile), "Failed to transfer file")
def testAvatars(self): self.gotAvatar = False # Set up the avatar for client1 imageData = self._generateData() self.client1.msnobj = msn.MSNObject() self.client1.msnobj.setData('*****@*****.**', lambda: imageData) self.client1.msnobj.makeText() # Make client2 request the avatar def avatarCallback((data, )): self.gotAvatar = (data == imageData) msnContact = msn.MSNContact(userHandle='*****@*****.**', msnobj=self.client1.msnobj) d = self.client2.sendAvatarRequest(msnContact) d.addCallback(avatarCallback) # Let them do their thing self._loop(10) # Check that client2 got the avatar self.failUnless((self.gotAvatar), "Failed to transfer avatar")