doc ftp: yaml tests for files/folders in wrong dirs.
[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     !python {model: document.directory, id: }: |
68         cr.commit()
69 -
70     I check through FTP that the correct partners are listed at each
71     'partners' folder.
72 -
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' ],
77                 'No partners': [],
78                 'Pat 1': ['Partner 1',] }
79         for dir in correct:
80             res = ftp.nlst(dir+'/Partners of Test')
81             assert res == correct[dir], "Dir %s falsely contains %s" %(dir, res)
82 -
83     I create an ir.attachment, attached (not related) to Partner1
84 -
85     !record {model: ir.attachment, id: file_test1 }:
86         name: File of pat1
87         res_model: res.partner
88         res_id:  !eval ref("tpartner1")
89 -
90     I check that pat1/Partner1 folder has the file.
91     I check that all/Partner1 folder has the file
92 -
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' ]
97         for dir in dirs:
98             res = ftp.nlst(dir+'/Partners of Test/Partner 1')
99             assert 'File of pat1' in res, "Dir %s contains only %s" %(dir, res)
100 -
101     I place a file at the 'pat1'/Partner1 folder, through FTP
102 -
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)
109 -
110     I check at the server that the file is attached to Partner1
111 -
112     !assert {model: ir.attachment, id: , search: "[('name','=','pat1-dynamic.txt')]" }:
113       - parent_id.name == 'Documents'
114       - res_model == 'res.partner'
115       - res_id !=  False
116 -
117     I try to create a file directly under the Partners Testing folder
118 -
119     !python {model: ir.attachment}: |
120         from document_ftp import test_easyftp as te
121         import ftplib
122         from cStringIO import StringIO
123         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
124         fdata = StringIO('abcd')
125         try:
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
130             pass
131 -
132     I try to create a folder directly under the Partners Testing folder
133 -
134     !python {model: ir.attachment}: |
135         from document_ftp import test_easyftp as te
136         import ftplib
137         from cStringIO import StringIO
138         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing')
139         try:
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
144             pass
145 -
146     I check that all/Partner1 also has the file
147 - |
148     Bonus Piste:
149     I create a 'Partner3' under 'all'
150 -
151     I delete the Partners Testing folder
152 -
153     !python {model: document.directory}: |
154         self.unlink(cr, uid, [ref('dir_tests2')])
155         self.unlink(cr, uid, [ref('dir_respart1')])
156         cr.commit()