17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
19 import copy |
19 import copy |
20 import warnings |
20 import warnings |
21 |
21 |
22 from cubicweb.devtools.testlib import CubicWebTC |
22 from yams.buildobjs import RelationDefinition, EntityType |
|
23 |
|
24 from cubicweb.devtools.testlib import CubicWebTC, BaseTestCase |
|
25 from cubicweb.schema import build_schema_from_namespace |
23 from cubicweb.web import uihelper, formwidgets as fwdgs |
26 from cubicweb.web import uihelper, formwidgets as fwdgs |
24 from cubicweb.web.views import uicfg |
27 from cubicweb.web.views import uicfg |
25 |
28 |
26 abaa = uicfg.actionbox_appearsin_addmenu |
29 abaa = uicfg.actionbox_appearsin_addmenu |
27 |
30 |
142 self.vreg['uicfg'].register(custom_afs) |
145 self.vreg['uicfg'].register(custom_afs) |
143 obj = self.vreg['uicfg'].select_or_none('autoform_section') |
146 obj = self.vreg['uicfg'].select_or_none('autoform_section') |
144 self.assertTrue(obj is custom_afs) |
147 self.assertTrue(obj is custom_afs) |
145 |
148 |
146 |
149 |
|
150 def _schema(): |
|
151 |
|
152 class Personne(EntityType): |
|
153 pass |
|
154 |
|
155 class Societe(EntityType): |
|
156 pass |
|
157 |
|
158 class Tag(EntityType): |
|
159 pass |
|
160 |
|
161 class travaille(RelationDefinition): |
|
162 subject = 'Personne' |
|
163 object = 'Societe' |
|
164 |
|
165 class tags(RelationDefinition): |
|
166 subject = 'Tag' |
|
167 object = ('Personne', 'Societe', 'Tag') |
|
168 |
|
169 return build_schema_from_namespace(locals().items()) |
|
170 |
|
171 |
|
172 class AutoformSectionTC(BaseTestCase): |
|
173 |
|
174 def test_derivation(self): |
|
175 schema = _schema() |
|
176 afs = uicfg.AutoformSectionRelationTags() |
|
177 afs.tag_subject_of(('Personne', 'travaille', '*'), 'main', 'relations') |
|
178 afs.tag_object_of(('*', 'travaille', 'Societe'), 'main', 'relations') |
|
179 afs.tag_subject_of(('Tag', 'tags', '*'), 'main', 'relations') |
|
180 |
|
181 afs2 = afs.derive(__name__, afs.__select__) |
|
182 afs2.tag_subject_of(('Personne', 'travaille', '*'), 'main', 'attributes') |
|
183 afs2.tag_object_of(('*', 'travaille', 'Societe'), 'main', 'attributes') |
|
184 afs2.tag_subject_of(('Tag', 'tags', 'Societe'), 'main', 'attributes') |
|
185 |
|
186 afs.init(schema) |
|
187 afs2.init(schema) |
|
188 |
|
189 self.assertEqual(afs2.etype_get('Tag', 'tags', 'subject', 'Personne'), |
|
190 set(('main_relations', 'muledit_hidden', 'inlined_relations'))) |
|
191 self.assertEqual(afs2.etype_get('Tag', 'tags', 'subject', 'Societe'), |
|
192 set(('main_attributes', 'muledit_hidden', 'inlined_attributes'))) |
|
193 self.assertEqual(afs2.etype_get('Personne', 'travaille', 'subject', 'Societe'), |
|
194 set(('main_attributes', 'muledit_hidden', 'inlined_attributes'))) |
|
195 self.assertEqual(afs2.etype_get('Societe', 'travaille', 'object', 'Personne'), |
|
196 set(('main_attributes', 'muledit_hidden', 'inlined_attributes'))) |
|
197 |
|
198 |
147 if __name__ == '__main__': |
199 if __name__ == '__main__': |
148 import unittest |
200 import unittest |
149 unittest.main() |
201 unittest.main() |