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