summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozdevice/tests/sut_push.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_push.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_push.py')
-rw-r--r--testing/mozbase/mozdevice/tests/sut_push.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/testing/mozbase/mozdevice/tests/sut_push.py b/testing/mozbase/mozdevice/tests/sut_push.py
new file mode 100644
index 000000000..023d5315c
--- /dev/null
+++ b/testing/mozbase/mozdevice/tests/sut_push.py
@@ -0,0 +1,88 @@
+from sut import MockAgent
+import mozfile
+import mozdevice
+import logging
+import unittest
+import hashlib
+import tempfile
+import os
+
+
+class PushTest(unittest.TestCase):
+
+ def test_push(self):
+ pushfile = "1234ABCD"
+ mdsum = hashlib.md5()
+ mdsum.update(pushfile)
+ expectedResponse = mdsum.hexdigest()
+
+ # (good response, no exception), (bad response, exception)
+ for response in [(expectedResponse, False), ("BADHASH", True)]:
+ cmd = "push /mnt/sdcard/foobar %s\r\n%s" % (len(pushfile), pushfile)
+ a = MockAgent(self, commands=[("isdir /mnt/sdcard", "TRUE"),
+ (cmd, response[0])])
+ exceptionThrown = False
+ with tempfile.NamedTemporaryFile() as f:
+ try:
+ f.write(pushfile)
+ f.flush()
+ d = mozdevice.DroidSUT("127.0.0.1", port=a.port)
+ d.pushFile(f.name, '/mnt/sdcard/foobar')
+ except mozdevice.DMError:
+ exceptionThrown = True
+ self.assertEqual(exceptionThrown, response[1])
+ a.wait()
+
+ def test_push_dir(self):
+ pushfile = "1234ABCD"
+ mdsum = hashlib.md5()
+ mdsum.update(pushfile)
+ expectedFileResponse = mdsum.hexdigest()
+
+ tempdir = tempfile.mkdtemp()
+ self.addCleanup(mozfile.remove, tempdir)
+ complex_path = os.path.join(tempdir, "baz")
+ os.mkdir(complex_path)
+ f = tempfile.NamedTemporaryFile(dir=complex_path)
+ f.write(pushfile)
+ f.flush()
+
+ subTests = [{'cmds': [("isdir /mnt/sdcard/baz", "TRUE"),
+ ("push /mnt/sdcard/baz/%s %s\r\n%s" %
+ (os.path.basename(f.name), len(pushfile),
+ pushfile),
+ expectedFileResponse)],
+ 'expectException': False},
+ {'cmds': [("isdir /mnt/sdcard/baz", "TRUE"),
+ ("push /mnt/sdcard/baz/%s %s\r\n%s" %
+ (os.path.basename(f.name), len(pushfile),
+ pushfile),
+ "BADHASH")],
+ 'expectException': True},
+ {'cmds': [("isdir /mnt/sdcard/baz", "FALSE"),
+ ('info os', 'android'),
+ ("isdir /mnt", "FALSE"),
+ ("mkdr /mnt",
+ "##AGENT-WARNING## Could not create the directory /mnt")],
+ 'expectException': True},
+
+ ]
+
+ for subTest in subTests:
+ a = MockAgent(self, commands=subTest['cmds'])
+
+ exceptionThrown = False
+ try:
+ d = mozdevice.DroidSUT("127.0.0.1", port=a.port,
+ logLevel=logging.DEBUG)
+ d.pushDir(tempdir, "/mnt/sdcard")
+ except mozdevice.DMError:
+ exceptionThrown = True
+ self.assertEqual(exceptionThrown, subTest['expectException'])
+
+ a.wait()
+
+ # FIXME: delete directory when done
+
+if __name__ == '__main__':
+ unittest.main()