Commit ec4a692d authored by Julien Cristau's avatar Julien Cristau
Browse files

[test] update unittest_hooks for cubicweb 3.19

parent 1a76dfaa70ef
......@@ -43,78 +43,85 @@ Lines: 2
class ChangeStateHooksTC(CubicWebTC):
def setup_database(self):
self.request().create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
self.request().create_entity('EmailAddress', address=u'devel@logilab.fr', alias=u'devel')
with self.admin_access.client_cnx() as cnx:
cnx.create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
cnx.create_entity('EmailAddress', address=u'devel@logilab.fr', alias=u'devel')
cnx.commit()
self.msg = MSG % (self.vreg.config.appid, gethostname())
def test_email_change_state(self):
u = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"').get_entity(0, 0)
subject = u':deactivate: %s' % u.eid
eeid = self.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
self.commit()
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': u.eid})[0][0]
self.assertEqual(userstate, 'deactivated')
self.assertEqual(u.cw_adapt_to('IWorkflowable').latest_trinfo().creator.login, 'admin')
with self.admin_access.client_cnx() as cnx:
u = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"').get_entity(0, 0)
subject = u':deactivate: %s' % u.eid
eeid = cnx.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
cnx.commit()
userstate = cnx.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': u.eid})[0][0]
self.assertEqual(userstate, 'deactivated')
self.assertEqual(u.cw_adapt_to('IWorkflowable').latest_trinfo().creator.login, 'admin')
def test_email_change_state_trinfo_owner(self):
self.execute('SET U use_email E WHERE U login "anon"')
u = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"').get_entity(0, 0)
subject = u':deactivate: %s' % u.eid
eeid = self.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
self.commit()
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': u.eid})[0][0]
self.assertEqual(userstate, 'deactivated')
self.assertEqual(u.cw_adapt_to('IWorkflowable').latest_trinfo().creator.login, 'anon')
with self.admin_access.client_cnx() as cnx:
cnx.execute('SET U use_email E WHERE U login "anon"')
u = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"').get_entity(0, 0)
subject = u':deactivate: %s' % u.eid
eeid = cnx.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
cnx.commit()
userstate = cnx.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': u.eid})[0][0]
self.assertEqual(userstate, 'deactivated')
self.assertEqual(u.cw_adapt_to('IWorkflowable').latest_trinfo().creator.login, 'anon')
def test_email_change_state_wrong_eid(self):
ueid = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"')[0][0]
subject = u':deactivate: %s' % 10
eeid = self.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
self.commit()
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid})[0][0]
self.assertEqual(userstate, 'activated')
with self.admin_access.client_cnx() as cnx:
ueid = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"')[0][0]
subject = u':deactivate: %s' % 10
eeid = cnx.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
cnx.commit()
userstate = cnx.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid})[0][0]
self.assertEqual(userstate, 'activated')
def test_email_change_state_unexistant_eid(self):
ueid = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"')[0][0]
subject = u':deactivate: %s' % 999999
eeid = self.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
self.commit()
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid})[0][0]
self.assertEqual(userstate, 'activated')
with self.admin_access.client_cnx() as cnx:
ueid = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"')[0][0]
subject = u':deactivate: %s' % 999999
eeid = cnx.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
cnx.commit()
userstate = cnx.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid})[0][0]
self.assertEqual(userstate, 'activated')
def test_email_change_state_unexistant_transition(self):
ueid = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"')[0][0]
subject = u':blabla: %s' % ueid
eeid = self.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
self.commit()
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid})[0][0]
self.assertEqual(userstate, 'activated')
with self.admin_access.client_cnx() as cnx:
ueid = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G '
'WHERE G name "users"')[0][0]
subject = u':blabla: %s' % ueid
eeid = cnx.execute('INSERT Email X: '
'X headers %(headers)s, X subject %(subject)s,'
'X messageid "hop", X sender EA',
{'subject': subject, 'headers': self.msg})[0][0]
cnx.commit()
userstate = cnx.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid})[0][0]
self.assertEqual(userstate, 'activated')
......@@ -144,21 +151,25 @@ from cubes.email.mboximport import MBOXImporter
class ReplyCommentHooksTC(CubicWebTC):
def setup_database(self):
self.b = self.request().create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
e = self.request().create_entity('EmailAddress', address=u'sylvain.thenault@logilab.fr', alias=u'syt')
self.execute('SET X use_email E WHERE X login "anon", E eid %(e)s', {'e': e.eid})
with self.admin_access.client_cnx() as cnx:
self.b = cnx.create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau").eid
e = cnx.create_entity('EmailAddress', address=u'sylvain.thenault@logilab.fr', alias=u'syt')
cnx.execute('SET X use_email E WHERE X login "anon", E eid %(e)s', {'e': e.eid})
cnx.commit()
def test_comment_created(self):
mi = MBOXImporter(self.cnx)
msg = open(join(self.datadir, 'reply.mbox'), 'rb').read() % \
construct_message_id(self.vreg.config.appid, self.b.eid, False)
mi.import_mbox_stream(StringIO(msg))
self.commit()
self.failUnless(self.execute('Email X'))
self.failUnless(self.b.reverse_comments)
c = self.b.reverse_comments[0]
self.failUnlessEqual(c.content_format, 'text/plain')
self.failUnlessEqual(c.content, u'''New ticket for project erudi-email :
construct_message_id(self.vreg.config.appid, self.b, False)
with self.admin_access.client_cnx() as cnx:
mi = MBOXImporter(cnx)
mi.import_mbox_stream(StringIO(msg))
cnx.commit()
self.assertTrue(cnx.execute('Email X'))
b = cnx.entity_from_eid(self.b)
self.assertTrue(b.reverse_comments)
c = b.reverse_comments[0]
self.assertEqual(c.content_format, 'text/plain')
self.assertEqual(c.content, u'''New ticket for project erudi-email :
#22742 - erudi-email #22742: commentaires de mailbot
====================
......@@ -176,8 +187,8 @@ URL
---
http://intranet.logilab.fr/jpl/ticket/22742
(project URL: http://intranet.logilab.fr/jpl/project/erudi-email)''')
self.failUnlessEqual(c.creator.login, 'anon')
self.failUnlessEqual(sorted(u.login for u in c.owned_by),
self.assertEqual(c.creator.login, 'anon')
self.assertEqual(sorted(u.login for u in c.owned_by),
['admin', 'anon'])
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment