Document FTP: improve the tests
[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()
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         ftp = te.get_ftp_login(cr, uid, self)
73         try:
74             ftp.cwd('/Not-This')
75             assert False, "We should't be able to change here"
76         except OSError, err:
77             assert err.errno == 2, err.errno
78 -
79     I create a "test2.txt" file through FTP.
80 -
81     !python {model: ir.attachment}: |
82         from document_ftp import test_easyftp as te
83         from cStringIO import StringIO
84         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
85         fdata = StringIO('abcd')
86         ftp.storbinary('STOR test2.txt', fdata)
87 -
88     I look for the "test2.txt" file at the server
89 -
90     !python {model: ir.attachment }: |
91         ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
92         assert ids
93 -
94     I delete the "test2.txt" file using 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         ftp.delete('test2.txt')
101 -
102     I check at the server that test2.txt is deleted
103 -
104     !python {model: ir.attachment }: |
105         ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
106         assert not ids
107 -
108     I create a test2.txt file again.
109 -
110     !python {model: ir.attachment}: |
111         from document_ftp import test_easyftp as te
112         from cStringIO import StringIO
113         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
114         fdata = StringIO('abcd')
115         ftp.storbinary('STOR test2.txt', fdata)
116 -
117     I delete the test2.txt from the server (RPC).
118 -
119     !delete { model: ir.attachment, id:,  search: "[('name','=','test2.txt')]" }
120 -
121     I check through FTP that test2.txt does not appear.
122 -
123     !python {model: ir.attachment}: |
124         from document_ftp import test_easyftp as te
125         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
126         assert ftp.nlst("test2.txt") == []
127 -
128     I create a "test-name.txt" file
129 -
130     !python {model: ir.attachment}: |
131         from document_ftp import test_easyftp as te
132         from cStringIO import StringIO
133         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
134         fdata = StringIO('abcd')
135         ftp.storbinary('STOR test-name.txt', fdata)
136 -
137     I rename the "test-name.txt" file through ftp.
138 -
139     !python {model: ir.attachment}: |
140         from document_ftp import test_easyftp as te
141         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
142         ftp.rename("test-name.txt", "test-renamed.txt")
143 -
144     I check that test-name.txt has been renamed.
145 -
146     !python {model: ir.attachment}: |
147         from document_ftp import test_easyftp as te
148         from ftplib import error_perm
149         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
150         try:
151             res = ftp.nlst("test-name.txt")
152             assert res == []
153         except error_perm, e:
154             pass
155         assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
156 -
157     I create a new folder 'Test-Folder2' through FTP
158 -
159     !python {model: ir.attachment}: |
160         from document_ftp import test_easyftp as te
161         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
162         ftp.mkd("Test-Folder2")
163 -
164     I create a file 'test3.txt' at the 'Test-Folder2'
165 -
166     !python {model: ir.attachment}: |
167         from document_ftp import test_easyftp as te
168         from cStringIO import StringIO
169         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
170         fdata = StringIO('abcd')
171         ftp.storbinary('STOR test3.txt', fdata)
172 -
173     I try to retrieve test3.txt
174 -
175     !python {model: ir.attachment}: |
176         from document_ftp import test_easyftp as te
177         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
178         assert ftp.nlst("test3.txt") == ['test3.txt']
179 -
180     I create a new folder, 'Test-Folder3', through FTP
181     I try to move test3.txt to 'Test-Folder3'
182 -
183     !python {model: ir.attachment}: |
184         from document_ftp import test_easyftp as te
185         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
186         ftp.mkd("Test-Folder2")
187         # TODO move
188 -
189     I remove the 'Test-Folder3'
190 -
191     I check that test3.txt is removed.
192 -
193     I create 1000 files through FTP
194 -
195     !python {model: ir.attachment}: |
196         from document_ftp import test_easyftp as te
197         from cStringIO import StringIO
198         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
199         fdata = StringIO('abcd')
200         # TODO speed
201         for i in range(0, 1000):
202             fdata.seek(0)
203             ftp.storbinary('STOR test-name%s.txt' %i, fdata)
204 -
205     I list the 1000 files, check speed
206 -
207     !python {model: ir.attachment}: |
208         from document_ftp import test_easyftp as te
209         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
210         # TODO speed
211         assert len(ftp.nlst()) > 1000
212 -
213     I read the 1000 files, check speed
214     # TODO
215 -
216     I move the 1000 files to 'Test-Folder2'
217     # TODO
218 -