web/test/unittest_views_basecontrollers.py
author Julien Cristau <julien.cristau@logilab.fr>
Wed, 06 Jan 2016 11:47:08 +0100
changeset 11080 245f440b814a
parent 10968 9c6c3e68422e
permissions -rw-r--r--
[devtools] fix get_bounds Say an attribute has two IntervalBoundConstraints, one with minvalue=0 and the other with maxvalue=10 (not literally, or that could be a single constraint, but e.g. with references to other attributes). We don't want to override the minvalue of the former with None just because the latter happens last in the constraints list. This doesn't fix the case where two constraints both have a min or a max value. Meh.
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
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
    20
from six import text_type
10603
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10587
diff changeset
    21
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
    22
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    23
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
    24
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    25
from logilab.common.testlib import unittest_main
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
10968
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    31
from cubicweb.devtools.webtest import CubicWebTestTC
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    32
from cubicweb.utils import json_dumps
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    33
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
    34
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
    35
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
    36
from cubicweb.server.session import Connection as OldConnection
4390
0285c1fa1459 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4389
diff changeset
    37
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
    38
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
    39
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
    40
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
    41
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
    42
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
    43
10968
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    44
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    45
class ViewControllerTC(CubicWebTestTC):
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    46
    def test_view_ctrl_with_valid_cache_headers(self):
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    47
        resp = self.webapp.get('/manage')
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    48
        self.assertEqual(resp.etag, 'manage/guests')
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    49
        self.assertEqual(resp.status_code, 200)
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    50
        cache_headers = {'if-modified-since': resp.headers['Last-Modified'],
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    51
                         'if-none-match': resp.etag}
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    52
        resp = self.webapp.get('/manage', headers=cache_headers)
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    53
        self.assertEqual(resp.status_code, 304)
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    54
        self.assertEqual(len(resp.body), 0)
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    55
9c6c3e68422e [web/views] Controllers should always return bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10932
diff changeset
    56
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    57
def req_form(user):
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    58
    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
    59
            '_cw_entity_fields:%s' % user.eid: '_cw_generic_field',
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    60
            '__type:%s' % user.eid: user.__regid__
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    61
            }
0
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
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    64
class EditControllerTC(CubicWebTC):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    65
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
    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
    67
        CubicWebTC.setUp(self)
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9478
diff changeset
    68
        self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read'))
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    69
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
    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
    71
        CubicWebTC.tearDown(self)
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9478
diff changeset
    72
        self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read'))
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    73
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    def test_noparam_edit(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        """check behaviour of this controller without any form parameter
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    77
        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
    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
            self.assertEqual(cm.exception.errors, {None: u'no selected entities'})
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    81
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    def test_validation_unique(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        """test creation of two linked entities
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    84
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    85
        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
    86
            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
    87
                        '_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
    88
                        'login-subject:X': u'admin',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    89
                        'upassword-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    90
                        '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
    91
                    }
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    92
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    93
                self.ctrl_publish(req)
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
    94
                cm.exception.translate(text_type)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    95
                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
    96
                                 cm.exception.errors)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
10016
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
    98
    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
    99
        """ 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
   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
        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
   102
            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
   103
            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
   104
            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
   105
            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
   106
            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
   107
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   108
        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
   109
            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
   110
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   111
        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
   112
            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
   113
            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
   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
    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
   116
        """ 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
   117
        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
   118
            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
   119
            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
   120
            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
   121
            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
   122
            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
   123
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   124
        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
   125
            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
   126
            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
   127
            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
   128
