Commit 5915c891 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

update test

parent efd84d0014c3
# -*- coding: iso-8859-1 -*-
from logilab.common.testlib import unittest_main
from cubicweb.devtools.apptest import EnvBasedTC
from socket import gethostname
from StringIO import StringIO
from cubicweb.sobjects.notification import construct_message_id
from logilab.common.testlib import unittest_main
from cubicweb.devtools.apptest import EnvBasedTC
from cubicweb.common.mail import construct_message_id
MSG = u'''From sthenault@free.fr Tue Jan 23 15:21:10 2007
Return-Path: <sthenault@free.fr>
......@@ -47,8 +48,8 @@ class ChangeStateHooksTC(EnvBasedTC):
def test_email_change_state(self):
u = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G, X in_state S '
'WHERE G name "users", S name "activated"').get_entity(0, 0)
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,'
......@@ -62,8 +63,8 @@ class ChangeStateHooksTC(EnvBasedTC):
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, X in_state S '
'WHERE G name "users", S name "activated"').get_entity(0, 0)
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,'
......@@ -76,8 +77,8 @@ class ChangeStateHooksTC(EnvBasedTC):
self.assertEquals(u.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, X in_state S '
'WHERE G name "users", S name "activated"')[0][0]
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,'
......@@ -87,10 +88,10 @@ class ChangeStateHooksTC(EnvBasedTC):
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid}, 'x')[0][0]
self.assertEquals(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, X in_state S '
'WHERE G name "users", S name "activated"')[0][0]
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,'
......@@ -102,8 +103,8 @@ class ChangeStateHooksTC(EnvBasedTC):
self.assertEquals(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, X in_state S '
'WHERE G name "users", S name "activated"')[0][0]
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,'
......@@ -113,7 +114,7 @@ class ChangeStateHooksTC(EnvBasedTC):
userstate = self.execute('Any SN WHERE X in_state S, S name SN, X eid %(x)s',
{'x': ueid}, 'x')[0][0]
self.assertEquals(userstate, 'activated')
MSG2 = u'''MIME-Version: 1.0
......@@ -147,7 +148,7 @@ class ReplyCommentHooksTC(EnvBasedTC):
self.execute('SET X use_email E WHERE X login "anon", E eid %(e)s', {'e': e.eid})
def test_comment_created(self):
mi = MBOXImporter(self.cursor(), self.schema)
mi = MBOXImporter(self.env.cnx)
msg = open('data/reply.mbox', 'rb').read() % \
construct_message_id(self.vreg.config.appid, self.b.eid, False)
mi.import_mbox_stream(StringIO(msg))
......
......@@ -12,8 +12,7 @@ from cubes.email.mboximport import MBOXImporter
class MBOXImporterTC(EnvBasedTC):
def test_all(self):
cursor = self.cursor()
mi = MBOXImporter(cursor, self.schema)
mi = MBOXImporter(self.env.cnx)
mi.import_mbox_stream(open('data/mbox'))
self.assertEquals(sorted([(x, len(y)) for x, y in mi.created.items()]),
[('email', 2), ('emailaddress', 4),
......@@ -28,10 +27,10 @@ class MBOXImporterTC(EnvBasedTC):
self.assertEquals([r.address for r in email.recipients], ['python-projects@logilab.org'])
self.assertEquals([r.address for r in email.cc], [])
self.assertEquals(email.in_thread[0].title, '[Python-projects] Pylint: Disable-msg for a block or statement?')
self.assertEquals(sorted([(f.name, f.data_format) for f in email.attachment]),
self.assertEquals(sorted([(f.data_name, f.data_format) for f in email.attachment]),
[(u'astng.patch', u'text/x-diff'), (u'pylint.patch', u'text/x-diff')])
assert not self.vreg.schema['parts'].inlined
self.assertEquals(len(cursor.execute('Any P WHERE E parts P, E eid %s'%email.eid)), 2)
self.assertEquals(len(self.execute('Any P WHERE E parts P, E eid %s'%email.eid)), 2)
self.assertEquals(len(email.parts), 2)
part1, part2 = email.parts_in_order()
self.assertEquals(part1.content_format,'text/plain')
......@@ -48,7 +47,7 @@ http://lists.logilab.org/mailman/listinfo/python-projects''')
self.assertEquals([r.address for r in email.recipients], ['python-projects@lists.logilab.org'])
self.assertEquals([r.address for r in email.cc], [])
self.assertEquals(email.in_thread[0].title, '[Python-projects] pylint: False positive about field initialisation')
self.assertEquals([(f.name, f.data_format) for f in email.attachment], [])
self.assertEquals([(f.data_name, f.data_format) for f in email.attachment], [])
self.assertEquals(len(email.parts), 3)
self.assertEquals(sorted([r.content_format for r in email.parts]), [u'text/html', u'text/plain', u'text/plain'])
part1, part2 = email.parts_in_order()
......@@ -175,8 +174,7 @@ http://lists.logilab.org/mailman/listinfo/python-projects
"""
def test_no_subject(self):
cu = self.env.cnx.cursor() # don't use self.cursor() to have no request set
mi = MBOXImporter(cu, self.schema)
mi = MBOXImporter(self.env.cnx)
mi.import_mbox_stream(StringIO(self.NOSUBJECT))
rset = self.execute('Any X ORDERBY S WHERE X is Email, X subject S')
self.assertEquals(len(rset), 1)
......@@ -185,8 +183,7 @@ http://lists.logilab.org/mailman/listinfo/python-projects
self.assertEquals(email.references(), set(('<xxx@blabla>',)))
def test_double_import(self):
cu = self.env.cnx.cursor() # don't use self.cursor() to have no request set
mi = MBOXImporter(cu, self.schema)
mi = MBOXImporter(self.env.cnx)
mi.import_mbox_stream(StringIO(self.NOSUBJECT))
mi.import_mbox_stream(StringIO(self.NOSUBJECT))
rset = self.execute('Any X ORDERBY S WHERE X is Email, X subject S')
......@@ -206,8 +203,7 @@ http://lists.logilab.org/mailman/listinfo/python-projects
#self.assertEquals(testrset[0][0], eid2)
#testrset = cursor.execute('Any X WHERE X identical_to Y, X canonical TRUE, Y eid %(y)s', {'y': eid1})
#self.assertEquals(testrset[0][0], eid2)
cu = self.env.cnx.cursor() # don't use self.cursor() to have no request set
mi = MBOXImporter(cu, self.schema)
mi = MBOXImporter(self.env.cnx)
mi.import_mbox_stream(StringIO(self.NOSUBJECT))
rset = self.execute('Any X ORDERBY S WHERE X is Email, X subject S')
self.assertEquals(len(rset), 1)
......
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