|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # This Source Code Form is subject to the terms of the Mozilla Public |
|
5 # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
6 # You can obtain one at http://mozilla.org/MPL/2.0/. |
|
7 |
|
8 import mozdevice |
|
9 import mozlog |
|
10 import unittest |
|
11 from sut import MockAgent |
|
12 |
|
13 class MoveTreeTest(unittest.TestCase): |
|
14 def test_moveFile(self): |
|
15 commands = [('mv /mnt/sdcard/tests/test.txt /mnt/sdcard/tests/test1.txt', ''), |
|
16 ('isdir /mnt/sdcard/tests', 'TRUE'), |
|
17 ('cd /mnt/sdcard/tests', ''), |
|
18 ('ls', 'test1.txt'), |
|
19 ('isdir /mnt/sdcard/tests', 'TRUE'), |
|
20 ('cd /mnt/sdcard/tests', ''), |
|
21 ('ls', 'test1.txt')] |
|
22 |
|
23 m = MockAgent(self, commands=commands) |
|
24 d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) |
|
25 self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/test.txt', |
|
26 '/mnt/sdcard/tests/test1.txt')) |
|
27 self.assertFalse(d.fileExists('/mnt/sdcard/tests/test.txt')) |
|
28 self.assertTrue(d.fileExists('/mnt/sdcard/tests/test1.txt')) |
|
29 |
|
30 def test_moveDir(self): |
|
31 commands = [("mv /mnt/sdcard/tests/foo /mnt/sdcard/tests/bar", ""), |
|
32 ('isdir /mnt/sdcard/tests', 'TRUE'), |
|
33 ('cd /mnt/sdcard/tests', ''), |
|
34 ('ls', 'bar')] |
|
35 |
|
36 m = MockAgent(self, commands=commands) |
|
37 d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) |
|
38 self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/foo', |
|
39 '/mnt/sdcard/tests/bar')) |
|
40 self.assertTrue(d.fileExists('/mnt/sdcard/tests/bar')) |
|
41 |
|
42 def test_moveNonEmptyDir(self): |
|
43 commands = [('isdir /mnt/sdcard/tests/foo/bar', 'TRUE'), |
|
44 ('mv /mnt/sdcard/tests/foo /mnt/sdcard/tests/foo2', ''), |
|
45 ('isdir /mnt/sdcard/tests', 'TRUE'), |
|
46 ('cd /mnt/sdcard/tests', ''), |
|
47 ('ls', 'foo2'), |
|
48 ('isdir /mnt/sdcard/tests/foo2', 'TRUE'), |
|
49 ('cd /mnt/sdcard/tests/foo2', ''), |
|
50 ('ls', 'bar')] |
|
51 |
|
52 m = MockAgent(self, commands=commands) |
|
53 d = mozdevice.DroidSUT("127.0.0.1", port=m.port, |
|
54 logLevel=mozlog.DEBUG) |
|
55 |
|
56 self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar')) |
|
57 self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/foo', |
|
58 '/mnt/sdcard/tests/foo2')) |
|
59 self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2')) |
|
60 self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar')) |
|
61 |
|
62 if __name__ == "__main__": |
|
63 unittest.main() |