Newer
Older
from cubicweb.web.views import actions
from cubes.comment import views
Sylvain Thénault
committed
def setup_database(self):
req = self.request()
self.b = req.create_entity('BlogEntry', title=u"yo", content=u"qu\'il est beau")
self.assertEqual(self.schema['comments'].rdef('Comment', 'BlogEntry').composite,
def test_possible_views(self):
# comment primary view priority
Sylvain Thénault
committed
rset = req.create_entity('Comment', content=u"bouh!", comments=self.b).as_rset()
self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
self.assertIsInstance(self.vreg['views'].select('tree', req, rset=rset),
Sylvain Thénault
committed
req.create_entity('Comment', content=u"bouh!", comments=self.b)
rset = req.execute('Any X WHERE X is BlogEntry')
actions = self.pactions(req, rset)
self.assertTrue(('reply_comment', views.AddCommentAction) in actions)
self.assertFalse(('edit_comment', views.EditCommentAction) in actions)
rset = req.execute('Any X WHERE X is Comment')
actions = self.pactions(req, rset)
self.assertTrue(('reply_comment', views.ReplyCommentAction) in actions)
self.assertTrue(('edit_comment', views.EditCommentAction) in actions)
req = self.request()
rset = req.execute('Any X WHERE X is Comment')
actions = self.pactions(req, rset)
self.assertTrue(('reply_comment', views.ReplyCommentAction) in actions)
self.assertFalse(('edit_comment', views.EditCommentAction) in actions)
rset = self.execute('INSERT Comment X: X content "ho bah non!", X comments B WHERE B is Comment')
cnx.commit()
self.assertTrue(('reply_comment', views.ReplyCommentAction) in actions)
self.assertTrue(('edit_comment', views.EditCommentAction) in actions)
req = self.request()
rset = req.execute('Any X WHERE X is Comment')
self.assertEqual(self.pactions(req, rset), [])
cnx.rollback()
def test_nonregr_possible_actions(self):
Sylvain Thénault
committed
req.create_entity('Comment', content=u"bouh!", comments=self.b)
req.create_entity('Comment', content=u"Yooo!", comments=self.b)
# now two comments are commenting the blog
rset = self.b.related('comments', 'object')
self.assertEqual(len(rset), 2)
self.assertTrue(self.vreg['actions'].select('reply_comment', req, rset=rset, row=0))
self.assertTrue(self.vreg['actions'].select('reply_comment', req, rset=rset, row=1))
Sylvain Thénault
committed
req.create_entity('Comment', content=u"bouh!", comments=self.b)
self.assertEqual(self.pactions_by_cats(req, rset), [])
self.assertEqual(self.pactions_by_cats(req, rset), [])
self.assertEqual(self.pactions_by_cats(req, rset), [])
Sylvain Thénault
committed
req = self.request()
c1 = req.create_entity('Comment', content=u"oijzr", comments=self.b)
itreec1 = c1.cw_adapt_to('ITree')
Sylvain Thénault
committed
c11 = req.create_entity('Comment', content=u"duh?", comments=c1)
itreec11 = c11.cw_adapt_to('ITree')
self.assertEqual(itreec1.path(), [self.b.eid, c1.eid])
self.assertEqual(itreec1.root().eid, self.b.eid)
self.assertEqual(itreec11.path(), [self.b.eid, c1.eid, c11.eid])
self.assertEqual(itreec11.root().eid, self.b.eid)
Sylvain Thénault
committed
def test_comments_ascending_order(self):
Sylvain Thénault
committed
req = self.request()
c1 = req.create_entity('Comment', content=u"one", comments=self.b)
c11 = req.create_entity('Comment', content=u"one-one", comments=c1)
c12 = req.create_entity('Comment', content=u"one-two", comments=c1)
c2 = req.create_entity('Comment', content=u"two", comments=self.b)
self.assertEqual([c.eid for c in self.b.reverse_comments],
Sylvain Thénault
committed
[c1.eid, c2.eid])
self.assertEqual([c.eid for c in c1.cw_adapt_to('ITree').children()],
Sylvain Thénault
committed
[c11.eid, c12.eid])
def test_subcomments_count(self):
req = self.request()
c1 = req.create_entity('Comment', content=u"one", comments=self.b)
c11 = req.create_entity('Comment', content=u"one-one", comments=c1)
c12 = req.create_entity('Comment', content=u"one-two", comments=c1)
c21 = req.create_entity('Comment', content=u"two-one", comments=c12)
Sylvain Thénault
committed
Sylvain Thénault
committed
req = self.request()
c = req.create_entity('Comment', content=u"bouh!", comments=self.b)
c2 = req.create_entity('Comment', content=u"""
some long <b>HTML</b> text which <em>should not</em> fit on 80 characters, so i'll add some extra xxxxxxx.
Sylvain Thénault
committed
Yeah !""", content_format=u"text/html", comments=c)
self.commit() # needed to set author
content = c2.view('fullthreadtext')
# remove date
content = re.sub('..../../.. ..:..', '', content)
"""\
> On - admin wrote :
> bouh!
some long **HTML** text which _should not_ fit on 80 characters, so i'll add
some extra xxxxxxx. Yeah !
i18n_by_author_field: admin
url: http://testing.fr/cubicweb/blogentry/%s""" % self.b.eid)
# fullthreadtext_descending view
self.assertMultiLineEqual('''On - admin wrote :
bouh!
> On - admin wrote :
> some long **HTML** text which _should not_ fit on 80 characters, so i\'ll add
> some extra xxxxxxx. Yeah !
>
''',
re.sub('..../../.. ..:..', '', c.view('fullthreadtext_descending')))
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()