equal
deleted
inserted
replaced
17 # You should have received a copy of the GNU Lesser General Public License along |
17 # You should have received a copy of the GNU Lesser General Public License along |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
19 """unit tests for modules cubicweb.server.querier and cubicweb.server.ssplanner |
19 """unit tests for modules cubicweb.server.querier and cubicweb.server.ssplanner |
20 """ |
20 """ |
21 |
21 |
|
22 from contextlib import contextmanager |
22 from datetime import date, datetime, timedelta, tzinfo |
23 from datetime import date, datetime, timedelta, tzinfo |
23 import unittest |
24 import unittest |
24 |
25 |
25 import pytz |
26 import pytz |
26 |
27 |
1665 cnx.execute('SET U use_email A WHERE U login "admin", A eid < %s' % a2.eid) |
1666 cnx.execute('SET U use_email A WHERE U login "admin", A eid < %s' % a2.eid) |
1666 self.assertEqual( |
1667 self.assertEqual( |
1667 [[a1.eid]], |
1668 [[a1.eid]], |
1668 cnx.execute('Any A ORDERBY A WHERE U use_email A, U login "admin"').rows) |
1669 cnx.execute('Any A ORDERBY A WHERE U use_email A, U login "admin"').rows) |
1669 |
1670 |
|
1671 def test_computed_relation_in_write_queries(self): |
|
1672 """Computed relations are not allowed in main part of write queries.""" |
|
1673 @contextmanager |
|
1674 def check(cnx): |
|
1675 with self.assertRaises(QueryError) as cm: |
|
1676 yield |
|
1677 self.assertIn("'user_login' is a computed relation", |
|
1678 str(cm.exception)) |
|
1679 cnx.rollback() |
|
1680 |
|
1681 with self.admin_access.cnx() as cnx: |
|
1682 person = cnx.create_entity('Personne', nom=u'p') |
|
1683 cnx.commit() |
|
1684 # create |
|
1685 with check(cnx): |
|
1686 cnx.execute('INSERT CWUser X: X login "user", X user_login P' |
|
1687 ' WHERE P is Personne, P nom "p"') |
|
1688 # update |
|
1689 bob = self.create_user(cnx, u'bob') |
|
1690 with check(cnx): |
|
1691 cnx.execute('SET U user_login P WHERE U login "bob", P nom "p"') |
|
1692 # delete |
|
1693 person.cw_set(login_user=bob) |
|
1694 cnx.commit() |
|
1695 with check(cnx): |
|
1696 cnx.execute('DELETE U user_login P WHERE U login "bob"') |
|
1697 |
|
1698 |
1670 if __name__ == '__main__': |
1699 if __name__ == '__main__': |
1671 unittest.main() |
1700 unittest.main() |