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 cr.rollback() # restart transaction to see changes (FTP-FS uses its own cursor)
108 ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
109 assert ids, "No test2.txt file found."
111 I delete the "test2.txt" file using FTP.
113 !python {model: ir.attachment}: |
114 from document_ftp import test_easyftp as te
115 from cStringIO import StringIO
116 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
117 ftp.delete('test2.txt')
120 I check at the server that test2.txt is deleted
122 !python {model: ir.attachment }: |
123 cr.rollback() # restart transaction to see changes (FTP-FS uses its own cursor)
124 ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
125 assert not ids, "test2.txt file can still be found."
127 I create a test2.txt file again.
129 !python {model: ir.attachment}: |
130 from document_ftp import test_easyftp as te
131 from cStringIO import StringIO
132 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
133 fdata = StringIO('abcd')
134 ftp.storbinary('STOR test2.txt', fdata)
136 cr.rollback() # restart transaction to see changes (FTP-FS uses its own cursor)
138 I delete the test2.txt from the server (RPC).
140 !delete { model: ir.attachment, id:, search: "[('name','=','test2.txt')]" }
142 I also commit, because ftp would run in a different transaction.
144 !python {model: ir.attachment}: |
147 I check through FTP that test2.txt does not appear.
149 !python {model: ir.attachment}: |
150 from document_ftp import test_easyftp as te
152 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
154 nlst_result = ftp.nlst("test2.txt")
155 except ftplib.error_perm: # 550 error: 'path not exists'
157 assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result
160 I create a "test-name.txt" file
162 !python {model: ir.attachment}: |
163 from document_ftp import test_easyftp as te
164 from cStringIO import StringIO
165 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
166 fdata = StringIO('abcd')
167 ftp.storbinary('STOR test-name.txt', fdata)
170 I rename the "test-name.txt" file through ftp.
172 !python {model: ir.attachment}: |
173 from document_ftp import test_easyftp as te
174 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
175 ftp.rename("test-name.txt", "test-renamed.txt")
178 I check that test-name.txt has been renamed.
180 !python {model: ir.attachment}: |
181 from document_ftp import test_easyftp as te
182 from ftplib import error_perm
183 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
185 res = ftp.nlst("test-name.txt")
186 assert res == [], "File has not been renamed!"
187 except error_perm, e:
189 assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
192 I create a new folder 'Test-Folder2' through FTP
194 !python {model: ir.attachment}: |
195 from document_ftp import test_easyftp as te
196 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
197 ftp.mkd("Test-Folder2")
200 I create a file 'test3.txt' at the 'Test-Folder2'
202 !python {model: ir.attachment}: |
203 from document_ftp import test_easyftp as te
204 from cStringIO import StringIO
205 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
206 fdata = StringIO('abcd')
207 ftp.storbinary('STOR test3.txt', fdata)
210 I try to retrieve test3.txt
212 !python {model: ir.attachment}: |
213 from document_ftp import test_easyftp as te
214 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
215 assert ftp.nlst("test3.txt") == ['test3.txt'], "File test3.txt is not there!"
218 I create a new folder, 'Test-Folder3', through FTP
219 I try to move test3.txt to 'Test-Folder3'
221 !python {model: ir.attachment}: |
222 from document_ftp import test_easyftp as te
223 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
224 ftp.mkd("Test-Folder3")
228 I remove the 'Test-Folder3'
230 !python {model: ir.attachment}: |
231 from document_ftp import test_easyftp as te
232 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
233 ftp.rmd("Test-Folder3")
236 I check that test3.txt is removed.
238 I create 5 files through FTP
240 !python {model: ir.attachment}: |
241 from document_ftp import test_easyftp as te
242 from cStringIO import StringIO
243 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
244 fdata = StringIO('abcd')
245 for i in range(0, 5):
247 ftp.storbinary('STOR test-name%s.txt' %i, fdata)
250 I list the 5 files, check speed
252 !python {model: ir.attachment}: |
253 from document_ftp import test_easyftp as te
254 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
255 assert len(ftp.nlst()) >= 5, "We haven't managed to store 5 files!"
257 I read the 5 files, check speed
259 I move the 5 files to 'Test-Folder2'
263 !python {model: ir.attachment}: |
264 from document_ftp import test_easyftp as te
265 from cStringIO import StringIO
266 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
267 ftp.delete('test3.txt')
268 for i in range(0, 5):
269 ftp.delete('test-name%s.txt' %i)
273 I delete the "test.txt" and "test-renamed.txt" file
275 !python {model: ir.attachment}: |
276 from document_ftp import test_easyftp as te
277 from cStringIO import StringIO
278 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
279 ftp.delete('test.txt')
280 ftp.delete('test-renamed.txt')
283 I remove the 'Test-Folder2'
285 !python {model: ir.attachment}: |
286 from document_ftp import test_easyftp as te
287 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
288 ftp.rmd("Test-Folder2")