1414# limitations under the License.
1515
1616import unittest
17+ from zipfile import ZipFile
1718import json
19+ import os
20+ import random
1821from time import sleep
1922
2023from selenium .common .exceptions import NoSuchElementException
@@ -35,6 +38,10 @@ def setUp(self):
3538 def tearDown (self ):
3639 self .driver .quit ()
3740
41+ # remove zipped file from `test_pull_folder`
42+ if os .path .isfile (self .zipfilename ):
43+ os .remove (self .zipfilename )
44+
3845 def test_app_strings (self ):
3946 strings = self .driver .app_strings ()
4047 self .assertEqual (u'You can\' t wipe my data, you are a monkey!' , strings [u'monkey_wipe_data' ])
@@ -67,6 +74,25 @@ def test_push_file(self):
6774 data_ret = self .driver .pull_file ('data/local/tmp/test_push_file.txt' ).decode ('base64' )
6875 self .assertEqual (data , data_ret )
6976
77+ def test_pull_folder (self ):
78+ string_data = 'random string data %d' % random .randint (0 , 1000 )
79+ path = '/data/local/tmp'
80+ self .driver .push_file (path + '/1.txt' , string_data .encode ('base64' ))
81+ self .driver .push_file (path + '/2.txt' , string_data .encode ('base64' ))
82+ folder = self .driver .pull_folder (path )
83+
84+ # python doesn't have any functionality for unzipping streams
85+ # save temporary file, which will be deleted in `tearDown`
86+ self .zipfilename = 'folder_%d.zip' % random .randint (0 , 1000000 )
87+ file = open (self .zipfilename , "w" )
88+ file .write (folder .decode ('base64' , 'strict' ))
89+ file .close ()
90+
91+ with ZipFile (self .zipfilename , 'r' ) as myzip :
92+ # should find these. otherwise it will raise a `KeyError`
93+ myzip .read ('1.txt' )
94+ myzip .read ('2.txt' )
95+
7096 def test_complex_find (self ):
7197 # this only works with a three dimensional array like here.
7298 el = self .driver .complex_find ([[[2 , 'Ani' ]]])
0 commit comments