Merge pull request #417 from gurneyalex/7.0-fix_1311004_account_move_line_index-afe
[odoo/odoo.git] / addons / document_ftp / test / document_ftp_test4.yml
1 -
2     In order to check dynamic folder functionality of document + FTP
3 -
4     !python {model: ir.attachment}: |
5         from document_ftp import test_easyftp as te
6         ftp = te.get_plain_ftp(timeout=1.0)
7 - |
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'
11 -
12     !record {model: res.partner.category, id: tpat_categ_none }:
13         name: 'No partners'
14 -
15     !record {model: res.partner.category, id: tpat_categ_pat1 }:
16         name: 'Pat 1'
17 -
18     !record {model: res.partner.category, id: tpat_categ_all }:
19         name: 'All Partner1+2'
20 -
21     !record {model: res.partner, id: tpartner1 }:
22         name: Partner 1
23         category_id:
24             - tpat_categ_pat1
25             - tpat_categ_all
26 -
27     !record {model: res.partner, id: tpartner_2 }:
28         name: 'Partner 2'
29         category_id:
30             - tpat_categ_all
31 -
32     I create a resource folder of partners, by the (none, pat1, all) 
33     categories.
34 -
35     !record {model: document.directory, id: dir_tests2 }:
36         name: Partners Testing
37         parent_id: document.dir_root
38         type: ressource
39         ressource_type_id: base.model_res_partner_category
40         domain: [] # TODO
41 -
42     I commit (because FTP operations are on different transaction)
43 -
44     !python {model: document.directory, id: }: |
45         cr.commit()
46 -
47     I browse through ftp in the resource folder, checking that three
48     categories are there.
49 -
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')
53         dirs = ftp.nlst()
54         for dir in [ 'All Partner1+2', 'No partners', 'Pat 1' ]:
55             assert dir in dirs, "Dir %s not in folder" % dir
56 -
57     I create a 'partners' folder by the first resource one.
58 -
59     !record {model: document.directory, id: dir_respart1 }:
60         name: Partners of Test
61         parent_id: dir_tests2
62         type: ressource
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
66 -
67     I commit (because FTP operations are on different transaction)
68 -
69     !python {model: document.directory, id: }: |
70         cr.commit()
71 -
72     I check through FTP that the correct partners are listed at each
73     'partners' folder.
74 -
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' ],
79                 'No partners': [],
80                 'Pat 1': ['Partner 1',] }
81         for dir in correct:
82             res = ftp.nlst(dir+'/Partners of Test')
83             assert res == correct[dir], "Dir %s falsely contains %s" %(dir, res)
84 -
85     I create an ir.attachment, attached (not related) to Partner1
86 -
87     !record {model: ir.attachment, id: file_test1}:
88         name: File of pat1
89         res_model: res.partner
90         res_id:  !eval ref("tpartner1")
91 -
92     I commit (because FTP operations are on different transaction)
93 -
94     !python {model: document.directory, id: }: |
95         cr.commit()
96 -
97     I check that pat1/Partner1 folder has the file.
98     I check that all/Partner1 folder has the file
99 -
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' ]
104         for dir in dirs:
105             res = ftp.nlst(dir+'/Partners of Test/Partner 1')
106             assert 'File of pat1' in res, "Dir %s contains only %s" %(dir, res)
107 -
108     I place a file at the 'pat1'/Partner1 folder, through FTP
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/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)
117 -
118     I check at the server that the file is attached to Partner1
119 -
120     !assert {model: ir.attachment, id: , search: "[('name','=','pat1-dynamic.txt')]" }:
121       - parent_id.name == 'Documents'
122       - res_model == 'res.partner'
123       - res_id !=  False
124 -
125     I try to create a file directly under the Partners Testing folder
126 -
127     !python {model: ir.attachment}: |
128         from document_ftp import test_easyftp as te
129         import ftplib
130         from cStringIO import StringIO
131         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
132         fdata = StringIO('abcd')
133         try:
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
138             pass
139 -
140     I try to create a folder directly under the Partners Testing folder
141 -
142     !python {model: ir.attachment}: |
143         from document_ftp import test_easyftp as te
144         import ftplib
145         from cStringIO import StringIO
146         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
147         try:
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
152             pass
153 -
154     I check that all/Partner1 also has the file
155 - |
156     Bonus Piste:
157     I create a 'Partner3' under 'all'
158     
159 -
160    I delete "pat1-dynamic.txt" File.
161 -
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')
167         ftp.close()
168         cr.rollback() # restart transaction to see changes (FTP-FS uses its own cursor)
169     
170 -
171     I delete the Partners Testing folder,  "File of pat1" file, Partner and Partner category.
172 -
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')
177         
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
187