michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import hashlib michael@0: import os michael@0: import posixpath michael@0: michael@0: from dmunit import DeviceManagerTestCase michael@0: from mozdevice.devicemanager import DMError michael@0: michael@0: class PullTestCase(DeviceManagerTestCase): michael@0: michael@0: def runTest(self): michael@0: """Tests the "pull" command with a binary file. michael@0: """ michael@0: orig = hashlib.md5() michael@0: new = hashlib.md5() michael@0: local_test_file = os.path.join('test-files', 'mybinary.zip') michael@0: orig.update(file(local_test_file, 'r').read()) michael@0: michael@0: testroot = self.dm.getDeviceRoot() michael@0: remote_test_file = posixpath.join(testroot, 'mybinary.zip') michael@0: self.dm.removeFile(remote_test_file) michael@0: self.dm.pushFile(local_test_file, remote_test_file) michael@0: new.update(self.dm.pullFile(remote_test_file)) michael@0: # Use hexdigest() instead of digest() since values are printed michael@0: # if assert fails michael@0: self.assertEqual(orig.hexdigest(), new.hexdigest()) michael@0: michael@0: remote_missing_file = posixpath.join(testroot, 'doesnotexist') michael@0: self.dm.removeFile(remote_missing_file) # Just to be sure michael@0: self.assertRaises(DMError, self.dm.pullFile, remote_missing_file)