984505da8b89 [forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 9846
diff changeset
   129
        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
   130
        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
   131
        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
   132
        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
   133
        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
   134
            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
   135
                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
   136
            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
   137
            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
   138
            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
   139
            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
   140
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
    def test_user_editing_itself(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        """checking that a manager user can edit itself
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   144
        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
   145
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   146
            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
   147
                                                     'in ("managers", "users")')]
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   148
            groups = [text_type(eid) for eid in groupeids]
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   149
            eid = text_type(user.eid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   150
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   151
                'eid': eid, '__type:'+eid: 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   152
                '_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject,in_group-subject',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   153
                'login-subject:'+eid:     text_type(user.login),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   154
                'surname-subject:'+eid: u'Th\xe9nault',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   155
                'firstname-subject:'+eid:   u'Sylvain',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   156
                'in_group-subject:'+eid:  groups,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   157
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   158
            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
   159
            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
   160
                            {'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
   161
            self.assertEqual(e.firstname, u'Sylvain')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   162
            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
   163
            self.assertEqual(e.login, user.login)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   164
            self.assertEqual([g.eid for g in e.in_group], groupeids)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
    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
   167
        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
   168
            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
   169
            cnx.commit()
10253
8eb9a3e9531c [web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents: 10083
diff changeset
   170
        with self.new_access(u'user').web_request() as req:
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   171
            eid = text_type(req.user.eid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   172
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   173
                'eid': eid, '__maineid' : eid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   174
                '__type:'+eid: 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   175
                '_cw_entity_fields:'+eid: 'upassword-subject',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   176
                'upassword-subject:'+eid: 'tournicoton',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   177
                'upassword-subject-confirm:'+eid: 'tournicoton',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   178
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   179
            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
   180
            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
   181
            self.assertEqual(path, 'cwuser/user')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   182
            self.assertNotIn('vid', params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   184
    def test_user_editing_itself_no_relation(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        """checking we can edit an entity without specifying some required
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        relations (meaning no changes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   188
        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
   189
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   190
            groupeids = [g.eid for g in user.in_group]
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   191
            eid = text_type(user.eid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   192
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   193
                'eid':       eid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   194
                '__type:'+eid:    'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   195
                '_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   196
                'login-subject:'+eid:     text_type(user.login),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   197
                'firstname-subject:'+eid: u'Th\xe9nault',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   198
                'surname-subject:'+eid:   u'Sylvain',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   199
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   200
            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
   201
            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
   202
                            {'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
   203
            self.assertEqual(e.login, user.login)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   204
            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
   205
            self.assertEqual(e.surname, u'Sylvain')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   206
            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
   207
            self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   208
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   209
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
    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
   211
        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
   212
            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
   213
            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
   214
                        '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   215
                        '_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
   216
                        'login-subject:X': u'adim',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   217
                        '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
   218
                        'surname-subject:X': u'Di Mascio',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   219
                        'in_group-subject:X': text_type(gueid),
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   220
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   221
                        '__type:Y': 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   222
                        '_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
   223
                        '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
   224
                        'use_email-object:Y': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   225
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   226
            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
   227
            # 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
   228
            self.assertEqual(path, 'cwuser/adim')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   229
            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
   230
            self.assertEqual(e.surname, 'Di Mascio')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   231
            email = e.use_email[0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   232
            self.assertEqual(email.address, 'dima@logilab.fr')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   233
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
   234
    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
   235
        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
   236
            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
   237
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   238
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   239
                        '_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
   240
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   241
                        '__type:Y': 'File',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   242
                        '_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
   243
                        '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
   244
                        'described_by_test-object:Y': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   245
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   246
            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
   247
            self.assertTrue(path.startswith('salesterm/'), path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   248
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   249
            salesterm = req.entity_from_eid(eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   250
            # 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
   251
            # 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
   252
            # will fail.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   253
            # 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
   254
            # 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
   255
            # created before.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   256
            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
   257
9196
13461cb8ff40 [editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9184
diff changeset
   258
    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
   259
        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
   260
            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
   261
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
   262
                        '__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
   263
                        '_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
   264
                        '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
   265
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
   266
                        '__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
   267
                        '_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
   268
                        '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
   269
                        }
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   270
            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
   271
            self.assertTrue(path.startswith('salesterm/'), path)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   272
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   273
            salesterm = req.entity_from_eid(eid)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   274
            # 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
   275
            # 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
   276
            # will fail.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   277
            # 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
   278
            # 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
   279
            # created before.
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   280
            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
   281
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   282
    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
   283
        # 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
   284
        # "unhashable type: 'list'" error
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   285
        with self.admin_access.web_request() as req:
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   286
            cwrelation = text_type(req.execute('CWEType X WHERE X name "CWSource"')[0][0])
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   287
            req.form = {'eid': [cwrelation], '__maineid' : cwrelation,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   288
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   289
                        '__type:'+cwrelation: 'CWEType',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   290
                        '_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
   291
                        'to_entity-object:'+cwrelation: [9999, 9998],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   292
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   293
            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
   294
                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
   295
            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
   296
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   297
    def test_edit_multiple_linked(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   298
        with self.admin_access.web_request() as req:
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   299
            peid = text_type(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
   300
            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
   301
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   302
                        '__type:'+peid: u'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   303
                        '_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
   304
                        'surname-subject:'+peid: u'Di Masci',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   305
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   306
                        '__type:Y': u'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   307
                        '_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
   308
                        '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
   309
                        'use_email-object:Y': peid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   310
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   311
            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
   312
            # 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
   313
            self.assertEqual(path, 'cwuser/adim')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   314
            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
   315
            email = e.use_email[0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   316
            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
   317
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   318
        # with self.admin_access.web_request() as req:
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   319
            emaileid = text_type(email.eid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   320
            req.form = {'eid': [peid, emaileid],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   321
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   322
                        '__type:'+peid: u'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   323
                        '_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
   324
                        'surname-subject:'+peid: u'Di Masci',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   325
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   326
                        '__type:'+emaileid: u'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   327
                        '_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
   328
                        '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
   329
                        'use_email-object:'+emaileid: peid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   330
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   331
            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
   332
            email.cw_clear_all_caches()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   333
            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
   334
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   335
    def test_password_confirm(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   336
        """test creation of two linked entities
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   337
        """
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   338
        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
   339
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   340
            req.form = {'eid': 'X',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   341
                        '__cloned_eid:X': text_type(user.eid), '__type:X': 'CWUser',
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   342
                        '_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
   343
                        'login-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   344
                        'upassword-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   345
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   346
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   347
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   348
            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
   349
                             cm.exception.errors)
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   350
            req.form = {'__cloned_eid:X': text_type(user.eid),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   351
                        'eid': 'X', '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   352
                        '_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
   353
                        'login-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   354
                        'upassword-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   355
                        'upassword-subject-confirm:X': u'tutu',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   356
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   357
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   358
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   359
            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
   360
                             cm.exception.errors)
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
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   363
    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
   364
        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
   365
            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
   366
                               {'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
   367
            cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   368
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   369
        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
   370
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   371
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   372
                        '_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
   373
                        'amount-subject:X': u'-10',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   374
                        'described_by_test-subject:X': text_type(feid),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   375
                    }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   376
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   377
                self.ctrl_publish(req)
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   378
            cm.exception.translate(text_type)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   379
            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
   380
                             cm.exception.errors)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   381
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   382
        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
   383
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   384
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   385
                        '_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
   386
                        'amount-subject:X': u'110',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   387
                        'described_by_test-subject:X': text_type(feid),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   388
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   389
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   390
                self.ctrl_publish(req)
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   391
            cm.exception.translate(text_type)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   392
            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
   393
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   394
        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
   395
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   396
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   397
                        '_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
   398
                        'amount-subject:X': u'10',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   399
                        'described_by_test-subject:X': text_type(feid),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   400
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   401
            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
   402
            # should be redirected on the created
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   403
            #eid = params['rql'].split()[-1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   404
            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
   405
            self.assertEqual(e.amount, 10)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   406
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   407
    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
   408
        """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
   409
        constrained attributes"""
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   410
        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
   411
            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
   412
                               {'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
   413
            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
   414
            cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   415
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   416
        # 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
   417
        with self.admin_access.web_request(rollbackfirst=True) as req:
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   418
            req.form = {'eid': [text_type(seid)],
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   419
                        '__type:%s'%seid: 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   420
                        '_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
   421
                        'amount-subject:%s'%seid: u'-10',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   422
                    }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   423
            self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   424
 window.parent.handleFormValidationResponse('entityForm', null, null, [false, [%s, {"amount-subject": "value -10 must be >= 0"}], null], null);
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
   425
</script>'''%seid, self.ctrl_publish(req, 'validateform').decode('ascii'))
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   426
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   427
        # 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
   428
        with self.admin_access.web_request(rollbackfirst=True) as req:
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   429
            req.form = {'eid': [text_type(seid)],
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   430
                        '__type:%s'%seid: 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   431
                        '_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
   432
                        'amount-subject:%s'%seid: u'20',
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
            self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   435
 window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
   436
</script>''', self.ctrl_publish(req, 'validateform').decode('ascii'))
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   437
            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
   438
                                             {'eid': seid})[0][0])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   439
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   440
        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
   441
            req.form = {'eid': ['X'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   442
                        '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   443
                        '_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
   444
                        'amount-subject:X': u'0',
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   445
                        'described_by_test-subject:X': text_type(feid),
9846
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
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   448
            # 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
   449
            # hook works as it should (see
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   450
            # https://www.cubicweb.org/ticket/2509729 )
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   451
            class MyOperation(Operation):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   452
                def precommit_event(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   453
                    self.entity.cw_set(amount=-10)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   454
            class ValidationErrorInOpAfterHook(Hook):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   455
                __regid__ = 'valerror-op-after-hook'
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   456
                __select__ = Hook.__select__ & is_instance('Salesterm')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   457
                events = ('after_add_entity',)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   458
                def __call__(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   459
                    MyOperation(self._cw, entity=self.entity)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   460
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   461
            with self.temporary_appobjects(ValidationErrorInOpAfterHook):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   462
                self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   463
 window.parent.handleFormValidationResponse('entityForm', null, null, [false, ["X", {"amount-subject": "value -10 must be >= 0"}], null], null);
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
   464
</script>''', self.ctrl_publish(req, 'validateform').decode('ascii'))
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   465
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   466
            self.assertMultiLineEqual('''<script type="text/javascript">
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   467
 window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
   468
</script>''', self.ctrl_publish(req, 'validateform').decode('ascii'))
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   469
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   470
    def test_req_pending_insert(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   471
        """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
   472
        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
   473
            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
   474
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   475
            req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   476
        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
   477
            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
   478
            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
   479
            usergroups = [gname for gname, in
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   480
                          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
   481
                                      {'u': user.eid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   482
            self.assertCountEqual(usergroups, ['managers', 'test'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   483
            self.assertEqual(get_pending_inserts(req), [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   484
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   485
    def test_req_pending_delete(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   486
        """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
   487
        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
   488
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   489
            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
   490
                                    {'x': user.eid})[0][0]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   491
            usergroups = [gname for gname, in
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   492
                          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
   493
                                      {'u': user.eid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   494
            # 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
   495
            self.assertCountEqual(usergroups, ['managers', 'test'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   496
            req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   497
            # now try to delete the relation
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   498
        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
   499
            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
   500
            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
   501
            usergroups = [gname for gname, in
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   502
                          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
   503
                                      {'u': user.eid})]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   504
            self.assertCountEqual(usergroups, ['managers'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   505
            self.assertEqual(get_pending_deletes(req), [])
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
    def test_redirect_apply_button(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   508
        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
   509
            redirectrql = rql_for_eid(4012) # whatever
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   510
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   511
                'eid': 'A', '__maineid' : 'A',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   512
                '__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
   513
                '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
   514
                'title-subject:A': u'huuu',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   515
                '__redirectrql': redirectrql,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   516
                '__redirectvid': 'primary',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   517
                '__redirectparams': 'toto=tutu&tata=titi',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   518
                '__form_id': 'edition',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   519
                '__action_apply': '',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   520
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   521
            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
   522
            self.assertTrue(path.startswith('blogentry/'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   523
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   524
            self.assertEqual(params['vid'], 'edition')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   525
            self.assertNotEqual(int(eid), 4012)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   526
            self.assertEqual(params['__redirectrql'], redirectrql)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   527
            self.assertEqual(params['__redirectvid'], 'primary')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   528
            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
   529
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   530
    def test_redirect_ok_button(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   531
        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
   532
            redirectrql = rql_for_eid(4012) # whatever
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   533
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   534
                'eid': 'A', '__maineid' : 'A',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   535
                '__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
   536
                '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
   537
                'title-subject:A': u'huuu',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   538
                '__redirectrql': redirectrql,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   539
                '__redirectvid': 'primary',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   540
                '__redirectparams': 'toto=tutu&tata=titi',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   541
                '__form_id': 'edition',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   542
                }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   543
            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
   544
            self.assertEqual(path, 'view')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   545
            self.assertEqual(params['rql'], redirectrql)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   546
            self.assertEqual(params['vid'], 'primary')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   547
            self.assertEqual(params['tata'], 'titi')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   548
            self.assertEqual(params['toto'], 'tutu')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   549
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   550
    def test_redirect_delete_button(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   551
        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
   552
            eid = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   553
            req.form = {'eid': text_type(eid), '__type:%s'%eid: 'BlogEntry',
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   554
                        '__action_delete': ''}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   555
            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
   556
            self.assertEqual(path, 'blogentry')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   557
            self.assertIn('_cwmsgid', params)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   558
            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
   559
            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
   560
                        {'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
   561
            req.cnx.commit()
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   562
            req.form = {'eid': text_type(eid), '__type:%s'%eid: 'EmailAddress',
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   563
                        '__action_delete': ''}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   564
            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
   565
            self.assertEqual(path, 'cwuser/admin')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   566
            self.assertIn('_cwmsgid', params)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   567
            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
   568
            eid2 = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   569
            req.form = {'eid': [text_type(eid1), text_type(eid2)],
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   570
                        '__type:%s'%eid1: 'BlogEntry',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   571
                        '__type:%s'%eid2: 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   572
                        '__action_delete': ''}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   573
            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
   574
            self.assertEqual(path, 'view')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   575
            self.assertIn('_cwmsgid', params)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   576
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   577
    def test_simple_copy(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   578
        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
   579
            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
   580
            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
   581
                                          content=u'content1', entry_of=blog)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   582
            req.form = {'__maineid' : 'X', 'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   583
                        '__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
   584
                        '_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
   585
                        'title-subject:X': u'entry1-copy',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   586
                        'content-subject:X': u'content1',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   587
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   588
            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
   589
            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
   590
            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
   591
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   592
    def test_skip_copy_for(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   593
        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
   594
            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
   595
            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
   596
                                          content=u'content1', entry_of=blog)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   597
            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
   598
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   599
                req.form = {'__maineid' : 'X', 'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   600
                            '__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
   601
                            '_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
   602
                            'title-subject:X': u'entry1-copy',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   603
                            'content-subject:X': u'content1',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   604
                            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   605
                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
   606
                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
   607
                # entry_of should not be copied
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   608
                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
   609
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   610
                blogentry.__class__.cw_skip_copy_for = []
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   611
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   612
    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
   613
        """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
   614
        """
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   615
        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
   616
            groupeids = sorted(eid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   617
                               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
   618
                                                       'WHERE G name in ("managers", "users")'))
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   619
            groups = [text_type(eid) for eid in groupeids]
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   620
            cwetypeeid = req.execute('CWEType X WHERE X name "CWEType"')[0][0]
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   621
            basegroups = [text_type(eid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   622
                          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
   623
                                                  '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
   624
                                                  {'x': cwetypeeid})]
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   625
            cwetypeeid = text_type(cwetypeeid)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   626
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   627
                'eid':      cwetypeeid,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   628
                '__type:'+cwetypeeid:  'CWEType',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   629
                '_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
   630
                'name-subject:'+cwetypeeid:     u'CWEType',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   631
                'final-subject:'+cwetypeeid:    '',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   632
                'description-subject:'+cwetypeeid:     u'users group',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   633
                'read_permission-subject:'+cwetypeeid:  groups,
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
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   636
                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
   637
                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
   638
                self.assertEqual(e.name, 'CWEType')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   639
                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
   640
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   641
                # restore
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   642
                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
   643
                            '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
   644
                req.cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   645
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   646
    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
   647
        """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
   648
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   649
        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
   650
        """
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   651
        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
   652
            req.form = {
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   653
                'eid': 'A', '__maineid' : 'A',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   654
                '__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
   655
                '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
   656
                '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
   657
            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
   658
            self.assertTrue(path.startswith('blogentry/'))
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   659
            eid = path.split('/')[1]
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   660
            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
   661
            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
   662
            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
   663
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   664
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   665
    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
   666
        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
   667
            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
   668
            req.form = {'eid': ['X', 'Y'],
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   669
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   670
                        '__type:X': 'CWUser',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   671
                        '_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
   672
                        'login-subject:X': u'adim',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   673
                        '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
   674
                        '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
   675
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   676
                        '__type:Y': 'EmailAddress',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   677
                        '_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
   678
                        'address-subject:Y': u'',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   679
                        'alias-subject:Y': u'',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   680
                        'use_email-object:Y': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   681
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   682
            with self.assertRaises(ValidationError) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   683
                self.ctrl_publish(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   684
            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
   685
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   686
    def test_nonregr_copy(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   687
        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
   688
            user = req.user
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   689
            req.form = {'__maineid' : 'X', 'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   690
                        '__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
   691
                        '_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
   692
                        'login-subject:X': u'toto',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   693
                        '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
   694
                        }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   695
            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
   696
            self.assertEqual(path, 'cwuser/toto')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   697
            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
   698
            self.assertEqual(e.login, 'toto')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   699
            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
   700
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   701
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   702
    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
   703
        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
   704
            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
   705
            # 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
   706
            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
   707
            p.__class__.skip_copy_for = ()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   708
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   709
                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
   710
                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
   711
                            {'p' : p.eid, 'e' : e.eid})
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   712
                req.form = {'eid': 'X',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   713
                            '__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
   714
                            '_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
   715
                            'login-subject': u'dodo',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   716
                            'surname-subject:X': u'Boom',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   717
                            '__errorurl' : "whatever but required",
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   718
                            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   719
                # 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
   720
                # 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
   721
                #    which fires a Redirect
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   722
                # 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
   723
                try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   724
                    self.app_handle_request(req, 'edit')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   725
                except Redirect:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   726
                    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
   727
                    req.form['vid'] = 'copy'
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   728
                    self.app_handle_request(req, 'view')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   729
                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
   730
                self.assertEqual(len(rset), 0)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   731
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   732
                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
   733
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   734
    def test_regr_inlined_forms(self):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   735
        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
   736
            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
   737
            try:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   738
                req.data['eidmap'] = {}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   739
                req.data['pending_others'] = set()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   740
                req.data['pending_inlined'] = {}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   741
                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
   742
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   743
                            '__type:X': 'Salesterm',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   744
                            '_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
   745
                            'described_by_test-subject:X': 'Y',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   746
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   747
                            '__type:Y': 'File',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   748
                            '_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
   749
                            '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
   750
                            }
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   751
                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
   752
                                     for eid in req.edited_eids())
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   753
                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
   754
                # 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
   755
                editctrl.errors = []
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   756
                editctrl._to_create = {}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   757
                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
   758
                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
   759
            finally:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   760
                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
   761
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   762
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   763
class ReportBugControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   764
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   765
    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
   766
        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
   767
            self.assertRaises(NoSelectableObject,
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   768
                              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
   769
        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
   770
            self.vreg['controllers'].select('reportbug', req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   771
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   772
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   773
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
   774
    tested_controller = 'ajax'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   775
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   776
    def ctrl(self, req=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   777
        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
   778
        return self.vreg['controllers'].select(self.tested_controller, req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   779
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   780
    def setup_database(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   781
        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
   782
            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
   783
            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
   784
            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
   785
            cnx.commit()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   786
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   787
    ## tests ##################################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   788
    def test_simple_exec(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   789
        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
   790
                                           pageid='123', fname='view') as req:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   791
            ctrl = self.ctrl(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   792
            rset = self.john.as_rset()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   793
            rset.req = req
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   794
            source = ctrl.publish()
10749
2703116e4b21 [web/test] str → bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10728
diff changeset
   795
            self.assertTrue(source.startswith(b'<div>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   796
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   797
#     def test_json_exec(self):
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   798
#         rql = 'Any T,N WHERE T is Tag, T name N'
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   799
#         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
   800
#         self.assertEqual(ctrl.publish(),
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   801
#                           json_dumps(self.execute(rql).rows))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   802
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   803
    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
   804
        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
   805
            self.assertCountEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   806
                [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
   807
                ['python', 'cubicweb'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   808
            self.assertEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   809
                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
   810
                [['python']])
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   811
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   812
    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
   813
        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
   814
            self.assertCountEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   815
                [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
   816
                ['python', 'cubicweb', 'javascript'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   817
            self.assertEqual(
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   818
                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
   819
                [['javascript']])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   820
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   821
    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
   822
        """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
   823
        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
   824
        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
   825
            req.cnx.commit()
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   826
        with self.temporary_permissions(
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   827
                (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
   828
                 {'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
   829
            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
   830
                                   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
   831
                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
   832
                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
   833
                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
   834
                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
   835
                # maydel jscall
10749
2703116e4b21 [web/test] str → bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10728
diff changeset
   836
                self.assertIn(b'ajaxBoxRemoveLinkedEntity', source)
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10016
diff changeset
   837
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   838
    def test_pending_insertion(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   839
        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
   840
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   841
            self.assertEqual(deletes, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   842
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   843
            self.assertEqual(inserts, ['12:tags:13'])
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_inserts', [['12', 'tags', '14']]) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   845
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   846
            self.assertEqual(deletes, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   847
            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
   848
            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
   849
            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
   850
            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
   851
            inserts = get_pending_inserts(req, 13)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   852
            self.assertEqual(inserts, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   853
            inserts = get_pending_inserts(req, 14)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   854
            self.assertEqual(inserts, ['12:tags:14'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   855
            req.remove_pending_operations()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   856
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   857
    def test_pending_deletion(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   858
        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
   859
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   860
            self.assertEqual(inserts, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   861
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   862
            self.assertEqual(deletes, ['12:tags:13'])
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', '14']) as (_, req):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   864
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   865
            self.assertEqual(inserts, [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   866
            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
   867
            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
   868
            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
   869
            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
   870
            deletes = get_pending_deletes(req, 13)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   871
            self.assertEqual(deletes, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   872
            deletes = get_pending_deletes(req, 14)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   873
            self.assertEqual(deletes, ['12:tags:14'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   874
            req.remove_pending_operations()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   875
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   876
    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
   877
        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
   878
            pass
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   879
        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
   880
            inserts = get_pending_inserts(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   881
            self.assertEqual(inserts, ['12:tags:14'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   882
            deletes = get_pending_deletes(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   883
            self.assertEqual(deletes, ['12:tags:13'])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   884
            req.remove_pending_operations()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   885
            self.assertEqual(get_pending_deletes(req), [])
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   886
            self.assertEqual(get_pending_inserts(req), [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   887
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   888
    def test_add_inserts(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('add_pending_inserts',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   890
                                 [('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
   891
            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
   892
            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
   893
            req.remove_pending_operations()
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   894
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   895
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   896
    # silly tests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   897
    def test_external_resource(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   898
        with self.remote_calling('external_resource', 'RSS_LOGO') as (res, _):
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   899
            self.assertEqual(json_dumps(self.config.uiprops['RSS_LOGO']).encode('ascii'),
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   900
                             res)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   901
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   902
    def test_i18n(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   903
        with self.remote_calling('i18n', ['bimboom']) as (res, _):
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   904
            self.assertEqual(json_dumps(['bimboom']).encode('ascii'), res)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   905
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   906
    def test_format_date(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   907
        with self.remote_calling('format_date', '2007-01-01 12:00:00') as (res, _):
10728
48c6de7321d8 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10704
diff changeset
   908
            self.assertEqual(json_dumps('2007/01/01').encode('ascii'), res)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   909
8128
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_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
   911
        @ajaxfunc
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):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   913
            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
   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, 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
   919
        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
   920
        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
   921
            f = appobject(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   922
            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
   923
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   924
    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
   925
        @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
   926
        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
   927
            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
   928
        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
   929
        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
   930
        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
   931
        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
   932
        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
   933
        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
   934
        # no pageid
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   935
        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
   936
            f = appobject(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   937
            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
   938
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   939
    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
   940
        @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
   941
        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
   942
            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
   943
        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
   944
        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
   945
        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
   946
        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
   947
        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
   948
        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
   949
        # no pageid
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   950
        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
   951
            f = appobject(req)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   952
            self.assertEqual(f(12, 13), '25')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   953
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   954
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   955
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
   956
    # 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
   957
    #       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
   958
    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
   959
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   960
    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
   961
        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
   962
        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
   963
                                     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
   964
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   965
    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
   966
        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
   967
        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
   968
            # 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
   969
            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
   970
                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
   971
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   972
    def test_monkeypatch_jsoncontroller(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   973
        with self.assertRaises(RemoteCallFailed):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   974
            with self.remote_calling('foo'):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   975
                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
   976
        @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
   977
        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
   978
            return u'hello'
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   979
        with self.remote_calling('foo') as (res, _):
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
   980
            self.assertEqual(res, b'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
   981
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   982
    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
   983
        with self.assertRaises(RemoteCallFailed):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   984
            with self.remote_calling('foo'):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   985
                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
   986
        @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
   987
        @xhtmlize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   988
        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
   989
            return u'hello'
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   990
        with self.remote_calling('foo') as (res, _):
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
   991
            self.assertEqual(b'<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
   992
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   993
    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
   994
        with self.assertRaises(RemoteCallFailed):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   995
            with self.remote_calling('foo'):
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   996
                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
   997
        @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
   998
        @jsonize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   999
        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
  1000
            return 12
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1001
        with self.remote_calling('foo') as (res, _):
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
  1002
            self.assertEqual(res, b'12')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1003
8504
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
  1004
    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
  1005
        @monkeypatch(JSonController)
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
  1006
        @jsonize
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
  1007
        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
  1008
            return 12
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1009
        with self.remote_calling('reledit_form') as (res, _):
10751
9ffdfa1d28f5 [web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents: 10749
diff changeset
  1010
            self.assertEqual(res, b'12')
8504
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
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
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
  1013
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
  1014
8812
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1015
    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
  1016
        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
  1017
            """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
  1018
            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
  1019
        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
  1020
        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
  1021
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1022
    def tearDown(self):
52af67a2f0a5 [session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8803
diff changeset
  1023
        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
  1024
        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
  1025
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
  1026
    def setup_database(self):
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1027
        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
  1028
            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
  1029
                                         password=u'toto',
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1030
                                         groups=('users',),
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1031
                                         commit=False)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1032
            self.txuuid_toto = cnx.commit()
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1033
            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
  1034
                                                address=u'toto@logilab.org',
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1035
                                                reverse_use_email=self.toto)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1036
            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
  1037
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
  1038
    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
  1039
        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
  1040
            txuuid = u"12345acbd"
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1041
            req.form['txuuid'] = txuuid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1042
            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
  1043
            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
  1044
                result = controller.publish(rset=None)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1045
            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
  1046
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
  1047
    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
  1048
        """ 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
  1049
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
  1050
        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
  1051
        """
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1052
        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
  1053
            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
  1054
            query_dict = parse_qs(query)
9846
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1055
            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
  1056
            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
  1057
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
  1058
    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
  1059
        "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
  1060
        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
  1061
            txuuid = self.txuuid_toto_email
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1062
            req.form['txuuid'] = txuuid
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1063
            rpath = "toto"
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1064
            req.form['__redirectpath'] = rpath
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1065
            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
  1066
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1067
                result = controller.publish(rset=None)
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1068
            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
  1069
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
  1070
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1071
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
  1072
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1073
    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
  1074
        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
  1075
            req.form = {'postlogin_path': 'elephants/babar'}
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1076
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1077
                self.ctrl_publish(req, ctrl='login')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1078
            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
  1079
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
  1080
    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
  1081
        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
  1082
            with self.assertRaises(Redirect) as cm:
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1083
                self.ctrl_publish(req, ctrl='login')
67c1b77b44be [webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
  1084
            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
  1085
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1086
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1087
    unittest_main()