summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozdevice/tests/sut_fileMethods.py
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mozbase/mozdevice/tests/sut_fileMethods.py
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozbase/mozdevice/tests/sut_fileMethods.py')
-rw-r--r--testing/mozbase/mozdevice/tests/sut_fileMethods.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/mozbase/mozdevice/tests/sut_fileMethods.py b/testing/mozbase/mozdevice/tests/sut_fileMethods.py
new file mode 100644
index 000000000..142950a81
--- /dev/null
+++ b/testing/mozbase/mozdevice/tests/sut_fileMethods.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+
+import hashlib
+import mozdevice
+import logging
+import shutil
+import tempfile
+import unittest
+from sut import MockAgent
+
+
+class TestFileMethods(unittest.TestCase):
+ """ Class to test misc file methods """
+
+ content = "What is the answer to the life, universe and everything? 42"
+ h = hashlib.md5()
+ h.update(content)
+ temp_hash = h.hexdigest()
+
+ def test_validateFile(self):
+
+ with tempfile.NamedTemporaryFile() as f:
+ f.write(self.content)
+ f.flush()
+
+ # Test Valid Hashes
+ commands_valid = [("hash /sdcard/test/file", self.temp_hash)]
+
+ m = MockAgent(self, commands=commands_valid)
+ d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
+ self.assertTrue(d.validateFile('/sdcard/test/file', f.name))
+
+ # Test invalid hashes
+ commands_invalid = [("hash /sdcard/test/file", "0this0hash0is0completely0invalid")]
+
+ m = MockAgent(self, commands=commands_invalid)
+ d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
+ self.assertFalse(d.validateFile('/sdcard/test/file', f.name))
+
+ def test_getFile(self):
+
+ fname = "/mnt/sdcard/file"
+ commands = [("pull %s" % fname, "%s,%s\n%s" % (fname, len(self.content), self.content)),
+ ("hash %s" % fname, self.temp_hash)]
+
+ with tempfile.NamedTemporaryFile() as f:
+ m = MockAgent(self, commands=commands)
+ d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
+ # No error means success
+ self.assertEqual(None, d.getFile(fname, f.name))
+
+ def test_getDirectory(self):
+
+ fname = "/mnt/sdcard/file"
+ commands = [("isdir /mnt/sdcard", "TRUE"),
+ ("isdir /mnt/sdcard", "TRUE"),
+ ("cd /mnt/sdcard", ""),
+ ("ls", "file"),
+ ("isdir %s" % fname, "FALSE"),
+ ("pull %s" % fname, "%s,%s\n%s" % (fname, len(self.content), self.content)),
+ ("hash %s" % fname, self.temp_hash)]
+
+ tmpdir = tempfile.mkdtemp()
+ m = MockAgent(self, commands=commands)
+ d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
+ self.assertEqual(None, d.getDirectory("/mnt/sdcard", tmpdir))
+
+ # Cleanup
+ shutil.rmtree(tmpdir)
+
+if __name__ == '__main__':
+ unittest.main()