web/test/unittest_views_basecontrollers.py
author Rémi Cardona <remi.cardona@logilab.fr>
Mon, 21 Sep 2015 17:54:15 +0200
changeset 10721 e9abbaa835f5
parent 10704 73367a56ee41
child 10728 48c6de7321d8
permissions -rw-r--r--
[tests] Port unittest_cwctl to py3k On python 2, sys.stdout takes bytes-like objects whereas python 3's takes unicode-like objects and handles the encoding on its own.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    18
"""cubicweb.web.views.basecontrollers unit tests"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
10603
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10587
diff changeset
    20
from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin, parse_qs
10016
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    21
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    22
import lxml
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    23
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    24
from logilab.common.testlib import unittest_main
10016
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    25
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    26
from logilab.common.decorators import monkeypatch
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
2559
46859078c866 [R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2058
diff changeset
    28
from cubicweb import Binary, NoSelectableObject, ValidationError
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
    29
from cubicweb.schema import RRQLExpression
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    30
from cubicweb.devtools.testlib import CubicWebTC
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    31
from cubicweb.utils import json_dumps
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    32
from cubicweb.uilib import rql_for_eid
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    33
from cubicweb.web import Redirect, RemoteCallFailed
8812
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
    34
import cubicweb.server.session
9020
cb87e831c183 rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
    35
from cubicweb.server.session import Connection as OldConnection
4390
0285c1fa1459 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4389
diff changeset
    36
from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    37
from cubicweb.web.views.basecontrollers import JSonController, xhtmlize, jsonize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    38
from cubicweb.web.views.ajaxcontroller import ajaxfunc, AjaxFunction
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
    39
import cubicweb.transaction as tx
9184
b982e88e4836 [repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents: 9179
diff changeset
    40
from cubicweb.server.hook import Hook, Operation
b982e88e4836 [repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents: 9179
diff changeset
    41
from cubicweb.predicates import is_instance
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    42
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    43
def req_form(user):
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    44
    return {'eid': [str(user.eid)],
7584
e1881933f366 [form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7442
diff changeset
    45
            '_cw_entity_fields:%s' % user.eid: '_cw_generic_field',
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    46
            '__type:%s' % user.eid: user.__regid__
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    47
            }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    49
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    50
class EditControllerTC(CubicWebTC):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    51
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    def setUp(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    53
        CubicWebTC.setUp(self)
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9478
diff changeset
    54
        self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read'))
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    55
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    def tearDown(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    57
        CubicWebTC.tearDown(self)
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9478
diff changeset
    58
        self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read'))
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    59
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
    def test_noparam_edit(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        """check behaviour of this controller without any form parameter
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    63
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    64
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    65
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    66
            self.assertEqual(cm.exception.errors, {None: u'no selected entities'})
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    67
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    def test_validation_unique(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        """test creation of two linked entities
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    70
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    71
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    72
            req.form = {'eid': 'X', '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    73
                        '_cw_entity_fields:X': 'login-subject,upassword-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    74
                        'login-subject:X': u'admin',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    75
                        'upassword-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    76
                        'upassword-subject-confirm:X': u'toto',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    77
                    }
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    78
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    79
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    80
                cm.exception.translate(unicode)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    81
                self.assertEqual({'login-subject': 'the value "admin" is already used, use another one'},
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    82
                                 cm.exception.errors)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
10016
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    84
    def test_simultaneous_edition_only_one_commit(self):
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    85
        """ Allow two simultaneous edit view of the same entity as long as only one commits
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    86
        """
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    87
        with self.admin_access.web_request() as req:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    88
            e = req.create_entity('BlogEntry', title=u'cubicweb.org', content=u"hop")
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    89
            expected_path = e.rest_path()
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    90
            req.cnx.commit()
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    91
            form = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    92
            html_form = lxml.html.fromstring(form.render(w=None, action='edit')).forms[0]
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    93
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    94
        with self.admin_access.web_request() as req2:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    95
            form2 = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    96
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    97
        with self.admin_access.web_request(**dict(html_form.form_values())) as req:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    98
            path, args = self.expect_redirect_handle_request(req, path='edit')
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    99
            self.assertEqual(path, expected_path)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   100
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   101
    def test_simultaneous_edition_refuse_second_commit(self):
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   102
        """ Disallow committing changes to an entity edited in between """
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   103
        with self.admin_access.web_request() as req:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   104
            e = req.create_entity('BlogEntry', title=u'cubicweb.org', content=u"hop")
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   105
            eid = e.eid
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   106
            req.cnx.commit()
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   107
            form = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   108
            html_form = lxml.html.fromstring(form.render(w=None, action='edit')).forms[0]
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   109
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   110
        with self.admin_access.web_request() as req2:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   111
            e = req2.entity_from_eid(eid)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   112
            e.cw_set(content = u"hip")
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   113
            req2.cnx.commit()
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   114
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   115
        form_field_name = "content-subject:%d" % eid
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   116
        form_values = dict(html_form.form_values())
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   117
        assert form_field_name in form_values
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   118
        form_values[form_field_name] = u'yep'
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   119
        with self.admin_access.web_request(**form_values) as req:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   120
            with self.assertRaises(ValidationError) as cm:
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   121
                self.ctrl_publish(req)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   122
            reported_eid, dict_info = cm.exception.args
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   123
            self.assertEqual(reported_eid, eid)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   124
            self.assertIn(None, dict_info)
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   125
            self.assertIn("has changed since you started to edit it.", dict_info[None])
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   126
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
    def test_user_editing_itself(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
        """checking that a manager user can edit itself
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   130
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   131
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   132
            groupeids = [eid for eid, in req.execute('CWGroup G WHERE G name '
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   133
                                                     'in ("managers", "users")')]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   134
            groups = [unicode(eid) for eid in groupeids]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   135
            eid = unicode(user.eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   136
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   137
                'eid': eid, '__type:'+eid: 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   138
                '_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject,in_group-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   139
                'login-subject:'+eid:     unicode(user.login),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   140
                'surname-subject:'+eid: u'Th\xe9nault',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   141
                'firstname-subject:'+eid:   u'Sylvain',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   142
                'in_group-subject:'+eid:  groups,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   143
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   144
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   145
            e = req.execute('Any X WHERE X eid %(x)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   146
                            {'x': user.eid}).get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   147
            self.assertEqual(e.firstname, u'Sylvain')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   148
            self.assertEqual(e.surname, u'Th\xe9nault')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   149
            self.assertEqual(e.login, user.login)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   150
            self.assertEqual([g.eid for g in e.in_group], groupeids)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
    def test_user_can_change_its_password(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   153
        with self.admin_access.repo_cnx() as cnx:
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   154
            self.create_user(cnx, u'user')
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   155
            cnx.commit()
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   156
        with self.new_access(u'user').web_request() as req:
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   157
            eid = unicode(req.user.eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   158
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   159
                'eid': eid, '__maineid' : eid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   160
                '__type:'+eid: 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   161
                '_cw_entity_fields:'+eid: 'upassword-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   162
                'upassword-subject:'+eid: 'tournicoton',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   163
                'upassword-subject-confirm:'+eid: 'tournicoton',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   164
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   165
            path, params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   166
            req.cnx.commit() # commit to check we don't get late validation error for instance
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   167
            self.assertEqual(path, 'cwuser/user')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   168
            self.assertNotIn('vid', params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   170
    def test_user_editing_itself_no_relation(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        """checking we can edit an entity without specifying some required
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        relations (meaning no changes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   174
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   175
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   176
            groupeids = [g.eid for g in user.in_group]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   177
            eid = unicode(user.eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   178
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   179
                'eid':       eid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   180
                '__type:'+eid:    'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   181
                '_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   182
                'login-subject:'+eid:     unicode(user.login),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   183
                'firstname-subject:'+eid: u'Th\xe9nault',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   184
                'surname-subject:'+eid:   u'Sylvain',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   185
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   186
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   187
            e = req.execute('Any X WHERE X eid %(x)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   188
                            {'x': user.eid}).get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   189
            self.assertEqual(e.login, user.login)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   190
            self.assertEqual(e.firstname, u'Th\xe9nault')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   191
            self.assertEqual(e.surname, u'Sylvain')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   192
            self.assertEqual([g.eid for g in e.in_group], groupeids)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   193
            self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   194
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   195
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
    def test_create_multiple_linked(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   197
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   198
            gueid = req.execute('CWGroup G WHERE G name "users"')[0][0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   199
            req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   200
                        '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   201
                        '_cw_entity_fields:X': 'login-subject,upassword-subject,surname-subject,in_group-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   202
                        'login-subject:X': u'adim',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   203
                        'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   204
                        'surname-subject:X': u'Di Mascio',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   205
                        'in_group-subject:X': unicode(gueid),
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   206
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   207
                        '__type:Y': 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   208
                        '_cw_entity_fields:Y': 'address-subject,use_email-object',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   209
                        'address-subject:Y': u'dima@logilab.fr',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   210
                        'use_email-object:Y': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   211
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   212
            path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   213
            # should be redirected on the created person
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   214
            self.assertEqual(path, 'cwuser/adim')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   215
            e = req.execute('Any P WHERE P surname "Di Mascio"').get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   216
            self.assertEqual(e.surname, 'Di Mascio')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   217
            email = e.use_email[0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   218
            self.assertEqual(email.address, 'dima@logilab.fr')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   219
9179
570208f74a84 [editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   220
    def test_create_mandatory_inlined(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   221
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   222
            req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
9179
570208f74a84 [editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   223
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   224
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   225
                        '_cw_entity_fields:X': '',
9179
570208f74a84 [editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   226
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   227
                        '__type:Y': 'File',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   228
                        '_cw_entity_fields:Y': 'data-subject,described_by_test-object',
10704
73367a56ee41 [py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
   229
                        'data-subject:Y': (u'coucou.txt', Binary(b'coucou')),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   230
                        'described_by_test-object:Y': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   231
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   232
            path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   233
            self.assertTrue(path.startswith('salesterm/'), path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   234
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   235
            salesterm = req.entity_from_eid(eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   236
            # The NOT NULL constraint of mandatory relation implies that the File
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   237
            # must be created before the Salesterm, otherwise Salesterm insertion
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   238
            # will fail.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   239
            # NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   240
            # insertion does not fail and we have to check dumbly that File is
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   241
            # created before.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   242
            self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid)
9179
570208f74a84 [editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   243
9196
13461cb8ff40 [editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9184
diff changeset
   244
    def test_create_mandatory_inlined2(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   245
        with self.admin_access.web_request() as req:
9213
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   246
            req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   247
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   248
                        '__type:X': 'Salesterm',
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   249
                        '_cw_entity_fields:X': 'described_by_test-subject',
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   250
                        'described_by_test-subject:X': 'Y',
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   251
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   252
                        '__type:Y': 'File',
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   253
                        '_cw_entity_fields:Y': 'data-subject',
10704
73367a56ee41 [py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
   254
                        'data-subject:Y': (u'coucou.txt', Binary(b'coucou')),
9213
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   255
                        }
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   256
            path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   257
            self.assertTrue(path.startswith('salesterm/'), path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   258
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   259
            salesterm = req.entity_from_eid(eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   260
            # The NOT NULL constraint of mandatory relation implies that the File
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   261
            # must be created before the Salesterm, otherwise Salesterm insertion
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   262
            # will fail.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   263
            # NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   264
            # insertion does not fail and we have to check dumbly that File is
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   265
            # created before.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   266
            self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   267
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   268
    def test_edit_mandatory_inlined3_object(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   269
        # non regression test for #3120495. Without the fix, leads to
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   270
        # "unhashable type: 'list'" error
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   271
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   272
            cwrelation = unicode(req.execute('CWEType X WHERE X name "CWSource"')[0][0])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   273
            req.form = {'eid': [cwrelation], '__maineid' : cwrelation,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   274
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   275
                        '__type:'+cwrelation: 'CWEType',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   276
                        '_cw_entity_fields:'+cwrelation: 'to_entity-object',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   277
                        'to_entity-object:'+cwrelation: [9999, 9998],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   278
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   279
            with req.cnx.deny_all_hooks_but():
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   280
                path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   281
            self.assertTrue(path.startswith('cwetype/CWSource'), path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   282
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   283
    def test_edit_multiple_linked(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   284
        with self.admin_access.web_request() as req:
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   285
            peid = unicode(self.create_user(req, u'adim').eid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   286
            req.form = {'eid': [peid, 'Y'], '__maineid': peid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   287
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   288
                        '__type:'+peid: u'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   289
                        '_cw_entity_fields:'+peid: u'surname-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   290
                        'surname-subject:'+peid: u'Di Masci',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   291
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   292
                        '__type:Y': u'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   293
                        '_cw_entity_fields:Y': u'address-subject,use_email-object',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   294
                        'address-subject:Y': u'dima@logilab.fr',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   295
                        'use_email-object:Y': peid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   296
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   297
            path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   298
            # should be redirected on the created person
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   299
            self.assertEqual(path, 'cwuser/adim')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   300
            e = req.execute('Any P WHERE P surname "Di Masci"').get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   301
            email = e.use_email[0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   302
            self.assertEqual(email.address, 'dima@logilab.fr')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   303
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   304
        # with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   305
            emaileid = unicode(email.eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   306
            req.form = {'eid': [peid, emaileid],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   307
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   308
                        '__type:'+peid: u'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   309
                        '_cw_entity_fields:'+peid: u'surname-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   310
                        'surname-subject:'+peid: u'Di Masci',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   311
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   312
                        '__type:'+emaileid: u'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   313
                        '_cw_entity_fields:'+emaileid: u'address-subject,use_email-object',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   314
                        'address-subject:'+emaileid: u'adim@logilab.fr',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   315
                        'use_email-object:'+emaileid: peid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   316
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   317
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   318
            email.cw_clear_all_caches()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   319
            self.assertEqual(email.address, 'adim@logilab.fr')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   320
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   321
    def test_password_confirm(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   322
        """test creation of two linked entities
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   323
        """
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   324
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   325
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   326
            req.form = {'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   327
                        '__cloned_eid:X': unicode(user.eid), '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   328
                        '_cw_entity_fields:X': 'login-subject,upassword-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   329
                        'login-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   330
                        'upassword-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   331
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   332
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   333
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   334
            self.assertEqual({'upassword-subject': u'password and confirmation don\'t match'},
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   335
                             cm.exception.errors)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   336
            req.form = {'__cloned_eid:X': unicode(user.eid),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   337
                        'eid': 'X', '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   338
                        '_cw_entity_fields:X': 'login-subject,upassword-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   339
                        'login-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   340
                        'upassword-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   341
                        'upassword-subject-confirm:X': u'tutu',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   342
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   343
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   344
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   345
            self.assertEqual({'upassword-subject': u'password and confirmation don\'t match'},
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   346
                             cm.exception.errors)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   347
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   348
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   349
    def test_interval_bound_constraint_success(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   350
        with self.admin_access.repo_cnx() as cnx:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   351
            feid = cnx.execute('INSERT File X: X data_name "toto.txt", X data %(data)s',
10704
73367a56ee41 [py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
   352
                               {'data': Binary(b'yo')})[0][0]
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   353
            cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   354
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   355
        with self.admin_access.web_request(rollbackfirst=True) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   356
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   357
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   358
                        '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   359
                        'amount-subject:X': u'-10',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   360
                        'described_by_test-subject:X': unicode(feid),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   361
                    }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   362
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   363
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   364
            cm.exception.translate(unicode)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   365
            self.assertEqual({'amount-subject': 'value -10 must be >= 0'},
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   366
                             cm.exception.errors)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   367
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   368
        with self.admin_access.web_request(rollbackfirst=True) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   369
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   370
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   371
                        '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   372
                        'amount-subject:X': u'110',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   373
                        'described_by_test-subject:X': unicode(feid),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   374
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   375
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   376
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   377
            cm.exception.translate(unicode)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   378
            self.assertEqual(cm.exception.errors, {'amount-subject': 'value 110 must be <= 100'})
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   379
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   380
        with self.admin_access.web_request(rollbackfirst=True) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   381
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   382
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   383
                        '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   384
                        'amount-subject:X': u'10',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   385
                        'described_by_test-subject:X': unicode(feid),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   386
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   387
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   388
            # should be redirected on the created
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   389
            #eid = params['rql'].split()[-1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   390
            e = req.execute('Salesterm X').get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   391
            self.assertEqual(e.amount, 10)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   392
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   393
    def test_interval_bound_constraint_validateform(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   394
        """Test the FormValidatorController controller on entity with
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   395
        constrained attributes"""
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   396
        with self.admin_access.repo_cnx() as cnx:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   397
            feid = cnx.execute('INSERT File X: X data_name "toto.txt", X data %(data)s',
10704
73367a56ee41 [py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
   398
                               {'data': Binary(b'yo')})[0][0]
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   399
            seid = cnx.create_entity('Salesterm', amount=0, described_by_test=feid).eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   400
            cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   401
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   402
        # ensure a value that violate a constraint is properly detected
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   403
        with self.admin_access.web_request(rollbackfirst=True) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   404
            req.form = {'eid': [unicode(seid)],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   405
                        '__type:%s'%seid: 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   406
                        '_cw_entity_fields:%s'%seid: 'amount-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   407
                        'amount-subject:%s'%seid: u'-10',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   408
                    }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   409
            self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   410
 window.parent.handleFormValidationResponse('entityForm', null, null, [false, [%s, {"amount-subject": "value -10 must be >= 0"}], null], null);
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   411
</script>'''%seid, self.ctrl_publish(req, 'validateform'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   412
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   413
        # ensure a value that comply a constraint is properly processed
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   414
        with self.admin_access.web_request(rollbackfirst=True) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   415
            req.form = {'eid': [unicode(seid)],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   416
                        '__type:%s'%seid: 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   417
                        '_cw_entity_fields:%s'%seid: 'amount-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   418
                        'amount-subject:%s'%seid: u'20',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   419
                    }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   420
            self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   421
 window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   422
</script>''', self.ctrl_publish(req, 'validateform'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   423
            self.assertEqual(20, req.execute('Any V WHERE X amount V, X eid %(eid)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   424
                                             {'eid': seid})[0][0])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   425
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   426
        with self.admin_access.web_request(rollbackfirst=True) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   427
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   428
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   429
                        '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   430
                        'amount-subject:X': u'0',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   431
                        'described_by_test-subject:X': unicode(feid),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   432
                    }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   433
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   434
            # ensure a value that is modified in an operation on a modify
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   435
            # hook works as it should (see
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   436
            # https://www.cubicweb.org/ticket/2509729 )
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   437
            class MyOperation(Operation):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   438
                def precommit_event(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   439
                    self.entity.cw_set(amount=-10)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   440
            class ValidationErrorInOpAfterHook(Hook):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   441
                __regid__ = 'valerror-op-after-hook'
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   442
                __select__ = Hook.__select__ & is_instance('Salesterm')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   443
                events = ('after_add_entity',)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   444
                def __call__(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   445
                    MyOperation(self._cw, entity=self.entity)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   446
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   447
            with self.temporary_appobjects(ValidationErrorInOpAfterHook):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   448
                self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   449
 window.parent.handleFormValidationResponse('entityForm', null, null, [false, ["X", {"amount-subject": "value -10 must be >= 0"}], null], null);
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   450
</script>''', self.ctrl_publish(req, 'validateform'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   451
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   452
            self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   453
 window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   454
</script>''', self.ctrl_publish(req, 'validateform'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   455
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   456
    def test_req_pending_insert(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   457
        """make sure req's pending insertions are taken into account"""
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   458
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   459
            tmpgroup = req.create_entity('CWGroup', name=u"test")
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   460
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   461
            req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   462
        with self.admin_access.web_request(**req_form(user)) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   463
            req.session.data['pending_insert'] = set([(user.eid, 'in_group', tmpgroup.eid)])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   464
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   465
            usergroups = [gname for gname, in
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   466
                          req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   467
                                      {'u': user.eid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   468
            self.assertCountEqual(usergroups, ['managers', 'test'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   469
            self.assertEqual(get_pending_inserts(req), [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   470
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   471
    def test_req_pending_delete(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   472
        """make sure req's pending deletions are taken into account"""
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   473
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   474
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   475
            groupeid = req.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   476
                                    {'x': user.eid})[0][0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   477
            usergroups = [gname for gname, in
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   478
                          req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   479
                                      {'u': user.eid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   480
            # just make sure everything was set correctly
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   481
            self.assertCountEqual(usergroups, ['managers', 'test'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   482
            req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   483
            # now try to delete the relation
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   484
        with self.admin_access.web_request(**req_form(user)) as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   485
            req.session.data['pending_delete'] = set([(user.eid, 'in_group', groupeid)])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   486
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   487
            usergroups = [gname for gname, in
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   488
                          req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   489
                                      {'u': user.eid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   490
            self.assertCountEqual(usergroups, ['managers'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   491
            self.assertEqual(get_pending_deletes(req), [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   492
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   493
    def test_redirect_apply_button(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   494
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   495
            redirectrql = rql_for_eid(4012) # whatever
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   496
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   497
                'eid': 'A', '__maineid' : 'A',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   498
                '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   499
                'content-subject:A': u'"13:03:43"',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   500
                'title-subject:A': u'huuu',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   501
                '__redirectrql': redirectrql,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   502
                '__redirectvid': 'primary',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   503
                '__redirectparams': 'toto=tutu&tata=titi',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   504
                '__form_id': 'edition',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   505
                '__action_apply': '',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   506
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   507
            path, params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   508
            self.assertTrue(path.startswith('blogentry/'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   509
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   510
            self.assertEqual(params['vid'], 'edition')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   511
            self.assertNotEqual(int(eid), 4012)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   512
            self.assertEqual(params['__redirectrql'], redirectrql)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   513
            self.assertEqual(params['__redirectvid'], 'primary')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   514
            self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   515
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   516
    def test_redirect_ok_button(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   517
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   518
            redirectrql = rql_for_eid(4012) # whatever
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   519
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   520
                'eid': 'A', '__maineid' : 'A',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   521
                '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   522
                'content-subject:A': u'"13:03:43"',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   523
                'title-subject:A': u'huuu',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   524
                '__redirectrql': redirectrql,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   525
                '__redirectvid': 'primary',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   526
                '__redirectparams': 'toto=tutu&tata=titi',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   527
                '__form_id': 'edition',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   528
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   529
            path, params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   530
            self.assertEqual(path, 'view')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   531
            self.assertEqual(params['rql'], redirectrql)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   532
            self.assertEqual(params['vid'], 'primary')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   533
            self.assertEqual(params['tata'], 'titi')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   534
            self.assertEqual(params['toto'], 'tutu')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   535
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   536
    def test_redirect_delete_button(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   537
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   538
            eid = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   539
            req.form = {'eid': unicode(eid), '__type:%s'%eid: 'BlogEntry',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   540
                        '__action_delete': ''}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   541
            path, params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   542
            self.assertEqual(path, 'blogentry')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   543
            self.assertIn('_cwmsgid', params)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   544
            eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   545
            req.execute('SET X use_email E WHERE E eid %(e)s, X eid %(x)s',
10254
e42c2226c878 [web/test] fix cubicweb 3.19 deprecation warning
Julien Cristau <julien.cristau@logilab.fr>
parents: 10253
diff changeset
   546
                        {'x': req.user.eid, 'e': eid})
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   547
            req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   548
            req.form = {'eid': unicode(eid), '__type:%s'%eid: 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   549
                        '__action_delete': ''}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   550
            path, params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   551
            self.assertEqual(path, 'cwuser/admin')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   552
            self.assertIn('_cwmsgid', params)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   553
            eid1 = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   554
            eid2 = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   555
            req.form = {'eid': [unicode(eid1), unicode(eid2)],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   556
                        '__type:%s'%eid1: 'BlogEntry',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   557
                        '__type:%s'%eid2: 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   558
                        '__action_delete': ''}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   559
            path, params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   560
            self.assertEqual(path, 'view')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   561
            self.assertIn('_cwmsgid', params)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   562
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   563
    def test_simple_copy(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   564
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   565
            blog = req.create_entity('Blog', title=u'my-blog')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   566
            blogentry = req.create_entity('BlogEntry', title=u'entry1',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   567
                                          content=u'content1', entry_of=blog)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   568
            req.form = {'__maineid' : 'X', 'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   569
                        '__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   570
                        '_cw_entity_fields:X': 'title-subject,content-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   571
                        'title-subject:X': u'entry1-copy',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   572
                        'content-subject:X': u'content1',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   573
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   574
            self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   575
            blogentry2 = req.find('BlogEntry', title=u'entry1-copy').one()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   576
            self.assertEqual(blogentry2.entry_of[0].eid, blog.eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   577
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   578
    def test_skip_copy_for(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   579
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   580
            blog = req.create_entity('Blog', title=u'my-blog')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   581
            blogentry = req.create_entity('BlogEntry', title=u'entry1',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   582
                                          content=u'content1', entry_of=blog)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   583
            blogentry.__class__.cw_skip_copy_for = [('entry_of', 'subject')]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   584
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   585
                req.form = {'__maineid' : 'X', 'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   586
                            '__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   587
                            '_cw_entity_fields:X': 'title-subject,content-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   588
                            'title-subject:X': u'entry1-copy',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   589
                            'content-subject:X': u'content1',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   590
                            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   591
                self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   592
                blogentry2 = req.find('BlogEntry', title=u'entry1-copy').one()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   593
                # entry_of should not be copied
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   594
                self.assertEqual(len(blogentry2.entry_of), 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   595
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   596
                blogentry.__class__.cw_skip_copy_for = []
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   597
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   598
    def test_nonregr_eetype_etype_editing(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   599
        """non-regression test checking that a manager user can edit a CWEType entity
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   600
        """
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   601
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   602
            groupeids = sorted(eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   603
                               for eid, in req.execute('CWGroup G '
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   604
                                                       'WHERE G name in ("managers", "users")'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   605
            groups = [unicode(eid) for eid in groupeids]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   606
            cwetypeeid = req.execute('CWEType X WHERE X name "CWEType"')[0][0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   607
            basegroups = [unicode(eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   608
                          for eid, in req.execute('CWGroup G '
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   609
                                                  'WHERE X read_permission G, X eid %(x)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   610
                                                  {'x': cwetypeeid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   611
            cwetypeeid = unicode(cwetypeeid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   612
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   613
                'eid':      cwetypeeid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   614
                '__type:'+cwetypeeid:  'CWEType',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   615
                '_cw_entity_fields:'+cwetypeeid: 'name-subject,final-subject,description-subject,read_permission-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   616
                'name-subject:'+cwetypeeid:     u'CWEType',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   617
                'final-subject:'+cwetypeeid:    '',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   618
                'description-subject:'+cwetypeeid:     u'users group',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   619
                'read_permission-subject:'+cwetypeeid:  groups,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   620
            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   621
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   622
                self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   623
                e = req.execute('Any X WHERE X eid %(x)s', {'x': cwetypeeid}).get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   624
                self.assertEqual(e.name, 'CWEType')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   625
                self.assertEqual(sorted(g.eid for g in e.read_permission), groupeids)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   626
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   627
                # restore
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   628
                req.execute('SET X read_permission Y WHERE X name "CWEType", '
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   629
                            'Y eid IN (%s), NOT X read_permission Y' % (','.join(basegroups)))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   630
                req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   631
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   632
    def test_nonregr_strange_text_input(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   633
        """non-regression test checking text input containing "13:03:43"
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   634
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   635
        this seems to be postgres (tsearch?) specific
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   636
        """
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   637
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   638
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   639
                'eid': 'A', '__maineid' : 'A',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   640
                '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'title-subject,content-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   641
                'title-subject:A': u'"13:03:40"',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   642
                'content-subject:A': u'"13:03:43"',}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   643
            path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   644
            self.assertTrue(path.startswith('blogentry/'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   645
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   646
            e = req.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}).get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   647
            self.assertEqual(e.title, '"13:03:40"')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   648
            self.assertEqual(e.content, '"13:03:43"')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   649
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   650
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   651
    def test_nonregr_multiple_empty_email_addr(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   652
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   653
            gueid = req.execute('CWGroup G WHERE G name "users"')[0][0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   654
            req.form = {'eid': ['X', 'Y'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   655
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   656
                        '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   657
                        '_cw_entity_fields:X': 'login-subject,upassword-subject,in_group-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   658
                        'login-subject:X': u'adim',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   659
                        'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto',
10587
72447be71b48 [py3k] backtick to repr
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10255
diff changeset
   660
                        'in_group-subject:X': repr(gueid),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   661
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   662
                        '__type:Y': 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   663
                        '_cw_entity_fields:Y': 'address-subject,alias-subject,use_email-object',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   664
                        'address-subject:Y': u'',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   665
                        'alias-subject:Y': u'',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   666
                        'use_email-object:Y': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   667
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   668
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   669
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   670
            self.assertEqual(cm.exception.errors, {'address-subject': u'required field'})
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   671
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   672
    def test_nonregr_copy(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   673
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   674
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   675
            req.form = {'__maineid' : 'X', 'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   676
                        '__cloned_eid:X': user.eid, '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   677
                        '_cw_entity_fields:X': 'login-subject,upassword-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   678
                        'login-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   679
                        'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   680
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   681
            path, _params = self.expect_redirect_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   682
            self.assertEqual(path, 'cwuser/toto')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   683
            e = req.execute('Any X WHERE X is CWUser, X login "toto"').get_entity(0, 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   684
            self.assertEqual(e.login, 'toto')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   685
            self.assertEqual(e.in_group[0].name, 'managers')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   686
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   687
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   688
    def test_nonregr_rollback_on_validation_error(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   689
        with self.admin_access.web_request() as req:
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   690
            p = self.create_user(req, u"doe")
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   691
            # do not try to skip 'primary_email' for this test
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   692
            old_skips = p.__class__.skip_copy_for
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   693
            p.__class__.skip_copy_for = ()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   694
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   695
                e = req.create_entity('EmailAddress', address=u'doe@doe.com')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   696
                req.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   697
                            {'p' : p.eid, 'e' : e.eid})
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   698
                req.form = {'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   699
                            '__cloned_eid:X': p.eid, '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   700
                            '_cw_entity_fields:X': 'login-subject,surname-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   701
                            'login-subject': u'dodo',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   702
                            'surname-subject:X': u'Boom',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   703
                            '__errorurl' : "whatever but required",
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   704
                            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   705
                # try to emulate what really happens in the web application
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   706
                # 1/ validate form => EditController.publish raises a ValidationError
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   707
                #    which fires a Redirect
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   708
                # 2/ When re-publishing the copy form, the publisher implicitly commits
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   709
                try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   710
                    self.app_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   711
                except Redirect:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   712
                    req.form['rql'] = 'Any X WHERE X eid %s' % p.eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   713
                    req.form['vid'] = 'copy'
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   714
                    self.app_handle_request(req, 'view')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   715
                rset = req.execute('CWUser P WHERE P surname "Boom"')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   716
                self.assertEqual(len(rset), 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   717
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   718
                p.__class__.skip_copy_for = old_skips
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   719
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   720
    def test_regr_inlined_forms(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   721
        with self.admin_access.web_request() as req:
9213
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   722
            self.schema['described_by_test'].inlined = False
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   723
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   724
                req.data['eidmap'] = {}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   725
                req.data['pending_others'] = set()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   726
                req.data['pending_inlined'] = {}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   727
                req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   728
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   729
                            '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   730
                            '_cw_entity_fields:X': 'described_by_test-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   731
                            'described_by_test-subject:X': 'Y',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   732
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   733
                            '__type:Y': 'File',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   734
                            '_cw_entity_fields:Y': 'data-subject',
10704
73367a56ee41 [py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
   735
                            'data-subject:Y': (u'coucou.txt', Binary(b'coucou')),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   736
                            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   737
                values_by_eid = dict((eid, req.extract_entity_params(eid, minparams=2))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   738
                                     for eid in req.edited_eids())
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   739
                editctrl = self.vreg['controllers'].select('edit', req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   740
                # don't call publish to enforce select order
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   741
                editctrl.errors = []
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   742
                editctrl._to_create = {}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   743
                editctrl.edit_entity(values_by_eid['X']) # #3064653 raise ValidationError
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   744
                editctrl.edit_entity(values_by_eid['Y'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   745
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   746
                self.schema['described_by_test'].inlined = False
9213
312062f53981 [inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9196
diff changeset
   747
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   748
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   749
class ReportBugControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   750
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   751
    def test_usable_by_guest(self):
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   752
        with self.new_access(u'anon').web_request() as req:
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   753
            self.assertRaises(NoSelectableObject,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   754
                              self.vreg['controllers'].select, 'reportbug', req)
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   755
        with self.new_access(u'anon').web_request(description='hop') as req:
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   756
            self.vreg['controllers'].select('reportbug', req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   757
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   758
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   759
class AjaxControllerTC(CubicWebTC):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   760
    tested_controller = 'ajax'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   761
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   762
    def ctrl(self, req=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   763
        req = req or self.request(url='http://whatever.fr/')
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   764
        return self.vreg['controllers'].select(self.tested_controller, req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   765
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   766
    def setup_database(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   767
        with self.admin_access.repo_cnx() as cnx:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   768
            self.pytag = cnx.create_entity('Tag', name=u'python')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   769
            self.cubicwebtag = cnx.create_entity('Tag', name=u'cubicweb')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   770
            self.john = self.create_user(cnx, u'John')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   771
            cnx.commit()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   772
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   773
    ## tests ##################################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   774
    def test_simple_exec(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   775
        with self.admin_access.web_request(rql='CWUser P WHERE P login "John"',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   776
                                           pageid='123', fname='view') as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   777
            ctrl = self.ctrl(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   778
            rset = self.john.as_rset()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   779
            rset.req = req
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   780
            source = ctrl.publish()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   781
            self.assertTrue(source.startswith('<div>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   782
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   783
#     def test_json_exec(self):
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   784
#         rql = 'Any T,N WHERE T is Tag, T name N'
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   785
#         ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123'))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   786
#         self.assertEqual(ctrl.publish(),
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   787
#                           json_dumps(self.execute(rql).rows))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   788
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   789
    def test_remote_add_existing_tag(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   790
        with self.remote_calling('tag_entity', self.john.eid, ['python']) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   791
            self.assertCountEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   792
                [tname for tname, in req.execute('Any N WHERE T is Tag, T name N')],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   793
                ['python', 'cubicweb'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   794
            self.assertEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   795
                req.execute('Any N WHERE T tags P, P is CWUser, T name N').rows,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   796
                [['python']])
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   797
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   798
    def test_remote_add_new_tag(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   799
        with self.remote_calling('tag_entity', self.john.eid, ['javascript']) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   800
            self.assertCountEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   801
                [tname for tname, in req.execute('Any N WHERE T is Tag, T name N')],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   802
                ['python', 'cubicweb', 'javascript'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   803
            self.assertEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   804
                req.execute('Any N WHERE T tags P, P is CWUser, T name N').rows,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   805
                [['javascript']])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   806
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   807
    def test_maydel_perms(self):
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   808
        """Check that AjaxEditRelationCtxComponent calls rdef.check with a
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   809
        sufficient context"""
10083
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   810
        with self.remote_calling('tag_entity', self.john.eid, ['python']) as (_, req):
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   811
            req.cnx.commit()
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   812
        with self.temporary_permissions(
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   813
                (self.schema['tags'].rdefs['Tag', 'CWUser'],
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   814
                 {'delete': (RRQLExpression('S owned_by U'), )}, )):
10083
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   815
            with self.admin_access.web_request(rql='CWUser P WHERE P login "John"',
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   816
                                   pageid='123', fname='view') as req:
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   817
                ctrl = self.ctrl(req)
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   818
                rset = self.john.as_rset()
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   819
                rset.req = req
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   820
                source = ctrl.publish()
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   821
                # maydel jscall
afc5615aa92b [tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10075
diff changeset
   822
                self.assertIn('ajaxBoxRemoveLinkedEntity', source)
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   823
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   824
    def test_pending_insertion(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   825
        with self.remote_calling('add_pending_inserts', [['12', 'tags', '13']]) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   826
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   827
            self.assertEqual(deletes, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   828
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   829
            self.assertEqual(inserts, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   830
        with self.remote_calling('add_pending_inserts', [['12', 'tags', '14']]) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   831
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   832
            self.assertEqual(deletes, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   833
            inserts = get_pending_inserts(req)
10255
55413788be10 [web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents: 10254
diff changeset
   834
            self.assertCountEqual(inserts, ['12:tags:13', '12:tags:14'])
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   835
            inserts = get_pending_inserts(req, 12)
10255
55413788be10 [web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents: 10254
diff changeset
   836
            self.assertCountEqual(inserts, ['12:tags:13', '12:tags:14'])
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   837
            inserts = get_pending_inserts(req, 13)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   838
            self.assertEqual(inserts, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   839
            inserts = get_pending_inserts(req, 14)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   840
            self.assertEqual(inserts, ['12:tags:14'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   841
            req.remove_pending_operations()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   842
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   843
    def test_pending_deletion(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   844
        with self.remote_calling('add_pending_delete', ['12', 'tags', '13']) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   845
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   846
            self.assertEqual(inserts, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   847
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   848
            self.assertEqual(deletes, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   849
        with self.remote_calling('add_pending_delete', ['12', 'tags', '14']) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   850
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   851
            self.assertEqual(inserts, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   852
            deletes = get_pending_deletes(req)
10255
55413788be10 [web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents: 10254
diff changeset
   853
            self.assertCountEqual(deletes, ['12:tags:13', '12:tags:14'])
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   854
            deletes = get_pending_deletes(req, 12)
10255
55413788be10 [web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents: 10254
diff changeset
   855
            self.assertCountEqual(deletes, ['12:tags:13', '12:tags:14'])
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   856
            deletes = get_pending_deletes(req, 13)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   857
            self.assertEqual(deletes, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   858
            deletes = get_pending_deletes(req, 14)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   859
            self.assertEqual(deletes, ['12:tags:14'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   860
            req.remove_pending_operations()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   861
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   862
    def test_remove_pending_operations(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   863
        with self.remote_calling('add_pending_delete', ['12', 'tags', '13']):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   864
            pass
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   865
        with self.remote_calling('add_pending_inserts', [['12', 'tags', '14']]) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   866
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   867
            self.assertEqual(inserts, ['12:tags:14'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   868
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   869
            self.assertEqual(deletes, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   870
            req.remove_pending_operations()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   871
            self.assertEqual(get_pending_deletes(req), [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   872
            self.assertEqual(get_pending_inserts(req), [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   873
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   874
    def test_add_inserts(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   875
        with self.remote_calling('add_pending_inserts',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   876
                                 [('12', 'tags', '13'), ('12', 'tags', '14')]) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   877
            inserts = get_pending_inserts(req)
10255
55413788be10 [web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents: 10254
diff changeset
   878
            self.assertCountEqual(inserts, ['12:tags:13', '12:tags:14'])
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   879
            req.remove_pending_operations()
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   880
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   881
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   882
    # silly tests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   883
    def test_external_resource(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   884
        with self.remote_calling('external_resource', 'RSS_LOGO') as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   885
            self.assertEqual(json_dumps(self.config.uiprops['RSS_LOGO']),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   886
                             res)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   887
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   888
    def test_i18n(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   889
        with self.remote_calling('i18n', ['bimboom']) as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   890
            self.assertEqual(json_dumps(['bimboom']), res)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   891
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   892
    def test_format_date(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   893
        with self.remote_calling('format_date', '2007-01-01 12:00:00') as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   894
            self.assertEqual(json_dumps('2007/01/01'), res)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   895
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   896
    def test_ajaxfunc_noparameter(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   897
        @ajaxfunc
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   898
        def foo(self, x, y):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   899
            return 'hello'
8437
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   900
        self.assertEqual(foo(object, 1, 2), 'hello')
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   901
        appobject = foo.__appobject__
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   902
        self.assertTrue(issubclass(appobject, AjaxFunction))
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   903
        self.assertEqual(appobject.__regid__, 'foo')
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   904
        self.assertEqual(appobject.check_pageid, False)
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   905
        self.assertEqual(appobject.output_type, None)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   906
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   907
            f = appobject(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   908
            self.assertEqual(f(12, 13), 'hello')
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   909
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   910
    def test_ajaxfunc_checkpageid(self):
8437
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   911
        @ajaxfunc(check_pageid=True)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   912
        def foo(self, x, y):
8437
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   913
            return 'hello'
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   914
        self.assertEqual(foo(object, 1, 2), 'hello')
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   915
        appobject = foo.__appobject__
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   916
        self.assertTrue(issubclass(appobject, AjaxFunction))
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   917
        self.assertEqual(appobject.__regid__, 'foo')
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   918
        self.assertEqual(appobject.check_pageid, True)
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   919
        self.assertEqual(appobject.output_type, None)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   920
        # no pageid
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   921
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   922
            f = appobject(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   923
            self.assertRaises(RemoteCallFailed, f, 12, 13)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   924
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   925
    def test_ajaxfunc_json(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   926
        @ajaxfunc(output_type='json')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   927
        def foo(self, x, y):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   928
            return x + y
8437
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   929
        self.assertEqual(foo(object, 1, 2), 3)
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   930
        appobject = foo.__appobject__
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   931
        self.assertTrue(issubclass(appobject, AjaxFunction))
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   932
        self.assertEqual(appobject.__regid__, 'foo')
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   933
        self.assertEqual(appobject.check_pageid, False)
c9ab72f0645d [registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8312
diff changeset
   934
        self.assertEqual(appobject.output_type, 'json')
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   935
        # no pageid
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   936
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   937
            f = appobject(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   938
            self.assertEqual(f(12, 13), '25')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   939
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   940
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   941
class JSonControllerTC(AjaxControllerTC):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   942
    # NOTE: this class performs the same tests as AjaxController but with
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   943
    #       deprecated 'json' controller (i.e. check backward compatibility)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   944
    tested_controller = 'json'
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   945
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   946
    def setUp(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   947
        super(JSonControllerTC, self).setUp()
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   948
        self.exposed_remote_funcs = [fname for fname in dir(JSonController)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   949
                                     if fname.startswith('js_')]
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   950
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   951
    def tearDown(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   952
        super(JSonControllerTC, self).tearDown()
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   953
        for funcname in dir(JSonController):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   954
            # remove functions added dynamically during tests
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   955
            if funcname.startswith('js_') and funcname not in self.exposed_remote_funcs:
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   956
                delattr(JSonController, funcname)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   957
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   958
    def test_monkeypatch_jsoncontroller(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   959
        with self.assertRaises(RemoteCallFailed):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   960
            with self.remote_calling('foo'):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   961
                pass
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   962
        @monkeypatch(JSonController)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   963
        def js_foo(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   964
            return u'hello'
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   965
        with self.remote_calling('foo') as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   966
            self.assertEqual(res, u'hello')
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   967
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   968
    def test_monkeypatch_jsoncontroller_xhtmlize(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   969
        with self.assertRaises(RemoteCallFailed):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   970
            with self.remote_calling('foo'):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   971
                pass
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   972
        @monkeypatch(JSonController)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   973
        @xhtmlize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   974
        def js_foo(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   975
            return u'hello'
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   976
        with self.remote_calling('foo') as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   977
            self.assertEqual(u'<div>hello</div>', res)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   978
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   979
    def test_monkeypatch_jsoncontroller_jsonize(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   980
        with self.assertRaises(RemoteCallFailed):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   981
            with self.remote_calling('foo'):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   982
                pass
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   983
        @monkeypatch(JSonController)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   984
        @jsonize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   985
        def js_foo(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   986
            return 12
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   987
        with self.remote_calling('foo') as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   988
            self.assertEqual(res, '12')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   989
8504
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   990
    def test_monkeypatch_jsoncontroller_stdfunc(self):
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   991
        @monkeypatch(JSonController)
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   992
        @jsonize
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   993
        def js_reledit_form(self):
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   994
            return 12
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   995
        with self.remote_calling('reledit_form') as (res, _):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   996
            self.assertEqual(res, '12')
8504
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   997
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
   998
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
   999
class UndoControllerTC(CubicWebTC):
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1000
8812
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1001
    def setUp(self):
9020
cb87e831c183 rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
  1002
        class Connection(OldConnection):
8812
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1003
            """Force undo feature to be turned on in all case"""
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1004
            undo_actions = property(lambda tx: True, lambda x, y:None)
9020
cb87e831c183 rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
  1005
        cubicweb.server.session.Connection = Connection
8812
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1006
        super(UndoControllerTC, self).setUp()
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1007
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1008
    def tearDown(self):
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1009
        super(UndoControllerTC, self).tearDown()
9020
cb87e831c183 rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
  1010
        cubicweb.server.session.Connection = OldConnection
8812
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1011
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1012
    def setup_database(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1013
        with self.admin_access.repo_cnx() as cnx:
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
  1014
            self.toto = self.create_user(cnx, u'toto',
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
  1015
                                         password=u'toto',
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1016
                                         groups=('users',),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1017
                                         commit=False)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1018
            self.txuuid_toto = cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1019
            self.toto_email = cnx.create_entity('EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1020
                                                address=u'toto@logilab.org',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1021
                                                reverse_use_email=self.toto)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1022
            self.txuuid_toto_email = cnx.commit()
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1023
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1024
    def test_no_such_transaction(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1025
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1026
            txuuid = u"12345acbd"
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1027
            req.form['txuuid'] = txuuid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1028
            controller = self.vreg['controllers'].select('undo', req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1029
            with self.assertRaises(tx.NoSuchTransaction) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1030
                result = controller.publish(rset=None)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1031
            self.assertEqual(cm.exception.txuuid, txuuid)
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1032
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1033
    def assertURLPath(self, url, expected_path, expected_params=None):
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1034
        """ This assert that the path part of `url` matches  expected path
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1035
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1036
        TODO : implement assertion on the expected_params too
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1037
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1038
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1039
            scheme, netloc, path, query, fragment = urlsplit(url)
10603
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10587
diff changeset
  1040
            query_dict = parse_qs(query)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1041
            expected_url = urljoin(req.base_url(), expected_path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1042
            self.assertEqual( urlunsplit((scheme, netloc, path, None, None)), expected_url)
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1043
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1044
    def test_redirect_redirectpath(self):
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1045
        "Check that the potential __redirectpath is honored"
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1046
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1047
            txuuid = self.txuuid_toto_email
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1048
            req.form['txuuid'] = txuuid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1049
            rpath = "toto"
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1050
            req.form['__redirectpath'] = rpath
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1051
            controller = self.vreg['controllers'].select('undo', req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1052
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1053
                result = controller.publish(rset=None)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1054
            self.assertURLPath(cm.exception.location, rpath)
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1055
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1056
    def test_redirect_default(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1057
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1058
            txuuid = self.txuuid_toto_email
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1059
            req.form['txuuid'] = txuuid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1060
            req.session.data['breadcrumbs'] = [ urljoin(req.base_url(), path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1061
                                                for path in ('tata', 'toto',)]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1062
            controller = self.vreg['controllers'].select('undo', req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1063
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1064
                result = controller.publish(rset=None)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1065
            self.assertURLPath(cm.exception.location, 'toto')
8267
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1066
486386d9f836 [web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8128
diff changeset
  1067
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1068
class LoginControllerTC(CubicWebTC):
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1069
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1070
    def test_login_with_dest(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1071
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1072
            req.form = {'postlogin_path': 'elephants/babar'}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1073
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1074
                self.ctrl_publish(req, ctrl='login')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1075
            self.assertEqual(req.build_url('elephants/babar'), cm.exception.location)
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1076
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1077
    def test_login_no_dest(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1078
        with self.admin_access.web_request() as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1079
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1080
                self.ctrl_publish(req, ctrl='login')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1081
            self.assertEqual(req.base_url(), cm.exception.location)
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1082
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1083
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1084
    unittest_main()