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