server/test/unittest_postgres.py
changeset 11034 75d752e6daf7
parent 10812 a747e211266b
equal deleted inserted replaced
11033:63d860a14a17 11034:75d752e6daf7
   125                 cnx.commit()
   125                 cnx.commit()
   126                 self.assertEqual(cnx.execute('Any X ORDERBY FTIRANK(X) DESC '
   126                 self.assertEqual(cnx.execute('Any X ORDERBY FTIRANK(X) DESC '
   127                                              'WHERE X has_text "cubicweb"').rows,
   127                                              'WHERE X has_text "cubicweb"').rows,
   128                                   [[c1.eid,], [c3.eid,], [c2.eid,]])
   128                                   [[c1.eid,], [c3.eid,], [c2.eid,]])
   129 
   129 
   130 
       
   131     def test_tz_datetime(self):
   130     def test_tz_datetime(self):
   132         with self.admin_access.repo_cnx() as cnx:
   131         with self.admin_access.repo_cnx() as cnx:
   133             cnx.execute("INSERT Personne X: X nom 'bob', X tzdatenaiss %(date)s",
   132             bob = cnx.create_entity('Personne', nom=u'bob',
   134                         {'date': datetime(1977, 6, 7, 2, 0, tzinfo=FixedOffset(1))})
   133                                    tzdatenaiss=datetime(1977, 6, 7, 2, 0, tzinfo=FixedOffset(1)))
   135             datenaiss = cnx.execute("Any XD WHERE X nom 'bob', X tzdatenaiss XD")[0][0]
   134             datenaiss = cnx.execute("Any XD WHERE X nom 'bob', X tzdatenaiss XD")[0][0]
   136             self.assertEqual(datenaiss.tzinfo, None)
   135             self.assertIsNotNone(datenaiss.tzinfo)
   137             self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 1, 0))
   136             self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 1, 0))
   138             cnx.commit()
   137             cnx.commit()
   139             cnx.execute("INSERT Personne X: X nom 'boby', X tzdatenaiss %(date)s",
   138             cnx.create_entity('Personne', nom=u'boby',
   140                         {'date': datetime(1977, 6, 7, 2, 0)})
   139                               tzdatenaiss=datetime(1977, 6, 7, 2, 0))
   141             datenaiss = cnx.execute("Any XD WHERE X nom 'boby', X tzdatenaiss XD")[0][0]
   140             datenaiss = cnx.execute("Any XD WHERE X nom 'boby', X tzdatenaiss XD")[0][0]
   142             self.assertEqual(datenaiss.tzinfo, None)
   141             self.assertIsNotNone(datenaiss.tzinfo)
   143             self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0))
   142             self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0))
       
   143             rset = cnx.execute("Any X WHERE X tzdatenaiss %(d)s",
       
   144                                {'d': datetime(1977, 6, 7, 2, 0, tzinfo=FixedOffset(1))})
       
   145             self.assertEqual(rset.rows, [[bob.eid]])
   144 
   146 
   145     def test_constraint_validationerror(self):
   147     def test_constraint_validationerror(self):
   146         with self.admin_access.repo_cnx() as cnx:
   148         with self.admin_access.repo_cnx() as cnx:
   147             with cnx.allow_all_hooks_but('integrity'):
   149             with cnx.allow_all_hooks_but('integrity'):
   148                 with self.assertRaises(ValidationError) as cm:
   150                 with self.assertRaises(ValidationError) as cm: