hooks/test/unittest_hooks.py
branchstable
changeset 5030 5238d9a8dfee
parent 4689 4eb1f4490538
child 5421 8167de96c523
equal deleted inserted replaced
5029:f7709d28fb79 5030:5238d9a8dfee
   100     def test_unsatisfied_constraints(self):
   100     def test_unsatisfied_constraints(self):
   101         releid = self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE '
   101         releid = self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE '
   102                               'WHERE FE name "CWUser", RT name "in_group", TE name "String"')[0][0]
   102                               'WHERE FE name "CWUser", RT name "in_group", TE name "String"')[0][0]
   103         self.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
   103         self.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
   104                      {'x': releid}, 'x')
   104                      {'x': releid}, 'x')
   105         ex = self.assertRaises(ValidationError,
   105         ex = self.assertRaises(ValidationError, self.commit)
   106                                self.commit)
   106         self.assertEquals(ex.errors,
   107         self.assertEquals(ex.errors, {'to_entity': 'RQLConstraint O final FALSE failed'})
   107                           {'to_entity-object': 'RQLConstraint O final FALSE failed'})
   108 
   108 
   109     def test_html_tidy_hook(self):
   109     def test_html_tidy_hook(self):
   110         req = self.request()
   110         req = self.request()
   111         entity = req.create_entity('Workflow', name=u'wf1', description_format=u'text/html',
   111         entity = req.create_entity('Workflow', name=u'wf1', description_format=u'text/html',
   112                                  description=u'yo')
   112                                  description=u'yo')
   215 class CWPropertyHooksTC(CubicWebTC):
   215 class CWPropertyHooksTC(CubicWebTC):
   216 
   216 
   217     def test_unexistant_eproperty(self):
   217     def test_unexistant_eproperty(self):
   218         ex = self.assertRaises(ValidationError,
   218         ex = self.assertRaises(ValidationError,
   219                           self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U')
   219                           self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U')
   220         self.assertEquals(ex.errors, {'pkey': 'unknown property key'})
   220         self.assertEquals(ex.errors, {'pkey-subject': 'unknown property key'})
   221         ex = self.assertRaises(ValidationError,
   221         ex = self.assertRaises(ValidationError,
   222                           self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
   222                           self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
   223         self.assertEquals(ex.errors, {'pkey': 'unknown property key'})
   223         self.assertEquals(ex.errors, {'pkey-subject': 'unknown property key'})
   224 
   224 
   225     def test_site_wide_eproperty(self):
   225     def test_site_wide_eproperty(self):
   226         ex = self.assertRaises(ValidationError,
   226         ex = self.assertRaises(ValidationError,
   227                                self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U')
   227                                self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U')
   228         self.assertEquals(ex.errors, {'for_user': "site-wide property can't be set for user"})
   228         self.assertEquals(ex.errors, {'for_user-subject': "site-wide property can't be set for user"})
   229 
   229 
   230     def test_bad_type_eproperty(self):
   230     def test_bad_type_eproperty(self):
   231         ex = self.assertRaises(ValidationError,
   231         ex = self.assertRaises(ValidationError,
   232                                self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U')
   232                                self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U')
   233         self.assertEquals(ex.errors, {'value': u'unauthorized value'})
   233         self.assertEquals(ex.errors, {'value-subject': u'unauthorized value'})
   234         ex = self.assertRaises(ValidationError,
   234         ex = self.assertRaises(ValidationError,
   235                           self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"')
   235                           self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"')
   236         self.assertEquals(ex.errors, {'value': u'unauthorized value'})
   236         self.assertEquals(ex.errors, {'value-subject': u'unauthorized value'})
   237 
   237 
   238 
   238 
   239 class SchemaHooksTC(CubicWebTC):
   239 class SchemaHooksTC(CubicWebTC):
   240 
   240 
   241     def test_duplicate_etype_error(self):
   241     def test_duplicate_etype_error(self):
   251                           self.execute, 'INSERT CWUser X: X login "admin"')
   251                           self.execute, 'INSERT CWUser X: X login "admin"')
   252         try:
   252         try:
   253             self.execute('INSERT CWUser X: X login "admin"')
   253             self.execute('INSERT CWUser X: X login "admin"')
   254         except ValidationError, ex:
   254         except ValidationError, ex:
   255             self.assertIsInstance(ex.entity, int)
   255             self.assertIsInstance(ex.entity, int)
   256             self.assertEquals(ex.errors, {'login': 'the value "admin" is already used, use another one'})
   256             self.assertEquals(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'})
   257 
   257 
   258 
   258 
   259 if __name__ == '__main__':
   259 if __name__ == '__main__':
   260     unittest_main()
   260     unittest_main()