from twisted.python import log
# System imports
-import sys
+import sys, random
# Local imports
import msnw
+import msn
# Settings
# Loops with a timeout
self.done = False
self.timeout = reactor.callLater(timeout, self.failed, "Timeout: " + failMsg)
- while self.done != cond and not self.done:
- reactor.iterate(0.1)
+ if cond == True:
+ while not self.done:
+ reactor.iterate(0.1)
+ else:
+ while self.done != cond:
+ reactor.iterate(0.1)
try:
self.timeout.cancel()
except (error.AlreadyCancelled, error.AlreadyCalled):
self.failUnless((self.user2.message == (USER1, "Hi user2")), "Failed to transfer message.")
# testMessageExchange.skip = "True"
- def testFileTransfer(self):
+ def testFileSend(self):
+ if raw_input("\n\nALERT!!!\n\nPlease connect to account %s and accept the file transfer from %s. When you have received the complete file, send a message back to the client to signal success.\nType ok when you are ready: " % (USER2, USER1)).lower() != "ok":
+ raise unittest.SkipTest("User didn't type 'ok'")
+
data = "Testing 123\r\n" * 5000
def accepted((yes,)):
if yes:
def gotFileSend((fileSend, d)):
self.fileSend = fileSend
d.addCallbacks(accepted, failed)
- if raw_input("\n\nALERT!!!\n\nPlease connect to account %s and accept the file transfer from %s. When you have received the complete file, send a message back to the client to signal success.\nType ok when you are ready: " % (USER2, USER1)).lower() != "ok":
- print "TEST SKIPPED!!!"
- return
+
self.doLogins(both=False)
self.doPurgeContacts(both=False)
self.doAddContacts(both=False)
d = self.user1.sendFile(USER2, "myfile.txt", len(data))
d.addCallback(gotFileSend)
self.loop("Sending file.", cond="GOTMESSAGE", timeout=60*60)
+# testFileSend.skip = "True"
+
+ def testFileReceive(self):
+ if raw_input("\n\nALERT!!!\n\nPlease connect to account %s and send a file transfer to %s.\nType ok when you are ready: " % (USER2, USER1)).lower() != "ok":
+ raise unittest.SkipTest("User didn't type 'ok'")
+
+ def fileFinished(data):
+ #filename = "/tmp/msn" + str(random.randint(1000, 9999)) + ".dat"
+ filename = "/tmp/MSNFILE_" + self.fileReceive.filename
+ f = open(filename, "w")
+ f.write(data)
+ f.close()
+ print "Got file!", filename
+ # Terminate the loop in a little, let them send the BYE before
+ # we drop the connection
+ def wait():
+ self.done = "GOTFILE"
+ reactor.callLater(5, wait)
+
+ def gotFileReceive(fileReceive):
+ buffer = msn.StringBuffer(fileFinished)
+ self.fileReceive = fileReceive
+ self.fileReceive.accept(buffer)
+
+ self.doLogins(both=False)
+ self.user1.gotFileReceive = gotFileReceive
+ self.doPurgeContacts(both=False)
+ self.doAddContacts(both=False)
+ self.loop("Receiving file.", cond="GOTFILE", timeout=60*60)
+# testFileReceive.skip = "True"