20 from datetime import datetime |
20 from datetime import datetime |
21 from threading import Thread |
21 from threading import Thread |
22 |
22 |
23 from logilab.common.testlib import SkipTest |
23 from logilab.common.testlib import SkipTest |
24 |
24 |
|
25 from cubicweb import ValidationError |
25 from cubicweb.devtools import PostgresApptestConfiguration, startpgcluster, stoppgcluster |
26 from cubicweb.devtools import PostgresApptestConfiguration, startpgcluster, stoppgcluster |
26 from cubicweb.devtools.testlib import CubicWebTC |
27 from cubicweb.devtools.testlib import CubicWebTC |
27 from cubicweb.predicates import is_instance |
28 from cubicweb.predicates import is_instance |
28 from cubicweb.entities.adapters import IFTIndexableAdapter |
29 from cubicweb.entities.adapters import IFTIndexableAdapter |
29 |
30 |
121 {'date': datetime(1977, 6, 7, 2, 0)}) |
122 {'date': datetime(1977, 6, 7, 2, 0)}) |
122 datenaiss = cnx.execute("Any XD WHERE X nom 'boby', X tzdatenaiss XD")[0][0] |
123 datenaiss = cnx.execute("Any XD WHERE X nom 'boby', X tzdatenaiss XD")[0][0] |
123 self.assertEqual(datenaiss.tzinfo, None) |
124 self.assertEqual(datenaiss.tzinfo, None) |
124 self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0)) |
125 self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0)) |
125 |
126 |
|
127 def test_constraint_validationerror(self): |
|
128 with self.admin_access.repo_cnx() as cnx: |
|
129 with cnx.allow_all_hooks_but('integrity'): |
|
130 with self.assertRaises(ValidationError) as cm: |
|
131 cnx.execute("INSERT Note N: N type 'nogood'") |
|
132 self.assertEqual(cm.exception.errors, |
|
133 {'type-subject': u'invalid value %(KEY-value)s, it must be one of %(KEY-choices)s'}) |
|
134 self.assertEqual(cm.exception.msgargs, |
|
135 {'type-subject-value': u'"nogood"', |
|
136 'type-subject-choices': u'"todo", "a", "b", "T", "lalala"'}) |
|
137 |
|
138 |
126 class PostgresLimitSizeTC(CubicWebTC): |
139 class PostgresLimitSizeTC(CubicWebTC): |
127 configcls = PostgresApptestConfiguration |
140 configcls = PostgresApptestConfiguration |
128 |
141 |
129 def test(self): |
142 def test(self): |
130 with self.admin_access.repo_cnx() as cnx: |
143 with self.admin_access.repo_cnx() as cnx: |
139 yield self.assertEqual, sql("SELECT limit_size('<span class=\"1\">he</span>llo', 'text/html', 2)"), \ |
152 yield self.assertEqual, sql("SELECT limit_size('<span class=\"1\">he</span>llo', 'text/html', 2)"), \ |
140 'he...' |
153 'he...' |
141 yield self.assertEqual, sql("SELECT limit_size('<span>a>b</span>', 'text/html', 2)"), \ |
154 yield self.assertEqual, sql("SELECT limit_size('<span>a>b</span>', 'text/html', 2)"), \ |
142 'a>...' |
155 'a>...' |
143 |
156 |
|
157 |
144 if __name__ == '__main__': |
158 if __name__ == '__main__': |
145 from logilab.common.testlib import unittest_main |
159 from logilab.common.testlib import unittest_main |
146 unittest_main() |
160 unittest_main() |