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
11 I read the list of databases at port 8021 and confirm our db is
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("/")
19 I try to locate the default "Documents" folder in the db.
21 !python {model: ir.attachment}: |
22 from document_ftp import test_easyftp as te
23 ftp = te.get_ftp_login(cr, uid, self)
26 I create a "test.txt" file at the server (directly). The file
27 should have the "abcd" content
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)
36 I look for the "test.txt" file at the server
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']
43 I check that the content of "test.txt" is "abcd"
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'
51 I append the string 'defgh' into "test.txt"
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)
60 I check that the content of "text.txt" is 'abcddefgh'
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'
68 I try to cd into an non-existing folder 'Not-This'
70 !python {model: ir.attachment}: |
71 from document_ftp import test_easyftp as te
73 ftp = te.get_ftp_login(cr, uid, self)
76 assert False, "We should't be able to change here"
77 except ftplib.error_perm:
80 assert err.errno == 2, err.errno
82 I create a "test2.txt" file through FTP.
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)
91 I look for the "test2.txt" file at the server
93 !python {model: ir.attachment }: |
94 ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
97 I delete the "test2.txt" file using FTP.
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')
105 I check at the server that test2.txt is deleted
107 !python {model: ir.attachment }: |
108 ids = self.search(cr, uid, [('name', '=', 'test2.txt')])
111 I create a test2.txt file again.
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)
120 I delete the test2.txt from the server (RPC).
122 !delete { model: ir.attachment, id:, search: "[('name','=','test2.txt')]" }
124 I also commit, because ftp would run in a different transaction.
126 !python {model: ir.attachment}: |
129 I check through FTP that test2.txt does not appear.
131 !python {model: ir.attachment}: |
132 from document_ftp import test_easyftp as te
134 ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
136 nlst_result = ftp.nlst("test2.txt")
137 except ftplib.error_perm: # 550 error: 'path not exists'
139 assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result
141 I create a "test-name.txt" file
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)
150 I rename the "test-name.txt" file through ftp.
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")
157 I check that test-name.txt has been renamed.
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')
164 res = ftp.nlst("test-name.txt")
165 assert res == [], "File has not been renamed!"
166 except error_perm, e:
168 assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
170 I create a new folder 'Test-Folder2' 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.mkd("Test-Folder2")
177 I create a file 'test3.txt' at the 'Test-Folder2'
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)
186 I try to retrieve test3.txt
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!"
193 I create a new folder, 'Test-Folder3', through FTP
194 I try to move test3.txt to 'Test-Folder3'
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")
202 I remove the 'Test-Folder3'
204 I check that test3.txt is removed.
206 I create 200 files through FTP
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')
214 for i in range(0, 200):
216 ftp.storbinary('STOR test-name%s.txt' %i, fdata)
218 I list the 200 files, check speed
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')
224 assert len(ftp.nlst()) >= 200, "We haven't managed to store 200 files!"
226 I read the 200 files, check speed
229 I move the 200 files to 'Test-Folder2'