cubicweb/server/test/unittest_postgres.py
changeset 11077 09be48c01fa4
parent 11057 0b59724cb3f2
child 11257 dede32213426
equal deleted inserted replaced
11076:403a901b6b1e 11077:09be48c01fa4
   167 
   167 
   168     def test(self):
   168     def test(self):
   169         with self.admin_access.repo_cnx() as cnx:
   169         with self.admin_access.repo_cnx() as cnx:
   170             def sql(string):
   170             def sql(string):
   171                 return cnx.system_sql(string).fetchone()[0]
   171                 return cnx.system_sql(string).fetchone()[0]
   172             yield self.assertEqual, sql("SELECT limit_size('<p>hello</p>', 'text/html', 20)"), \
   172             for html, size, expected in [
   173                 '<p>hello</p>'
   173                 ('<p>hello</p>', 20, '<p>hello</p>'),
   174             yield self.assertEqual, sql("SELECT limit_size('<p>hello</p>', 'text/html', 2)"), \
   174                 ('<p>hello</p>', 2, 'he...'),
   175                 'he...'
   175                 ('<br/>hello', 2, 'he...'),
   176             yield self.assertEqual, sql("SELECT limit_size('<br/>hello', 'text/html', 2)"), \
   176                 ('<span class=\"1\">he</span>llo', 2, 'he...'),
   177                 'he...'
   177                 ('<span>a>b</span>', 2, 'a>...'),
   178             yield self.assertEqual, sql("SELECT limit_size('<span class=\"1\">he</span>llo', 'text/html', 2)"), \
   178             ]:
   179                 'he...'
   179                 with self.subTest(html=html, size=size):
   180             yield self.assertEqual, sql("SELECT limit_size('<span>a>b</span>', 'text/html', 2)"), \
   180                     actual = sql("SELECT limit_size('%s', 'text/html', %d)" % (html, size))
   181                 'a>...'
   181                     self.assertEqual(actual, expected)
   182 
   182 
   183 
   183 
   184 if __name__ == '__main__':
   184 if __name__ == '__main__':
   185     from logilab.common.testlib import unittest_main
   185     from logilab.common.testlib import unittest_main
   186     unittest_main()
   186     unittest_main()