2 In order to check dynamic folder functionality of document + FTP
4 !python {model: ir.attachment}: |
5 from document_ftp import test_easyftp as te
6 ftp = te.get_plain_ftp(timeout=1.0)
8 I create two partners 'Partner1' and 'Partner2'.
9 I create three partner categories: 'none', 'pat1' and 'all'
10 I attach Partner1 to pat1, Partner1+Partner2 to 'all'
12 !record {model: res.partner.category, id: tpat_categ_none }:
15 !record {model: res.partner.category, id: tpat_categ_pat1 }:
18 !record {model: res.partner.category, id: tpat_categ_all }:
19 name: 'All Partner1+2'
21 !record {model: res.partner, id: tpartner1 }:
27 !record {model: res.partner, id: tpartner_2 }:
32 I create a resource folder of partners, by the (none, pat1, all)
35 !record {model: document.directory, id: dir_tests2 }:
36 name: Partners Testing
37 parent_id: document.dir_root
39 ressource_type_id: base.model_res_partner_category
42 I commit (because FTP operations are on different transaction)
44 !python {model: document.directory, id: }: |
47 I browse through ftp in the resource folder, checking that three
50 !python {model: ir.attachment}: |
51 from document_ftp import test_easyftp as te
52 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
54 for dir in [ 'All Partner1+2', 'No partners', 'Pat 1' ]:
55 assert dir in dirs, "Dir %s not in folder" % dir
57 I create a 'partners' folder by the first resource one.
59 !record {model: document.directory, id: dir_respart1 }:
60 name: Partners of Test
63 ressource_type_id: base.model_res_partner
64 domain: "[('category_id','in',[active_id])]"
65 ressource_parent_type_id : base.model_res_partner_category
67 I commit (because FTP operations are on different transaction)
69 !python {model: document.directory, id: }: |
72 I check through FTP that the correct partners are listed at each
75 !python {model: ir.attachment}: |
76 from document_ftp import test_easyftp as te
77 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
78 correct = { 'All Partner1+2': [ 'Partner 1', 'Partner 2' ],
80 'Pat 1': ['Partner 1',] }
82 res = ftp.nlst(dir+'/Partners of Test')
83 assert res == correct[dir], "Dir %s falsely contains %s" %(dir, res)
85 I create an ir.attachment, attached (not related) to Partner1
87 !record {model: ir.attachment, id: file_test1}:
89 res_model: res.partner
90 res_id: !eval ref("tpartner1")
92 I commit (because FTP operations are on different transaction)
94 !python {model: document.directory, id: }: |
97 I check that pat1/Partner1 folder has the file.
98 I check that all/Partner1 folder has the file
100 !python {model: ir.attachment}: |
101 from document_ftp import test_easyftp as te
102 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
103 dirs = [ 'All Partner1+2', 'Pat 1' ]
105 res = ftp.nlst(dir+'/Partners of Test/Partner 1')
106 assert 'File of pat1' in res, "Dir %s contains only %s" %(dir, res)
108 I place a file at the 'pat1'/Partner1 folder, through FTP
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/Partners Testing/Pat 1/Partners of Test/Partner 1')
114 fdata = StringIO('abcd')
115 ftp.storbinary('STOR pat1-dynamic.txt', fdata)
116 cr.rollback() # restart transaction to see changes (FTP-FS uses its own cursor)
118 I check at the server that the file is attached to Partner1
120 !assert {model: ir.attachment, id: , search: "[('name','=','pat1-dynamic.txt')]" }:
121 - parent_id.name == 'Documents'
122 - res_model == 'res.partner'
125 I try to create a file directly under the Partners Testing folder
127 !python {model: ir.attachment}: |
128 from document_ftp import test_easyftp as te
130 from cStringIO import StringIO
131 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
132 fdata = StringIO('abcd')
134 ftp.storbinary('STOR stray.txt', fdata)
135 assert False, "We should't be able to create files here"
136 except ftplib.error_perm:
137 # That's what should happen
140 I try to create a folder directly under the Partners Testing folder
142 !python {model: ir.attachment}: |
143 from document_ftp import test_easyftp as te
145 from cStringIO import StringIO
146 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
148 ftp.mkd('Weird folder')
149 assert False, "We should't be able to create folders here"
150 except ftplib.error_perm:
151 # That's what should happen
154 I check that all/Partner1 also has the file
157 I create a 'Partner3' under 'all'
160 I delete "pat1-dynamic.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/Partners Testing/Pat 1/Partners of Test/Partner 1')
166 ftp.delete('pat1-dynamic.txt')
168 cr.rollback() # restart transaction to see changes (FTP-FS uses its own cursor)
171 I delete the Partners Testing folder, "File of pat1" file, Partner and Partner category.
173 !python {model: document.directory}: |
174 attach_pool = self.pool.get('ir.attachment')
175 partner_categ_pool = self.pool.get('res.partner.category')
176 partner_pool = self.pool.get('res.partner')
178 self.unlink(cr, uid, [ref('dir_tests2')])
179 self.unlink(cr, uid, [ref('dir_respart1')])
180 attach_pool.unlink(cr, uid, [ref('file_test1')])
181 partner_categ_pool.unlink(cr, uid, [ref('tpat_categ_none')])
182 partner_categ_pool.unlink(cr, uid, [ref('tpat_categ_pat1')])
183 partner_categ_pool.unlink(cr, uid, [ref('tpat_categ_all')])
184 partner_pool.unlink(cr, uid, [ref('tpartner1')])
185 partner_pool.unlink(cr, uid, [ref('tpartner_2')])
186 cr.commit() #required because all the operations via FTP were committed