forked from mhluongo/amazon-cloud-drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
194 lines (152 loc) · 5.82 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
#
# Copyright (c) 2011 anatanokeitai.com(sakurai_youhei)
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# The Software shall be used for *YOUNGER* than you, not *OLDER*.
#
import sys
import unittest
from cStringIO import StringIO
#from ConfigParser import SafeConfigParser
import time
import xml.dom.minidom
import pyacd
pyacd.debug_level=2
if len(sys.argv)!=3:
sys.stderr.write("usage: ./test.py email password")
sys.exit(2)
email=sys.argv[1]
password=sys.argv[2]
print "*** Inputs are here ***"
print "email:",email
print "password:",password
print "*"*20
print ""
session=None
class AuthTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testLogin(self):
global session
session=pyacd.login(email,password)
self.assertTrue(session.is_valid(),"invalid session %s"%session)
self.assertTrue(session.is_logged_in(),"not logined %s"%session)
self.assertNotEqual(session.username,None,"username is None %s"%session)
self.assertNotEqual(session.customer_id,None,"customer_id is None %s"%session)
#sys.stderr.write(str(session))
"""
def testLoginWithNoneEmail(self):
global session
try:
session=pyacd.login(None,password)
except TypeError,e:
pass
def testLoginWithNonePassword(self):
global session
try:
session=pyacd.login(email,None)
except TypeError,e:
pass
def testLoginWithNoneArgs(self):
global session
try:
session=pyacd.login(None,None,None)
except TypeError,e:
pass
def testReloginWithSession(self):
global session
session=pyacd.login(session=session)
self.assertTrue(session.is_valid(),"invalid session %s"%session)
self.assertTrue(session.is_logged_in(),"not logined %s"%session)
self.assertNotEqual(session.username,None,"username is None %s"%session)
self.assertNotEqual(session.customer_id,None,"customer_id is None %s"%session)
"""
class ApiTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testUserStorage(self):
user_storage = pyacd.api.get_user_storage()
self.assertEqual(user_storage.total_space,user_storage.
used_space+user_storage.free_space,"total /= used+free %s"%user_storage)
#sys.stderr.write(str(user_storage))
def testSubscriptionProblem(self):
subscription_problem=pyacd.api.get_subscription_problem()
#sys.stderr.write(str(subscription_problem))
def testInfoByPathAndById(self):
info_by_path=pyacd.api.get_info_by_path("/")
#sys.stderr.write(str(info_by_path))
info_by_id=pyacd.api.get_info_by_id(info_by_path.object_id)
#sys.stderr.write(str(info_by_path))
self.assertEqual(info_by_path.name,info_by_id.name,"different from byPath(%s) and byId(%s)"%
(info_by_path,info_by_id))
def testListById(self):
info=pyacd.api.get_info_by_path("/")
pyacd.api.list_by_id(info.object_id)
def testFolder_Create_Rename_Copy_Recycle_Remove(self):
root=pyacd.api.get_info_by_path("/")
old_name="create_%d"%int(time.time())
new_name=old_name.replace("create","rename")
# folder1 create(old_name) -> rename(new_name)
folder1=pyacd.api.create_by_id(root.object_id,old_name)
pyacd.api.move_by_id(folder1.object_id,root.object_id,new_name)
# folder2 create(old_name) -> copy to new_name/ move to new_name/
folder2=pyacd.api.create_by_id(root.object_id,old_name)
pyacd.api.copy_bulk_by_id(folder1.object_id,[folder2.object_id,])
pyacd.api.move_bulk_by_id(folder1.object_id,[folder2.object_id,])
# folder1 recycle -> remove
pyacd.api.recycle_bulk_by_id([folder1.object_id,])
pyacd.api.remove_bulk_by_id([folder1.object_id,])
def testEmptyRecycleBin(self):
pyacd.api.empty_recycle_bin()
def testFile_Create_Upload_Download(self):
filename = "test_%d.txt"%int(time.time())
filedata = "12345"
# file1 create
file1 = pyacd.api.create_by_path("/",filename)
# get upload_url
upload_url = pyacd.api.get_upload_url_by_id(file1.object_id,len(filedata))
storage_key=upload_url.storage_key
object_id=upload_url.object_id
end_point=upload_url.http_request.end_point
parameters=upload_url.http_request.parameters
# upload file
pyacd.api.upload(end_point,parameters,filename,filedata)
# completeing file
pyacd.api.complete_file_upload_by_id(object_id,storage_key)
# download file
download_data=pyacd.api.download_by_id(object_id)
self.assertEqual(filedata,download_data,"different from upload and download")
def main():
suites=[]
suites.append(unittest.TestLoader().loadTestsFromTestCase(AuthTest))
suites.append(unittest.TestLoader().loadTestsFromTestCase(ApiTest))
runner = unittest.TextTestRunner(verbosity=2)
for s in suites:
runner.run(s)
# suite=unittest.TestSuite(suites)
# runner.run(suite)
if __name__=="__main__":
main()