+ def testFilesHappyPath(self):
+ fileData = self._generateData()
+ self.gotFile = False
+
+ # Send the file (client2->client1)
+ msnContact = msn.MSNContact(userHandle='foo1@bar.com', caps=msn.MSNContact.MSNC1)
+ fileSend, d = self.client2.sendFile(msnContact, "myfile.txt", len(fileData))
+ def accepted((yes,)):
+ if yes:
+ fileSend.write(fileData)
+ 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 testFilesHappyChunkedPath(self):
+ fileData = self._generateData()
+ self.gotFile = False
+
+ # Send the file (client2->client1)
+ msnContact = msn.MSNContact(userHandle='foo1@bar.com', 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 testTwoFilesSequential(self):
+ self.testFilesHappyPath()
+ self.testFilesHappyPath()
+
+ def testFilesDeclinePath(self):
+ fileData = self._generateData()
+ self.gotDecline = False
+
+ # Send the file (client2->client1)
+ msnContact = msn.MSNContact(userHandle='foo1@bar.com', 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.")
+