[FIX]: Remove dir and File from yaml of document_ftp module.
[odoo/odoo.git] / addons / document_ftp / test / document_ftp_test2.yml
1 -
2     In order to test the document_ftp functionality
3 -
4     I open the 8021 port and see for ftp presence there
5 -
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
10         ftp.close()
11 -
12     I read the list of databases at port 8021 and confirm our db is
13     there
14 -
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("/")
19         ftp.close()
20 -
21     I try to locate the default "Documents" folder in the db.
22 -
23     !python {model: ir.attachment}: |
24         from document_ftp import test_easyftp as te
25         ftp = te.get_ftp_login(cr, uid, self)
26         ftp.cwd('Documents')
27         ftp.close()
28 -
29     I create a "test.txt" file at the server (directly). The file
30     should have the "abcd" content
31 -
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)
38         ftp.close()
39 -
40     I look for the "test.txt" file at the server
41 -
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']
46         ftp.close()
47 -
48     I check that the content of "test.txt" is "abcd"
49 -
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")
55         ftp.close()
56         assert gotdata == 'abcd', 'Data: %r' % gotdata
57 -
58     I append the string 'defgh' to "test.txt"
59 -
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)
66         ftp.close()
67 -
68     I check that the content of "text.txt" is 'abcddefgh'
69 -
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")
75         ftp.close()
76         assert gotdata == 'abcddefgh', 'Data: %r' % gotdata
77 -
78     I try to cd into an non-existing folder 'Not-This'
79 -
80     !python {model: ir.attachment}: |
81         from document_ftp import test_easyftp as te
82         import ftplib
83         ftp = te.get_ftp_login(cr, uid, self)
84         try:
85             ftp.cwd('/Not-This')
86             assert False, "We should't be able to change here"
87         except ftplib.error_perm:
88             pass
89         except OSError, err:
90             ftp.close()
91             assert err.errno == 2, err.errno
92         ftp.close()
93 -
94     I create a "test2.txt" file through FTP.
95 -
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)
102         ftp.close()
103 -
104     I look for the "test2.txt" file at the server
105 -
106     !python {model: ir.attachment }: |
107         ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
108         assert ids
109 -
110     I delete the "test2.txt" file using FTP.
111 -
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')
117         ftp.close()
118 -
119     I check at the server that test2.txt is deleted
120 -
121     !python {model: ir.attachment }: |
122         ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
123         assert not ids
124 -
125     I create a test2.txt file again.
126 -
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)
133         ftp.close()
134 -
135     I delete the test2.txt from the server (RPC).
136 -
137     !delete { model: ir.attachment, id:,  search: "[('name','=','test2.txt')]" }
138 -
139     I also commit, because ftp would run in a different transaction.
140 -
141     !python {model: ir.attachment}: |
142         cr.commit()
143 -
144     I check through FTP that test2.txt does not appear.
145 -
146     !python {model: ir.attachment}: |
147         from document_ftp import test_easyftp as te
148         import ftplib
149         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
150         try:
151             nlst_result = ftp.nlst("test2.txt")
152         except ftplib.error_perm: # 550 error: 'path not exists'
153             nlst_result = []
154         assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result
155         ftp.close()
156 -
157     I create a "test-name.txt" file
158 -
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)
165         ftp.close()
166 -
167     I rename the "test-name.txt" file through ftp.
168 -
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")
173         ftp.close()
174 -
175     I check that test-name.txt has been renamed.
176 -
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')
181         try:
182             res = ftp.nlst("test-name.txt")
183             assert res == [], "File has not been renamed!"
184         except error_perm, e:
185             pass
186         assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
187         ftp.close()
188 -
189     I create a new folder 'Test-Folder2' through FTP
190 -
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")
195         ftp.close()
196 -
197     I create a file 'test3.txt' at the 'Test-Folder2'
198 -
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)
205         ftp.close()
206 -
207     I try to retrieve test3.txt
208 -
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!"
213         ftp.close()
214 -
215     I create a new folder, 'Test-Folder3', through FTP
216     I try to move test3.txt to 'Test-Folder3'
217 -
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")
222         ftp.close()
223         # TODO move
224 -
225     I remove the 'Test-Folder3'
226 -
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")
231         ftp.close()
232 -
233     I check that test3.txt is removed.
234 -
235     I create 200 files through FTP
236 -
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')
242         # TODO speed
243         for i in range(0, 200):
244             fdata.seek(0)
245             ftp.storbinary('STOR test-name%s.txt' %i, fdata)
246         ftp.close()
247 -
248     I list the 200 files, check speed
249 -
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')
253         # TODO speed
254         assert len(ftp.nlst()) >= 200, "We haven't managed to store 200 files!"
255 -
256     I read the 200 files, check speed
257     # TODO
258 -
259     I move the 200 files to 'Test-Folder2'
260     # TODO
261
262 -
263     I delete the 200 files
264 -
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')
269         # TODO speed
270         ftp.delete('test3.txt')
271         for i in range(0, 200):
272             ftp.delete('test-name%s.txt' %i)
273         ftp.close()
274  
275 -
276     I delete the "test.txt" and "test-renamed.txt" file        
277 -
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')
282         # TODO speed
283         ftp.delete('test.txt')
284         ftp.delete('test-renamed.txt')
285         ftp.close()  
286               
287 -
288     I remove the 'Test-Folder2'
289 -
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")
294         ftp.close()