104 # instances but not RQLUniqueConstraint |
104 # instances but not RQLUniqueConstraint |
105 # |
105 # |
106 # isinstance(cstr, RQLConstraint) |
106 # isinstance(cstr, RQLConstraint) |
107 # -> expected to return RQLConstraint instances but not |
107 # -> expected to return RQLConstraint instances but not |
108 # RRQLVocabularyConstraint and QLUniqueConstraint |
108 # RRQLVocabularyConstraint and QLUniqueConstraint |
109 self.failIf(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
109 self.assertFalse(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
110 self.failIf(issubclass(RQLUniqueConstraint, RQLConstraint)) |
110 self.assertFalse(issubclass(RQLUniqueConstraint, RQLConstraint)) |
111 self.failUnless(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
111 self.assertTrue(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
112 |
112 |
113 def test_entity_perms(self): |
113 def test_entity_perms(self): |
114 self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests'))) |
114 self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests'))) |
115 self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',))) |
115 self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',))) |
116 self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners'))) |
116 self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners'))) |
159 self.assert_(isinstance(schema, CubicWebSchema)) |
159 self.assert_(isinstance(schema, CubicWebSchema)) |
160 self.assertEqual(schema.name, 'data') |
160 self.assertEqual(schema.name, 'data') |
161 entities = sorted([str(e) for e in schema.entities()]) |
161 entities = sorted([str(e) for e in schema.entities()]) |
162 expected_entities = ['BaseTransition', 'BigInt', 'Bookmark', 'Boolean', 'Bytes', 'Card', |
162 expected_entities = ['BaseTransition', 'BigInt', 'Bookmark', 'Boolean', 'Bytes', 'Card', |
163 'Date', 'Datetime', 'Decimal', |
163 'Date', 'Datetime', 'Decimal', |
164 'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType', |
164 'CWCache', 'CWConstraint', 'CWConstraintType', 'CWDataImport', |
165 'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', |
165 'CWEType', 'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', |
166 'CWPermission', 'CWProperty', 'CWRType', |
166 'CWPermission', 'CWProperty', 'CWRType', |
167 'CWSource', 'CWSourceHostConfig', 'CWSourceSchemaConfig', |
167 'CWSource', 'CWSourceHostConfig', 'CWSourceSchemaConfig', |
168 'CWUniqueTogetherConstraint', 'CWUser', |
168 'CWUniqueTogetherConstraint', 'CWUser', |
169 'ExternalUri', 'File', 'Float', 'Int', 'Interval', 'Note', |
169 'ExternalUri', 'File', 'Float', 'Int', 'Interval', 'Note', |
170 'Password', 'Personne', 'Produit', |
170 'Password', 'Personne', 'Produit', |
173 'Tag', 'TZDatetime', 'TZTime', 'Time', 'Transition', 'TrInfo', |
173 'Tag', 'TZDatetime', 'TZTime', 'Time', 'Transition', 'TrInfo', |
174 'Usine', |
174 'Usine', |
175 'Workflow', 'WorkflowTransition'] |
175 'Workflow', 'WorkflowTransition'] |
176 self.assertListEqual(sorted(expected_entities), entities) |
176 self.assertListEqual(sorted(expected_entities), entities) |
177 relations = sorted([str(r) for r in schema.relations()]) |
177 relations = sorted([str(r) for r in schema.relations()]) |
178 expected_relations = ['add_permission', 'address', 'alias', 'allowed_transition', |
178 expected_relations = ['actionnaire', 'add_permission', 'address', 'alias', 'allowed_transition', 'associe', |
179 'bookmarked_by', 'by_transition', |
179 'bookmarked_by', 'by_transition', |
180 |
180 |
181 'cardinality', 'comment', 'comment_format', |
181 'cardinality', 'comment', 'comment_format', |
182 'composite', 'condition', 'config', 'connait', |
182 'composite', 'condition', 'config', 'connait', |
183 'constrained_by', 'constraint_of', |
183 'constrained_by', 'constraint_of', |
184 'content', 'content_format', |
184 'content', 'content_format', 'contrat_exclusif', |
185 'created_by', 'creation_date', 'cstrtype', 'custom_workflow', |
185 'created_by', 'creation_date', 'cstrtype', 'custom_workflow', |
186 'cwuri', 'cw_for_source', 'cw_host_config_of', 'cw_schema', 'cw_source', |
186 'cwuri', 'cw_for_source', 'cw_import_of', 'cw_host_config_of', 'cw_schema', 'cw_source', |
187 |
187 |
188 'data', 'data_encoding', 'data_format', 'data_name', 'default_workflow', 'defaultval', 'delete_permission', |
188 'data', 'data_encoding', 'data_format', 'data_name', 'default_workflow', 'defaultval', 'delete_permission', |
189 'description', 'description_format', 'destination_state', |
189 'description', 'description_format', 'destination_state', 'dirige', |
190 |
190 |
191 'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype', |
191 'ecrit_par', 'eid', 'end_timestamp', 'evaluee', 'expression', 'exprtype', |
192 |
192 |
193 'fabrique_par', 'final', 'firstname', 'for_user', 'fournit', |
193 'fabrique_par', 'final', 'firstname', 'for_user', 'fournit', |
194 'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed', |
194 'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed', |
195 |
195 |
196 'has_text', |
196 'has_group_permission', 'has_text', |
197 'identity', 'in_group', 'in_state', 'in_synchronization', 'indexed', |
197 'identity', 'in_group', 'in_state', 'in_synchronization', 'indexed', |
198 'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of', |
198 'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of', |
199 |
199 |
200 'label', 'last_login_time', 'latest_retrieval', 'lieu', 'login', |
200 'label', 'last_login_time', 'latest_retrieval', 'lieu', 'log', 'login', |
201 |
201 |
202 'mainvars', 'match_host', 'modification_date', |
202 'mainvars', 'match_host', 'modification_date', |
203 |
203 |
204 'name', 'nom', |
204 'name', 'nom', |
205 |
205 |
207 |
207 |
208 'parser', 'path', 'pkey', 'prefered_form', 'prenom', 'primary_email', |
208 'parser', 'path', 'pkey', 'prefered_form', 'prenom', 'primary_email', |
209 |
209 |
210 'read_permission', 'relation_type', 'relations', 'require_group', |
210 'read_permission', 'relation_type', 'relations', 'require_group', |
211 |
211 |
212 'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symmetric', 'synopsis', |
212 'specializes', 'start_timestamp', 'state_of', 'status', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symmetric', 'synopsis', |
213 |
213 |
214 'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', |
214 'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', |
215 |
215 |
216 'upassword', 'update_permission', 'url', 'uri', 'use_email', |
216 'upassword', 'update_permission', 'url', 'uri', 'use_email', |
217 |
217 |
223 |
223 |
224 eschema = schema.eschema('CWUser') |
224 eschema = schema.eschema('CWUser') |
225 rels = sorted(str(r) for r in eschema.subject_relations()) |
225 rels = sorted(str(r) for r in eschema.subject_relations()) |
226 self.assertListEqual(rels, ['created_by', 'creation_date', 'custom_workflow', |
226 self.assertListEqual(rels, ['created_by', 'creation_date', 'custom_workflow', |
227 'cw_source', 'cwuri', 'eid', |
227 'cw_source', 'cwuri', 'eid', |
228 'evaluee', 'firstname', 'has_text', 'identity', |
228 'evaluee', 'firstname', 'has_group_permission', |
229 'in_group', 'in_state', 'is', |
229 'has_text', 'identity', |
230 'is_instance_of', 'last_login_time', |
230 'in_group', 'in_state', 'is', |
231 'login', 'modification_date', 'owned_by', |
231 'is_instance_of', 'last_login_time', |
232 'primary_email', 'surname', 'upassword', |
232 'login', 'modification_date', 'owned_by', |
233 'use_email']) |
233 'primary_email', 'surname', 'upassword', |
|
234 'use_email']) |
234 rels = sorted(r.type for r in eschema.object_relations()) |
235 rels = sorted(r.type for r in eschema.object_relations()) |
235 self.assertListEqual(rels, ['bookmarked_by', 'created_by', 'for_user', |
236 self.assertListEqual(rels, ['bookmarked_by', 'created_by', 'for_user', |
236 'identity', 'owned_by', 'wf_info_for']) |
237 'identity', 'owned_by', 'wf_info_for']) |
237 rschema = schema.rschema('relation_type') |
238 rschema = schema.rschema('relation_type') |
238 properties = rschema.rdef('CWAttribute', 'CWRType') |
239 properties = rschema.rdef('CWAttribute', 'CWRType') |
239 self.assertEqual(properties.cardinality, '1*') |
240 self.assertEqual(properties.cardinality, '1*') |
240 constraints = properties.constraints |
241 constraints = properties.constraints |
241 self.failUnlessEqual(len(constraints), 1, constraints) |
242 self.assertEqual(len(constraints), 1, constraints) |
242 constraint = constraints[0] |
243 constraint = constraints[0] |
243 self.failUnless(isinstance(constraint, RQLConstraint)) |
244 self.assertTrue(isinstance(constraint, RQLConstraint)) |
244 self.failUnlessEqual(constraint.expression, 'O final TRUE') |
245 self.assertEqual(constraint.expression, 'O final TRUE') |
245 |
246 |
246 def test_fulltext_container(self): |
247 def test_fulltext_container(self): |
247 schema = loader.load(config) |
248 schema = loader.load(config) |
248 self.failUnless('has_text' in schema['CWUser'].subject_relations()) |
249 self.assertTrue('has_text' in schema['CWUser'].subject_relations()) |
249 self.failIf('has_text' in schema['EmailAddress'].subject_relations()) |
250 self.assertFalse('has_text' in schema['EmailAddress'].subject_relations()) |
250 |
251 |
251 def test_permission_settings(self): |
252 def test_permission_settings(self): |
252 schema = loader.load(config) |
253 schema = loader.load(config) |
253 aschema = schema['TrInfo'].rdef('comment') |
254 aschema = schema['TrInfo'].rdef('comment') |
254 self.assertEqual(aschema.get_groups('read'), |
255 self.assertEqual(aschema.get_groups('read'), |
262 |
263 |
263 def test_nonregr_allowed_type_names(self): |
264 def test_nonregr_allowed_type_names(self): |
264 schema = CubicWebSchema('Test Schema') |
265 schema = CubicWebSchema('Test Schema') |
265 schema.add_entity_type(EntityType('NaN')) |
266 schema.add_entity_type(EntityType('NaN')) |
266 |
267 |
|
268 def test_relation_perm_overriding(self): |
|
269 loader = CubicWebSchemaLoader() |
|
270 config = TestConfiguration('data', apphome=join(dirname(__file__), 'data_schemareader')) |
|
271 config.bootstrap_cubes() |
|
272 schema = loader.load(config) |
|
273 self.assertEqual(schema['in_group'].rdefs.values()[0].permissions, |
|
274 {'read': ('managers',), |
|
275 'add': ('managers',), |
|
276 'delete': ('managers',)}) |
|
277 self.assertEqual(schema['cw_for_source'].rdefs.values()[0].permissions, |
|
278 {'read': ('managers', 'users'), |
|
279 'add': ('managers',), |
|
280 'delete': ('managers',)}) |
|
281 |
267 |
282 |
268 class BadSchemaTC(TestCase): |
283 class BadSchemaTC(TestCase): |
269 def setUp(self): |
284 def setUp(self): |
270 self.loader = CubicWebSchemaLoader() |
285 self.loader = CubicWebSchemaLoader() |
271 self.loader.defined = {} |
286 self.loader.defined = {} |
331 anoneid = self.execute('Any X WHERE X login "anon"')[0][0] |
346 anoneid = self.execute('Any X WHERE X login "anon"')[0][0] |
332 self.assertRaises(ValidationError, cstr.repo_check, self.session, 1, 'rel', anoneid) |
347 self.assertRaises(ValidationError, cstr.repo_check, self.session, 1, 'rel', anoneid) |
333 self.assertEqual(cstr.repo_check(self.session, 1, self.session.user.eid), |
348 self.assertEqual(cstr.repo_check(self.session, 1, self.session.user.eid), |
334 None) # no validation error, constraint checked |
349 None) # no validation error, constraint checked |
335 |
350 |
|
351 class WorkflowShemaTC(CubicWebTC): |
|
352 def test_trinfo_default_format(self): |
|
353 tr = self.session.user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
|
354 self.assertEqual(tr.comment_format, 'text/plain') |
336 |
355 |
337 if __name__ == '__main__': |
356 if __name__ == '__main__': |
338 unittest_main() |
357 unittest_main() |