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 !python {model: document.directory, id: }: |
70 I check through FTP that the correct partners are listed at each
73 !python {model: ir.attachment}: |
74 from document_ftp import test_easyftp as te
75 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
76 correct = { 'All Partner1+2': [ 'Partner 1', 'Partner 2' ],
78 'Pat 1': ['Partner 1',] }
80 res = ftp.nlst(dir+'/Partners of Test')
81 assert res == correct[dir], "Dir %s falsely contains %s" %(dir, res)
83 I create an ir.attachment, attached (not related) to Partner1
85 !record {model: ir.attachment, id: file_test1}:
87 res_model: res.partner
88 res_id: !eval ref("tpartner1")
90 I check that pat1/Partner1 folder has the file.
91 I check that all/Partner1 folder has the file
93 !python {model: ir.attachment}: |
94 from document_ftp import test_easyftp as te
95 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
96 dirs = [ 'All Partner1+2', 'Pat 1' ]
98 res = ftp.nlst(dir+'/Partners of Test/Partner 1')
99 assert 'File of pat1' in res, "Dir %s contains only %s" %(dir, res)
101 I place a file at the 'pat1'/Partner1 folder, through FTP
103 !python {model: ir.attachment}: |
104 from document_ftp import test_easyftp as te
105 from cStringIO import StringIO
106 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing/Pat 1/Partners of Test/Partner 1')
107 fdata = StringIO('abcd')
108 ftp.storbinary('STOR pat1-dynamic.txt', fdata)
110 I check at the server that the file is attached to Partner1
112 !assert {model: ir.attachment, id: , search: "[('name','=','pat1-dynamic.txt')]" }:
113 - parent_id.name == 'Documents'
114 - res_model == 'res.partner'
117 I try to create a file directly under the Partners Testing folder
119 !python {model: ir.attachment}: |
120 from document_ftp import test_easyftp as te
122 from cStringIO import StringIO
123 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
124 fdata = StringIO('abcd')
126 ftp.storbinary('STOR stray.txt', fdata)
127 assert False, "We should't be able to create files here"
128 except ftplib.error_perm:
129 # That's what should happen
132 I try to create a folder directly under the Partners Testing folder
134 !python {model: ir.attachment}: |
135 from document_ftp import test_easyftp as te
137 from cStringIO import StringIO
138 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
140 ftp.mkd('Weird folder')
141 assert False, "We should't be able to create folders here"
142 except ftplib.error_perm:
143 # That's what should happen
146 I check that all/Partner1 also has the file
149 I create a 'Partner3' under 'all'
152 I delete "pat1-dynamic.txt" File.
154 !python {model: ir.attachment}: |
155 from document_ftp import test_easyftp as te
156 from cStringIO import StringIO
157 ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing/Pat 1/Partners of Test/Partner 1')
158 ftp.delete('pat1-dynamic.txt')
162 I delete the Partners Testing folder, "File of pat1" file, Partner and Partner category.
164 !python {model: document.directory}: |
165 attach_pool = self.pool.get('ir.attachment')
166 partner_categ_pool = self.pool.get('res.partner.category')
167 partner_pool = self.pool.get('res.partner')
169 self.unlink(cr, uid, [ref('dir_tests2')])
170 self.unlink(cr, uid, [ref('dir_respart1')])
171 attach_pool.unlink(cr, uid, [ref('file_test1')])
172 partner_categ_pool.unlink(cr, uid, [ref('tpat_categ_none')])
173 partner_categ_pool.unlink(cr, uid, [ref('tpat_categ_pat1')])
174 partner_categ_pool.unlink(cr, uid, [ref('tpat_categ_all')])
175 partner_pool.unlink(cr, uid, [ref('tpartner1')])
176 partner_pool.unlink(cr, uid, [ref('tpartner_2')])