2 In order to test the document_ftp functionality
4 I open the 8021 port and see for ftp presence there
6 !python {model: ir.attachment}: |
7 from document_ftp import test_easyftp as te
8 ftp = te.get_plain_ftp(timeout=2.0)
9 assert ftp.sock and (ftp.lastresp == '220'), ftp.lastresp
12 I read the list of databases at port 8021 and confirm our db is
15 !python {model: ir.attachment}: |
16 from document_ftp import test_easyftp as te
17 ftp = te.get_ftp_login(cr, uid, self)
18 assert cr.dbname in ftp.nlst("/")
21 I try to locate the default "Documents" folder in the db.
23 !python {model: ir.attachment}: |
24 from document_ftp import test_easyftp as te
25 ftp = te.get_ftp_login(cr, uid, self)
29 I create a "test.txt" file at the server (directly). The file
30 should have the "abcd" content
32 !python {model: ir.attachment}: |
33 from document_ftp import test_easyftp as te
34 from cStringIO import StringIO
35 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
36 fdata = StringIO('abcd')
37 ftp.storbinary('STOR test.txt', fdata)
40 I look for the "test.txt" file at the server
42 !python {model: ir.attachment}: |
43 from document_ftp import test_easyftp as te
44 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
45 assert ftp.nlst("test.txt") == ['test.txt']
48 I check that the content of "test.txt" is "abcd"
50 !python {model: ir.attachment}: |
51 from document_ftp import test_easyftp as te
52 from cStringIO import StringIO
53 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
54 gotdata = te.get_ftp_fulldata(ftp, "test.txt")
56 assert gotdata == 'abcd', 'Data: %r' % gotdata
58 I append the string 'defgh' to "test.txt"
60 !python {model: ir.attachment}: |
61 from document_ftp import test_easyftp as te
62 from cStringIO import StringIO
63 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
64 fdata = StringIO('defgh')
65 ftp.storbinary('APPE test.txt', fdata)
68 I check that the content of "text.txt" is 'abcddefgh'
70 !python {model: ir.attachment}: |
71 from document_ftp import test_easyftp as te
72 from cStringIO import StringIO
73 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
74 gotdata = te.get_ftp_fulldata(ftp, "test.txt")
76 assert gotdata == 'abcddefgh', 'Data: %r' % gotdata
78 I try to cd into an non-existing folder 'Not-This'
80 !python {model: ir.attachment}: |
81 from document_ftp import test_easyftp as te
83 ftp = te.get_ftp_login(cr, uid, self)
86 assert False, "We should't be able to change here"
87 except ftplib.error_perm:
91 assert err.errno == 2, err.errno
94 I create a "test2.txt" file through FTP.
96 !python {model: ir.attachment}: |
97 from document_ftp import test_easyftp as te
98 from cStringIO import StringIO
99 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
100 fdata = StringIO('abcd')
101 ftp.storbinary('STOR test2.txt', fdata)
104 I look for the "test2.txt" file at the server
106 !python {model: ir.attachment }: |
107 ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
110 I delete the "test2.txt" file using FTP.
112 !python {model: ir.attachment}: |
113 from document_ftp import test_easyftp as te
114 from cStringIO import StringIO
115 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
116 ftp.delete('test2.txt')
119 I check at the server that test2.txt is deleted
121 !python {model: ir.attachment }: |
122 ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
125 I create a test2.txt file again.
127 !python {model: ir.attachment}: |
128 from document_ftp import test_easyftp as te
129 from cStringIO import StringIO
130 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
131 fdata = StringIO('abcd')
132 ftp.storbinary('STOR test2.txt', fdata)
135 I delete the test2.txt from the server (RPC).
137 !delete { model: ir.attachment, id:, search: "[('name','=','test2.txt')]" }
139 I also commit, because ftp would run in a different transaction.
141 !python {model: ir.attachment}: |
144 I check through FTP that test2.txt does not appear.
146 !python {model: ir.attachment}: |
147 from document_ftp import test_easyftp as te
149 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
151 nlst_result = ftp.nlst("test2.txt")
152 except ftplib.error_perm: # 550 error: 'path not exists'
154 assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result
157 I create a "test-name.txt" file
159 !python {model: ir.attachment}: |
160 from document_ftp import test_easyftp as te
161 from cStringIO import StringIO
162 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
163 fdata = StringIO('abcd')
164 ftp.storbinary('STOR test-name.txt', fdata)
167 I rename the "test-name.txt" file through ftp.
169 !python {model: ir.attachment}: |
170 from document_ftp import test_easyftp as te
171 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
172 ftp.rename("test-name.txt", "test-renamed.txt")
175 I check that test-name.txt has been renamed.
177 !python {model: ir.attachment}: |
178 from document_ftp import test_easyftp as te
179 from ftplib import error_perm
180 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
182 res = ftp.nlst("test-name.txt")
183 assert res == [], "File has not been renamed!"
184 except error_perm, e:
186 assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
189 I create a new folder 'Test-Folder2' through FTP
191 !python {model: ir.attachment}: |
192 from document_ftp import test_easyftp as te
193 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
194 ftp.mkd("Test-Folder2")
197 I create a file 'test3.txt' at the 'Test-Folder2'
199 !python {model: ir.attachment}: |
200 from document_ftp import test_easyftp as te
201 from cStringIO import StringIO
202 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
203 fdata = StringIO('abcd')
204 ftp.storbinary('STOR test3.txt', fdata)
207 I try to retrieve test3.txt
209 !python {model: ir.attachment}: |
210 from document_ftp import test_easyftp as te
211 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
212 assert ftp.nlst("test3.txt") == ['test3.txt'], "File test3.txt is not there!"
215 I create a new folder, 'Test-Folder3', through FTP
216 I try to move test3.txt to 'Test-Folder3'
218 !python {model: ir.attachment}: |
219 from document_ftp import test_easyftp as te
220 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
221 ftp.mkd("Test-Folder3")
225 I remove the 'Test-Folder3'
227 !python {model: ir.attachment}: |
228 from document_ftp import test_easyftp as te
229 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
230 ftp.rmd("Test-Folder3")
233 I check that test3.txt is removed.
235 I create 200 files through FTP
237 !python {model: ir.attachment}: |
238 from document_ftp import test_easyftp as te
239 from cStringIO import StringIO
240 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
241 fdata = StringIO('abcd')
243 for i in range(0, 200):
245 ftp.storbinary('STOR test-name%s.txt' %i, fdata)
248 I list the 200 files, check speed
250 !python {model: ir.attachment}: |
251 from document_ftp import test_easyftp as te
252 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
254 assert len(ftp.nlst()) >= 200, "We haven't managed to store 200 files!"
256 I read the 200 files, check speed
259 I move the 200 files to 'Test-Folder2'
263 I delete the 200 files
265 !python {model: ir.attachment}: |
266 from document_ftp import test_easyftp as te
267 from cStringIO import StringIO
268 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
270 ftp.delete('test3.txt')
271 for i in range(0, 200):
272 ftp.delete('test-name%s.txt' %i)
276 I delete the "test.txt" and "test-renamed.txt" file
278 !python {model: ir.attachment}: |
279 from document_ftp import test_easyftp as te
280 from cStringIO import StringIO
281 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
283 ftp.delete('test.txt')
284 ftp.delete('test-renamed.txt')
288 I remove the 'Test-Folder2'
290 !python {model: ir.attachment}: |
291 from document_ftp import test_easyftp as te
292 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
293 ftp.rmd("Test-Folder2")