1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozdevice/tests/sut_pull.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +from sut import MockAgent 1.5 +import mozdevice 1.6 +import mozlog 1.7 +import unittest 1.8 +import hashlib 1.9 +import tempfile 1.10 +import os 1.11 + 1.12 +class PullTest(unittest.TestCase): 1.13 + 1.14 + def test_pull_success(self): 1.15 + for count in [ 1, 4, 1024, 2048 ]: 1.16 + cheeseburgers = "" 1.17 + for i in range(count): 1.18 + cheeseburgers += "cheeseburgers" 1.19 + 1.20 + # pull file is kind of gross, make sure we can still execute commands after it's done 1.21 + remoteName = "/mnt/sdcard/cheeseburgers" 1.22 + a = MockAgent(self, commands = [("pull %s" % remoteName, 1.23 + "%s,%s\n%s" % (remoteName, 1.24 + len(cheeseburgers), 1.25 + cheeseburgers)), 1.26 + ("isdir /mnt/sdcard", "TRUE")]) 1.27 + 1.28 + d = mozdevice.DroidSUT("127.0.0.1", port=a.port, 1.29 + logLevel=mozlog.DEBUG) 1.30 + pulledData = d.pullFile("/mnt/sdcard/cheeseburgers") 1.31 + self.assertEqual(pulledData, cheeseburgers) 1.32 + d.dirExists('/mnt/sdcard') 1.33 + 1.34 + def test_pull_failure(self): 1.35 + 1.36 + # this test simulates only receiving a few bytes of what we expect 1.37 + # to be larger file 1.38 + remoteName = "/mnt/sdcard/cheeseburgers" 1.39 + a = MockAgent(self, commands = [("pull %s" % remoteName, 1.40 + "%s,15\n%s" % (remoteName, 1.41 + "cheeseburgh"))]) 1.42 + d = mozdevice.DroidSUT("127.0.0.1", port=a.port, 1.43 + logLevel=mozlog.DEBUG) 1.44 + exceptionThrown = False 1.45 + try: 1.46 + d.pullFile("/mnt/sdcard/cheeseburgers") 1.47 + except mozdevice.DMError: 1.48 + exceptionThrown = True 1.49 + self.assertTrue(exceptionThrown) 1.50 + 1.51 +if __name__ == '__main__': 1.52 + unittest.main() 1.53 + 1.54 +