|
1 from sut import MockAgent |
|
2 import mozdevice |
|
3 import mozlog |
|
4 import unittest |
|
5 import hashlib |
|
6 import tempfile |
|
7 import os |
|
8 |
|
9 class PullTest(unittest.TestCase): |
|
10 |
|
11 def test_pull_success(self): |
|
12 for count in [ 1, 4, 1024, 2048 ]: |
|
13 cheeseburgers = "" |
|
14 for i in range(count): |
|
15 cheeseburgers += "cheeseburgers" |
|
16 |
|
17 # pull file is kind of gross, make sure we can still execute commands after it's done |
|
18 remoteName = "/mnt/sdcard/cheeseburgers" |
|
19 a = MockAgent(self, commands = [("pull %s" % remoteName, |
|
20 "%s,%s\n%s" % (remoteName, |
|
21 len(cheeseburgers), |
|
22 cheeseburgers)), |
|
23 ("isdir /mnt/sdcard", "TRUE")]) |
|
24 |
|
25 d = mozdevice.DroidSUT("127.0.0.1", port=a.port, |
|
26 logLevel=mozlog.DEBUG) |
|
27 pulledData = d.pullFile("/mnt/sdcard/cheeseburgers") |
|
28 self.assertEqual(pulledData, cheeseburgers) |
|
29 d.dirExists('/mnt/sdcard') |
|
30 |
|
31 def test_pull_failure(self): |
|
32 |
|
33 # this test simulates only receiving a few bytes of what we expect |
|
34 # to be larger file |
|
35 remoteName = "/mnt/sdcard/cheeseburgers" |
|
36 a = MockAgent(self, commands = [("pull %s" % remoteName, |
|
37 "%s,15\n%s" % (remoteName, |
|
38 "cheeseburgh"))]) |
|
39 d = mozdevice.DroidSUT("127.0.0.1", port=a.port, |
|
40 logLevel=mozlog.DEBUG) |
|
41 exceptionThrown = False |
|
42 try: |
|
43 d.pullFile("/mnt/sdcard/cheeseburgers") |
|
44 except mozdevice.DMError: |
|
45 exceptionThrown = True |
|
46 self.assertTrue(exceptionThrown) |
|
47 |
|
48 if __name__ == '__main__': |
|
49 unittest.main() |
|
50 |
|
51 |