Doc ftp: improve yaml tests, assert messages
[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 -
11     I read the list of databases at port 8021 and confirm our db is
12     there
13 -
14     !python {model: ir.attachment}: |
15         from document_ftp import test_easyftp as te
16         ftp = te.get_ftp_login(cr, uid, self)
17         assert cr.dbname in ftp.nlst("/")
18 -
19     I try to locate the default "Documents" folder in the db.
20 -
21     !python {model: ir.attachment}: |
22         from document_ftp import test_easyftp as te
23         ftp = te.get_ftp_login(cr, uid, self)
24         ftp.cwd('Documents')
25 -
26     I create a "test.txt" file at the server (directly). The file
27     should have the "abcd" content
28 -
29     !python {model: ir.attachment}: |
30         from document_ftp import test_easyftp as te
31         from cStringIO import StringIO
32         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
33         fdata = StringIO('abcd')
34         ftp.storbinary('STOR test.txt', fdata)
35 -
36     I look for the "test.txt" file at the server
37 -
38     !python {model: ir.attachment}: |
39         from document_ftp import test_easyftp as te
40         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
41         assert ftp.nlst("test.txt") == ['test.txt']
42 -
43     I check that the content of "test.txt" is "abcd"
44 -
45     !python {model: ir.attachment}: |
46         from document_ftp import test_easyftp as te
47         from cStringIO import StringIO
48         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
49         assert te.get_ftp_fulldata(ftp, "test.txt") == 'abcd'
50 -
51     I append the string 'defgh' into "test.txt"
52 -
53     !python {model: ir.attachment}: |
54         from document_ftp import test_easyftp as te
55         from cStringIO import StringIO
56         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
57         fdata = StringIO('defgh')
58         ftp.storbinary('APPE test.txt', fdata)
59 -
60     I check that the content of "text.txt" is 'abcddefgh'
61 -
62     !python {model: ir.attachment}: |
63         from document_ftp import test_easyftp as te
64         from cStringIO import StringIO
65         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
66         assert te.get_ftp_fulldata(ftp, "test.txt") == 'abcddefgh'
67 -
68     I try to cd into an non-existing folder 'Not-This'
69 -
70     !python {model: ir.attachment}: |
71         from document_ftp import test_easyftp as te
72         import ftplib
73         ftp = te.get_ftp_login(cr, uid, self)
74         try:
75             ftp.cwd('/Not-This')
76             assert False, "We should't be able to change here"
77         except ftplib.error_perm:
78             pass
79         except OSError, err:
80             assert err.errno == 2, err.errno
81 -
82     I create a "test2.txt" file through FTP.
83 -
84     !python {model: ir.attachment}: |
85         from document_ftp import test_easyftp as te
86         from cStringIO import StringIO
87         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
88         fdata = StringIO('abcd')
89         ftp.storbinary('STOR test2.txt', fdata)
90 -
91     I look for the "test2.txt" file at the server
92 -
93     !python {model: ir.attachment }: |
94         ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
95         assert ids
96 -
97     I delete the "test2.txt" file using FTP.
98 -
99     !python {model: ir.attachment}: |
100         from document_ftp import test_easyftp as te
101         from cStringIO import StringIO
102         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
103         ftp.delete('test2.txt')
104 -
105     I check at the server that test2.txt is deleted
106 -
107     !python {model: ir.attachment }: |
108         ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
109         assert not ids
110 -
111     I create a test2.txt file again.
112 -
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         fdata = StringIO('abcd')
118         ftp.storbinary('STOR test2.txt', fdata)
119 -
120     I delete the test2.txt from the server (RPC).
121 -
122     !delete { model: ir.attachment, id:,  search: "[('name','=','test2.txt')]" }
123 -
124     I also commit, because ftp would run in a different transaction.
125 -
126     !python {model: ir.attachment}: |
127         cr.commit()
128 -
129     I check through FTP that test2.txt does not appear.
130 -
131     !python {model: ir.attachment}: |
132         from document_ftp import test_easyftp as te
133         import ftplib
134         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
135         try:
136             nlst_result = ftp.nlst("test2.txt")
137         except ftplib.error_perm: # 550 error: 'path not exists'
138             nlst_result = []
139         assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result
140 -
141     I create a "test-name.txt" file
142 -
143     !python {model: ir.attachment}: |
144         from document_ftp import test_easyftp as te
145         from cStringIO import StringIO
146         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
147         fdata = StringIO('abcd')
148         ftp.storbinary('STOR test-name.txt', fdata)
149 -
150     I rename the "test-name.txt" file through ftp.
151 -
152     !python {model: ir.attachment}: |
153         from document_ftp import test_easyftp as te
154         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
155         ftp.rename("test-name.txt", "test-renamed.txt")
156 -
157     I check that test-name.txt has been renamed.
158 -
159     !python {model: ir.attachment}: |
160         from document_ftp import test_easyftp as te
161         from ftplib import error_perm
162         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
163         try:
164             res = ftp.nlst("test-name.txt")
165             assert res == [], "File has not been renamed!"
166         except error_perm, e:
167             pass
168         assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
169 -
170     I create a new folder 'Test-Folder2' through FTP
171 -
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.mkd("Test-Folder2")
176 -
177     I create a file 'test3.txt' at the 'Test-Folder2'
178 -
179     !python {model: ir.attachment}: |
180         from document_ftp import test_easyftp as te
181         from cStringIO import StringIO
182         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
183         fdata = StringIO('abcd')
184         ftp.storbinary('STOR test3.txt', fdata)
185 -
186     I try to retrieve test3.txt
187 -
188     !python {model: ir.attachment}: |
189         from document_ftp import test_easyftp as te
190         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
191         assert ftp.nlst("test3.txt") == ['test3.txt'], "File test3.txt is not there!"
192 -
193     I create a new folder, 'Test-Folder3', through FTP
194     I try to move test3.txt to 'Test-Folder3'
195 -
196     !python {model: ir.attachment}: |
197         from document_ftp import test_easyftp as te
198         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
199         ftp.mkd("Test-Folder2")
200         # TODO move
201 -
202     I remove the 'Test-Folder3'
203 -
204     I check that test3.txt is removed.
205 -
206     I create 200 files through FTP
207 -
208     !python {model: ir.attachment}: |
209         from document_ftp import test_easyftp as te
210         from cStringIO import StringIO
211         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
212         fdata = StringIO('abcd')
213         # TODO speed
214         for i in range(0, 200):
215             fdata.seek(0)
216             ftp.storbinary('STOR test-name%s.txt' %i, fdata)
217 -
218     I list the 200 files, check speed
219 -
220     !python {model: ir.attachment}: |
221         from document_ftp import test_easyftp as te
222         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
223         # TODO speed
224         assert len(ftp.nlst()) >= 200, "We haven't managed to store 200 files!"
225 -
226     I read the 200 files, check speed
227     # TODO
228 -
229     I move the 200 files to 'Test-Folder2'
230     # TODO