|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 import hashlib |
|
6 import os |
|
7 import posixpath |
|
8 |
|
9 from dmunit import DeviceManagerTestCase |
|
10 from mozdevice.devicemanager import DMError |
|
11 |
|
12 class PullTestCase(DeviceManagerTestCase): |
|
13 |
|
14 def runTest(self): |
|
15 """Tests the "pull" command with a binary file. |
|
16 """ |
|
17 orig = hashlib.md5() |
|
18 new = hashlib.md5() |
|
19 local_test_file = os.path.join('test-files', 'mybinary.zip') |
|
20 orig.update(file(local_test_file, 'r').read()) |
|
21 |
|
22 testroot = self.dm.getDeviceRoot() |
|
23 remote_test_file = posixpath.join(testroot, 'mybinary.zip') |
|
24 self.dm.removeFile(remote_test_file) |
|
25 self.dm.pushFile(local_test_file, remote_test_file) |
|
26 new.update(self.dm.pullFile(remote_test_file)) |
|
27 # Use hexdigest() instead of digest() since values are printed |
|
28 # if assert fails |
|
29 self.assertEqual(orig.hexdigest(), new.hexdigest()) |
|
30 |
|
31 remote_missing_file = posixpath.join(testroot, 'doesnotexist') |
|
32 self.dm.removeFile(remote_missing_file) # Just to be sure |
|
33 self.assertRaises(DMError, self.dm.pullFile, remote_missing_file) |