yo') - self.assertEqual(entity.description, u'R&D
yo
') - - def test_metadata_cwuri(self): - with self.admin_access.repo_cnx() as cnx: - entity = cnx.create_entity('Workflow', name=u'wf1') - self.assertEqual(entity.cwuri, self.repo.config['base-url'] + str(entity.eid)) - - def test_metadata_creation_modification_date(self): - with self.admin_access.repo_cnx() as cnx: - _now = datetime.now(utc) - entity = cnx.create_entity('Workflow', name=u'wf1') - self.assertEqual((entity.creation_date - _now).seconds, 0) - self.assertEqual((entity.modification_date - _now).seconds, 0) - - def test_metadata_created_by(self): - with self.admin_access.repo_cnx() as cnx: - entity = cnx.create_entity('Bookmark', title=u'wf1', path=u'/view') - cnx.commit() # fire operations - self.assertEqual(len(entity.created_by), 1) # make sure we have only one creator - self.assertEqual(entity.created_by[0].eid, cnx.user.eid) - - def test_metadata_owned_by(self): - with self.admin_access.repo_cnx() as cnx: - entity = cnx.create_entity('Bookmark', title=u'wf1', path=u'/view') - cnx.commit() # fire operations - self.assertEqual(len(entity.owned_by), 1) # make sure we have only one owner - self.assertEqual(entity.owned_by[0].eid, cnx.user.eid) - - def test_user_login_stripped(self): - with self.admin_access.repo_cnx() as cnx: - u = self.create_user(cnx, ' joe ') - tname = cnx.execute('Any L WHERE E login L, E eid %(e)s', - {'e': u.eid})[0][0] - self.assertEqual(tname, 'joe') - cnx.execute('SET X login " jijoe " WHERE X eid %(x)s', {'x': u.eid}) - tname = cnx.execute('Any L WHERE E login L, E eid %(e)s', - {'e': u.eid})[0][0] - self.assertEqual(tname, 'jijoe') - - - -class UserGroupHooksTC(CubicWebTC): - - def test_user_group_synchronization(self): - with self.admin_access.repo_cnx() as cnx: - user = cnx.user - self.assertEqual(user.groups, set(('managers',))) - cnx.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) - self.assertEqual(user.groups, set(('managers',))) - cnx.commit() - self.assertEqual(user.groups, set(('managers', 'guests'))) - cnx.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) - self.assertEqual(user.groups, set(('managers', 'guests'))) - cnx.commit() - self.assertEqual(user.groups, set(('managers',))) - - def test_user_composite_owner(self): - with self.admin_access.repo_cnx() as cnx: - self.create_user(cnx, 'toto').eid - # composite of euser should be owned by the euser regardless of who created it - cnx.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' - 'WHERE U login "toto"') - cnx.commit() - self.assertEqual(cnx.execute('Any A WHERE X owned_by U, U use_email X,' - 'U login "toto", X address A')[0][0], - 'toto@logilab.fr') - - def test_user_composite_no_owner_on_deleted_entity(self): - with self.admin_access.repo_cnx() as cnx: - u = self.create_user(cnx, 'toto').eid - cnx.commit() - e = cnx.create_entity('EmailAddress', address=u'toto@logilab.fr', reverse_use_email=u) - e.cw_delete() - cnx.commit() - self.assertFalse(cnx.system_sql( - 'SELECT * FROM owned_by_relation ' - 'WHERE eid_from NOT IN (SELECT eid FROM entities)').fetchall()) - - def test_no_created_by_on_deleted_entity(self): - with self.admin_access.repo_cnx() as cnx: - eid = cnx.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] - cnx.execute('DELETE EmailAddress X WHERE X eid %s' % eid) - cnx.commit() - self.assertFalse(cnx.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) - - - -class SchemaHooksTC(CubicWebTC): - - def test_duplicate_etype_error(self): - with self.admin_access.repo_cnx() as cnx: - # check we can't add a CWEType or CWRType entity if it already exists one - # with the same name - self.assertRaises(ValidationError, - cnx.execute, 'INSERT CWEType X: X name "CWUser"') - cnx.rollback() - self.assertRaises(ValidationError, - cnx.execute, 'INSERT CWRType X: X name "in_group"') - - def test_validation_unique_constraint(self): - with self.admin_access.repo_cnx() as cnx: - with self.assertRaises(ValidationError) as cm: - cnx.execute('INSERT CWUser X: X login "admin"') - ex = cm.exception - ex.translate(text_type) - self.assertIsInstance(ex.entity, int) - self.assertEqual(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'}) - - -if __name__ == '__main__': - from logilab.common.testlib import unittest_main - unittest_main()