web/test/unittest_views_basecontrollers.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 31 Jul 2012 11:04:45 +0200
branchstable
changeset 8500 bfc1875ce9e3
parent 8487 017af22e7678
child 8504 f21c72928662
permissions -rw-r--r--
[composite] apply composite on new enty too Before this changesets, automatic deletion did not applied to entity created in the same transaction. This patch remove this filtering in the dedicated operation. The original filtering where introduced by 5d889b4928bb but no rational where found for this changes. The former behavior is seen as inconsistent and creates bug in some cubes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
     1
# copyright 2003-2011 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
6875
a166b51d13f8 [test] missing future imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
    20
from __future__ import with_statement
a166b51d13f8 [test] missing future imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
    21
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
    22
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
    23
# 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
    24
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
    25
    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
    26
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
    27
    from cgi import parse_qs as url_parse_query
1899
361774742f3e [test] fix test after xhml_wrap changed signature
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1797
diff changeset
    28
from logilab.common.testlib import unittest_main, mock_object
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    29
from logilab.common.decorators import monkeypatch
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
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
    31
from cubicweb import Binary, NoSelectableObject, ValidationError
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
    32
from cubicweb.view import STRICT_DOCTYPE
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    33
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
    34
from cubicweb.utils import json_dumps
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    35
from cubicweb.uilib import rql_for_eid
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    36
from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError, RemoteCallFailed
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    37
from cubicweb.entities.authobjs import CWUser
4390
0285c1fa1459 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4389
diff changeset
    38
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
    39
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
    40
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
    41
import cubicweb.transaction as tx
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
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    43
u = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    45
def req_form(user):
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    46
    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
    47
            '_cw_entity_fields:%s' % user.eid: '_cw_generic_field',
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    48
            '__type:%s' % user.eid: user.__regid__
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
    49
            }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    51
class EditControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    def setUp(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    53
        CubicWebTC.setUp(self)
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
    54
        self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read'))
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    55
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    def tearDown(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    57
        CubicWebTC.tearDown(self)
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
    58
        self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read'))
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    59
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
    def test_noparam_edit(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        """check behaviour of this controller without any form parameter
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        """
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    63
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    64
            self.ctrl_publish(self.request())
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    65
        self.assertEqual(cm.exception.errors, {None: u'no selected entities'})
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    66
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    def test_validation_unique(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        """test creation of two linked entities
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    69
        """
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        user = self.user()
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    71
        req = self.request()
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    72
        req.form = {'eid': 'X', '__type:X': 'CWUser',
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
    73
                    '_cw_entity_fields:X': 'login-subject,upassword-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    74
                    'login-subject:X': u'admin',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    75
                    'upassword-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    76
                    'upassword-subject-confirm:X': u'toto',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    77
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    78
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    79
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    80
        self.assertEqual(cm.exception.errors, {'login-subject': 'the value "admin" is already used, use another one'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    def test_user_editing_itself(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        """checking that a manager user can edit itself
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        user = self.user()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    86
        basegroups = [u(eid) for eid, in self.execute('CWGroup G WHERE X in_group G, X eid %(x)s', {'x': user.eid})]
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    87
        groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')]
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    88
        groups = [u(eid) for eid in groupeids]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    89
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    90
        eid = u(user.eid)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    91
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    92
            'eid': eid, '__type:'+eid: 'CWUser',
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
    93
            '_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject,in_group-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    94
            'login-subject:'+eid:     u(user.login),
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    95
            'surname-subject:'+eid: u'Th\xe9nault',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    96
            'firstname-subject:'+eid:   u'Sylvain',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    97
            'in_group-subject:'+eid:  groups,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
    99
        path, params = self.expect_redirect_handle_request(req, 'edit')
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5038
diff changeset
   100
        e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   101
        self.assertEqual(e.firstname, u'Sylvain')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   102
        self.assertEqual(e.surname, u'Th\xe9nault')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   103
        self.assertEqual(e.login, user.login)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   104
        self.assertEqual([g.eid for g in e.in_group], groupeids)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    def test_user_can_change_its_password(self):
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   107
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   108
        user = self.create_user(req, 'user')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        cnx = self.login('user')
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   110
        eid = u(user.eid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   112
            'eid': eid, '__maineid' : eid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   113
            '__type:'+eid: 'CWUser',
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
   114
            '_cw_entity_fields:'+eid: 'upassword-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   115
            'upassword-subject:'+eid: 'tournicoton',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   116
            'upassword-subject-confirm:'+eid: 'tournicoton',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   118
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
        cnx.commit() # commit to check we don't get late validation error for instance
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   120
        self.assertEqual(path, 'cwuser/user')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
   121
        self.assertFalse('vid' in params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   123
    def test_user_editing_itself_no_relation(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        """checking we can edit an entity without specifying some required
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        relations (meaning no changes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        user = self.user()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   128
        groupeids = [g.eid for g in user.in_group]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   129
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   130
        eid = u(user.eid)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   131
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   132
            'eid':       eid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   133
            '__type:'+eid:    'CWUser',
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
   134
            '_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   135
            'login-subject:'+eid:     u(user.login),
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   136
            'firstname-subject:'+eid: u'Th\xe9nault',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   137
            'surname-subject:'+eid:   u'Sylvain',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   139
        path, params = self.expect_redirect_handle_request(req, 'edit')
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5038
diff changeset
   140
        e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   141
        self.assertEqual(e.login, user.login)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   142
        self.assertEqual(e.firstname, u'Th\xe9nault')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   143
        self.assertEqual(e.surname, u'Sylvain')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   144
        self.assertEqual([g.eid for g in e.in_group], groupeids)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   145
        self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   146
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   147
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    def test_create_multiple_linked(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   149
        gueid = self.execute('CWGroup G WHERE G name "users"')[0][0]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   150
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   151
        req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   153
                    '__type:X': 'CWUser',
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
   154
                    '_cw_entity_fields:X': 'login-subject,upassword-subject,surname-subject,in_group-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   155
                    'login-subject:X': u'adim',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   156
                    'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   157
                    'surname-subject:X': u'Di Mascio',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   158
                    'in_group-subject:X': u(gueid),
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   159
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   160
                    '__type:Y': 'EmailAddress',
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
   161
                    '_cw_entity_fields:Y': 'address-subject,use_email-object',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   162
                    'address-subject:Y': u'dima@logilab.fr',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   163
                    'use_email-object:Y': 'X',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   164
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   165
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        # should be redirected on the created person
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   167
        self.assertEqual(path, 'cwuser/adim')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        e = self.execute('Any P WHERE P surname "Di Mascio"').get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   169
        self.assertEqual(e.surname, 'Di Mascio')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
        email = e.use_email[0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   171
        self.assertEqual(email.address, 'dima@logilab.fr')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   172
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    def test_edit_multiple_linked(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
   174
        req = self.request()
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   175
        peid = u(self.create_user(req, 'adim').eid)
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   176
        req.form = {'eid': [peid, 'Y'], '__maineid': peid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   177
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   178
                    '__type:'+peid: u'CWUser',
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
   179
                    '_cw_entity_fields:'+peid: u'surname-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   180
                    'surname-subject:'+peid: u'Di Masci',
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   181
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   182
                    '__type:Y': u'EmailAddress',
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
   183
                    '_cw_entity_fields:Y': u'address-subject,use_email-object',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   184
                    'address-subject:Y': u'dima@logilab.fr',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   185
                    'use_email-object:Y': peid,
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   186
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   187
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
        # should be redirected on the created person
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   189
        self.assertEqual(path, 'cwuser/adim')
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   190
        e = self.execute('Any P WHERE P surname "Di Masci"').get_entity(0, 0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        email = e.use_email[0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   192
        self.assertEqual(email.address, 'dima@logilab.fr')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   193
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   194
        emaileid = u(email.eid)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   195
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   196
        req.form = {'eid': [peid, emaileid],
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   197
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   198
                    '__type:'+peid: u'CWUser',
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
   199
                    '_cw_entity_fields:'+peid: u'surname-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   200
                    'surname-subject:'+peid: u'Di Masci',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   201
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   202
                    '__type:'+emaileid: u'EmailAddress',
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
   203
                    '_cw_entity_fields:'+emaileid: u'address-subject,use_email-object',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   204
                    'address-subject:'+emaileid: u'adim@logilab.fr',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   205
                    'use_email-object:'+emaileid: peid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   206
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   207
        path, params = self.expect_redirect_handle_request(req, 'edit')
7293
97505b798975 [entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   208
        email.cw_clear_all_caches()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   209
        self.assertEqual(email.address, 'adim@logilab.fr')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   211
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
    def test_password_confirm(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
        """test creation of two linked entities
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   214
        """
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        user = self.user()
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   216
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   217
        req.form = {'eid': 'X',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   218
                    '__cloned_eid:X': u(user.eid), '__type:X': 'CWUser',
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
   219
                    '_cw_entity_fields:X': 'login-subject,upassword-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   220
                    'login-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   221
                    'upassword-subject: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
   222
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   223
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   224
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   225
        self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'})
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   226
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   227
        req.form = {'__cloned_eid:X': u(user.eid),
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   228
                    'eid': 'X', '__type:X': 'CWUser',
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
   229
                    '_cw_entity_fields:X': 'login-subject,upassword-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   230
                    'login-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   231
                    'upassword-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   232
                    'upassword-subject-confirm:X': u'tutu',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   233
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   234
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   235
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   236
        self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
    def test_interval_bound_constraint_success(self):
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   240
        feid = self.execute('INSERT File X: X data_name "toto.txt", X data %(data)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
                            {'data': Binary('yo')})[0][0]
6365
a15cc5e16178 [test] must now commit file creation since the later ValidationError trigger a rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   242
        self.commit()
6410
2e7a7b0829ed [test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6365
diff changeset
   243
        req = self.request(rollbackfirst=True)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   244
        req.form = {'eid': ['X'],
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   245
                    '__type:X': 'Salesterm',
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
   246
                    '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   247
                    'amount-subject:X': u'-10',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   248
                    'described_by_test-subject:X': u(feid),
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   249
                }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   250
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   251
            self.ctrl_publish(req)
7442
aee55fb4633c [test] fix failure introduced by yams'changeset 644:f9c79356b758
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7293
diff changeset
   252
        self.assertEqual(cm.exception.errors, {'amount-subject': 'value -10 must be >= 0'})
6410
2e7a7b0829ed [test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6365
diff changeset
   253
        req = self.request(rollbackfirst=True)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   254
        req.form = {'eid': ['X'],
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   255
                    '__type:X': 'Salesterm',
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
   256
                    '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   257
                    'amount-subject:X': u'110',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   258
                    'described_by_test-subject:X': u(feid),
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   259
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   260
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   261
            self.ctrl_publish(req)
7442
aee55fb4633c [test] fix failure introduced by yams'changeset 644:f9c79356b758
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7293
diff changeset
   262
        self.assertEqual(cm.exception.errors, {'amount-subject': 'value 110 must be <= 100'})
6410
2e7a7b0829ed [test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6365
diff changeset
   263
        req = self.request(rollbackfirst=True)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   264
        req.form = {'eid': ['X'],
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   265
                    '__type:X': 'Salesterm',
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
   266
                    '_cw_entity_fields:X': 'amount-subject,described_by_test-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   267
                    'amount-subject:X': u'10',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   268
                    'described_by_test-subject:X': u(feid),
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   269
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   270
        self.expect_redirect_handle_request(req, 'edit')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   271
        # should be redirected on the created
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        #eid = params['rql'].split()[-1]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
        e = self.execute('Salesterm X').get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   274
        self.assertEqual(e.amount, 10)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
    def test_req_pending_insert(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
        """make sure req's pending insertions are taken into account"""
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   278
        tmpgroup = self.request().create_entity('CWGroup', name=u"test")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
        user = self.user()
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   280
        req = self.request(**req_form(user))
5223
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   281
        req.session.data['pending_insert'] = set([(user.eid, 'in_group', tmpgroup.eid)])
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   282
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   283
        usergroups = [gname for gname, in
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   284
                      self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   285
        self.assertItemsEqual(usergroups, ['managers', 'test'])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   286
        self.assertEqual(get_pending_inserts(req), [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   287
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
    def test_req_pending_delete(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   290
        """make sure req's pending deletions are taken into account"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
        user = self.user()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   292
        groupeid = self.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
                                {'x': user.eid})[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
        usergroups = [gname for gname, in
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
                      self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
        # just make sure everything was set correctly
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   297
        self.assertItemsEqual(usergroups, ['managers', 'test'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
        # now try to delete the relation
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   299
        req = self.request(**req_form(user))
5223
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   300
        req.session.data['pending_delete'] = set([(user.eid, 'in_group', groupeid)])
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   301
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
        usergroups = [gname for gname, in
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
                      self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   304
        self.assertItemsEqual(usergroups, ['managers'])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   305
        self.assertEqual(get_pending_deletes(req), [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
    def test_redirect_apply_button(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
        redirectrql = rql_for_eid(4012) # whatever
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   309
        req = self.request()
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   310
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   311
            'eid': 'A', '__maineid' : 'A',
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
   312
            '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   313
            'content-subject:A': u'"13:03:43"',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   314
            'title-subject:A': u'huuu',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   315
            '__redirectrql': redirectrql,
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   316
            '__redirectvid': 'primary',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   317
            '__redirectparams': 'toto=tutu&tata=titi',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   318
            '__form_id': 'edition',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   319
            '__action_apply': '',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   320
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   321
        path, params = self.expect_redirect_handle_request(req, 'edit')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
   322
        self.assertTrue(path.startswith('blogentry/'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
        eid = path.split('/')[1]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   324
        self.assertEqual(params['vid'], 'edition')
6412
370357e68837 [test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6410
diff changeset
   325
        self.assertNotEqual(int(eid), 4012)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   326
        self.assertEqual(params['__redirectrql'], redirectrql)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   327
        self.assertEqual(params['__redirectvid'], 'primary')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   328
        self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
    def test_redirect_ok_button(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
        redirectrql = rql_for_eid(4012) # whatever
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   332
        req = self.request()
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   333
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   334
            'eid': 'A', '__maineid' : 'A',
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
   335
            '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   336
            'content-subject:A': u'"13:03:43"',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   337
            'title-subject:A': u'huuu',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   338
            '__redirectrql': redirectrql,
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   339
            '__redirectvid': 'primary',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   340
            '__redirectparams': 'toto=tutu&tata=titi',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   341
            '__form_id': 'edition',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   342
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   343
        path, params = self.expect_redirect_handle_request(req, 'edit')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   344
        self.assertEqual(path, 'view')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   345
        self.assertEqual(params['rql'], redirectrql)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   346
        self.assertEqual(params['vid'], 'primary')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   347
        self.assertEqual(params['tata'], 'titi')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   348
        self.assertEqual(params['toto'], 'tutu')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
    def test_redirect_delete_button(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
   351
        req = self.request()
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   352
        eid = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   353
        req.form = {'eid': u(eid), '__type:%s'%eid: 'BlogEntry',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   354
                    '__action_delete': ''}
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   355
        path, params = self.expect_redirect_handle_request(req, 'edit')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   356
        self.assertEqual(path, 'blogentry')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   357
        self.assertIn('_cwmsgid', params)
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   358
        eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
        self.execute('SET X use_email E WHERE E eid %(e)s, X eid %(x)s',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5038
diff changeset
   360
                     {'x': self.session.user.eid, 'e': eid})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
        self.commit()
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   362
        req = req
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   363
        req.form = {'eid': u(eid), '__type:%s'%eid: 'EmailAddress',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   364
                    '__action_delete': ''}
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   365
        path, params = self.expect_redirect_handle_request(req, 'edit')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   366
        self.assertEqual(path, 'cwuser/admin')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   367
        self.assertIn('_cwmsgid', params)
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   368
        eid1 = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   369
        eid2 = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   370
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   371
        req.form = {'eid': [u(eid1), u(eid2)],
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   372
                    '__type:%s'%eid1: 'BlogEntry',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   373
                    '__type:%s'%eid2: 'EmailAddress',
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   374
                    '__action_delete': ''}
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   375
        path, params = self.expect_redirect_handle_request(req, 'edit')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   376
        self.assertEqual(path, 'view')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   377
        self.assertIn('_cwmsgid', params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
7702
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   379
    def test_simple_copy(self):
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   380
        req = self.request()
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   381
        blog = req.create_entity('Blog', title=u'my-blog')
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   382
        blogentry = req.create_entity('BlogEntry', title=u'entry1',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   383
                                      content=u'content1', entry_of=blog)
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   384
        req = self.request()
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   385
        req.form = {'__maineid' : 'X', 'eid': 'X',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   386
                    '__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   387
                    '_cw_entity_fields:X': 'title-subject,content-subject',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   388
                    'title-subject:X': u'entry1-copy',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   389
                    'content-subject:X': u'content1',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   390
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   391
        self.expect_redirect_handle_request(req, 'edit')
7702
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   392
        blogentry2 = req.find_one_entity('BlogEntry', title=u'entry1-copy')
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   393
        self.assertEqual(blogentry2.entry_of[0].eid, blog.eid)
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   394
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   395
    def test_skip_copy_for(self):
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   396
        req = self.request()
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   397
        blog = req.create_entity('Blog', title=u'my-blog')
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   398
        blogentry = req.create_entity('BlogEntry', title=u'entry1',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   399
                                      content=u'content1', entry_of=blog)
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   400
        blogentry.__class__.cw_skip_copy_for = [('entry_of', 'subject')]
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   401
        try:
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   402
            req = self.request()
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   403
            req.form = {'__maineid' : 'X', 'eid': 'X',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   404
                        '__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   405
                        '_cw_entity_fields:X': 'title-subject,content-subject',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   406
                        'title-subject:X': u'entry1-copy',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   407
                        'content-subject:X': u'content1',
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   408
                        }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   409
            self.expect_redirect_handle_request(req, 'edit')
7702
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   410
            blogentry2 = req.find_one_entity('BlogEntry', title=u'entry1-copy')
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   411
            # entry_of should not be copied
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   412
            self.assertEqual(len(blogentry2.entry_of), 0)
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   413
        finally:
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   414
            blogentry.__class__.cw_skip_copy_for = []
73cadb5d0097 [entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7584
diff changeset
   415
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
    def test_nonregr_eetype_etype_editing(self):
4389
14a993bc8d1e useless, same as test_nonregr_eetype_etype_editing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4292
diff changeset
   417
        """non-regression test checking that a manager user can edit a CWEType entity
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   419
        groupeids = sorted(eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")'))
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   420
        groups = [u(eid) for eid in groupeids]
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   421
        cwetypeeid = self.execute('CWEType X WHERE X name "CWEType"')[0][0]
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   422
        basegroups = [u(eid) for eid, in self.execute('CWGroup G WHERE X read_permission G, X eid %(x)s', {'x': cwetypeeid})]
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   423
        cwetypeeid = u(cwetypeeid)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   424
        req = self.request()
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   425
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   426
            'eid':      cwetypeeid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   427
            '__type:'+cwetypeeid:  'CWEType',
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
   428
            '_cw_entity_fields:'+cwetypeeid: 'name-subject,final-subject,description-subject,read_permission-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   429
            'name-subject:'+cwetypeeid:     u'CWEType',
4390
0285c1fa1459 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4389
diff changeset
   430
            'final-subject:'+cwetypeeid:    '',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   431
            'description-subject:'+cwetypeeid:     u'users group',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   432
            'read_permission-subject:'+cwetypeeid:  groups,
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   433
            }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
        try:
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   435
            path, params = self.expect_redirect_handle_request(req, 'edit')
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5038
diff changeset
   436
            e = self.execute('Any X WHERE X eid %(x)s', {'x': cwetypeeid}).get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   437
            self.assertEqual(e.name, 'CWEType')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   438
            self.assertEqual(sorted(g.eid for g in e.read_permission), groupeids)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   440
            # restore
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   441
            self.execute('SET X read_permission Y WHERE X name "CWEType", Y eid IN (%s), NOT X read_permission Y' % (','.join(basegroups)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
            self.commit()
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   443
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
    def test_nonregr_strange_text_input(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   445
        """non-regression test checking text input containing "13:03:43"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   446
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
        this seems to be postgres (tsearch?) specific
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   448
        """
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   449
        req = self.request()
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   450
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   451
            'eid': 'A', '__maineid' : 'A',
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
   452
            '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'title-subject,content-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   453
            'title-subject:A': u'"13:03:40"',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   454
            'content-subject:A': u'"13:03:43"',}
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   455
        path, params = self.expect_redirect_handle_request(req, 'edit')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
   456
        self.assertTrue(path.startswith('blogentry/'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   457
        eid = path.split('/')[1]
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5038
diff changeset
   458
        e = self.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}).get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   459
        self.assertEqual(e.title, '"13:03:40"')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   460
        self.assertEqual(e.content, '"13:03:43"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   461
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   462
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   463
    def test_nonregr_multiple_empty_email_addr(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   464
        gueid = self.execute('CWGroup G WHERE G name "users"')[0][0]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   465
        req = self.request()
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   466
        req.form = {'eid': ['X', 'Y'],
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   467
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   468
                    '__type:X': 'CWUser',
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
   469
                    '_cw_entity_fields:X': 'login-subject,upassword-subject,in_group-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   470
                    'login-subject:X': u'adim',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   471
                    'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   472
                    'in_group-subject:X': `gueid`,
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   473
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   474
                    '__type:Y': 'EmailAddress',
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
   475
                    '_cw_entity_fields:Y': 'address-subject,alias-subject,use_email-object',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   476
                    'address-subject:Y': u'',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   477
                    'alias-subject:Y': u'',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   478
                    'use_email-object:Y': 'X',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   479
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   480
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   481
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   482
        self.assertEqual(cm.exception.errors, {'address-subject': u'required field'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
    def test_nonregr_copy(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
        user = self.user()
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   486
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   487
        req.form = {'__maineid' : 'X', 'eid': 'X',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   488
                    '__cloned_eid:X': user.eid, '__type:X': 'CWUser',
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
   489
                    '_cw_entity_fields:X': 'login-subject,upassword-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   490
                    'login-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   491
                    'upassword-subject:X': u'toto', '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
   492
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   493
        path, params = self.expect_redirect_handle_request(req, 'edit')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   494
        self.assertEqual(path, 'cwuser/toto')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   495
        e = self.execute('Any X WHERE X is CWUser, X login "toto"').get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   496
        self.assertEqual(e.login, 'toto')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   497
        self.assertEqual(e.in_group[0].name, 'managers')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   498
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
    def test_nonregr_rollback_on_validation_error(self):
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   501
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   502
        p = self.create_user(req, "doe")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
        # do not try to skip 'primary_email' for this test
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   504
        old_skips = p.__class__.skip_copy_for
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
        p.__class__.skip_copy_for = ()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
        try:
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   507
            e = self.request().create_entity('EmailAddress', address=u'doe@doe.com')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
            self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
                         {'p' : p.eid, 'e' : e.eid})
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   510
            req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   511
            req.form = {'eid': 'X',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   512
                        '__cloned_eid:X': p.eid, '__type:X': 'CWUser',
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
   513
                        '_cw_entity_fields:X': 'login-subject,surname-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   514
                        'login-subject': u'dodo',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   515
                        'surname-subject:X': u'Boom',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   516
                        '__errorurl' : "whatever but required",
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   517
                        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
            # try to emulate what really happens in the web application
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   519
            # 1/ validate form => EditController.publish raises a ValidationError
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   520
            #    which fires a Redirect
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   521
            # 2/ When re-publishing the copy form, the publisher implicitly commits
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   522
            try:
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   523
                self.app_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   524
            except Redirect:
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   525
                req = self.request()
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   526
                req.form['rql'] = 'Any X WHERE X eid %s' % p.eid
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   527
                req.form['vid'] = 'copy'
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   528
                self.app_handle_request(req, 'view')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   529
            rset = self.execute('CWUser P WHERE P surname "Boom"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   530
            self.assertEqual(len(rset), 0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   531
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   532
            p.__class__.skip_copy_for = old_skips
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   533
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   534
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   535
class EmbedControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   536
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   537
    def test_nonregr_embed_publish(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   538
        # This test looks a bit stupid but at least it will probably
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   539
        # fail if the controller API changes and if EmbedController is not
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   540
        # updated (which is what happened before this test)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   541
        req = self.request()
4824
b01973eff0f7 [test] don't use an internal url for test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4390
diff changeset
   542
        req.form['url'] = 'http://www.logilab.fr/'
2661
f8df42c9da6b [vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2559
diff changeset
   543
        controller = self.vreg['controllers'].select('embed', req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   544
        result = controller.publish(rset=None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   545
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   546
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   547
class ReportBugControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   548
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   549
    def test_usable_by_guest(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
   550
        self.login('anon')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   551
        self.assertRaises(NoSelectableObject,
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   552
                          self.vreg['controllers'].select, 'reportbug', self.request())
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   553
        self.vreg['controllers'].select('reportbug', self.request(description='hop'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   554
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   555
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   556
class SendMailControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   557
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   558
    def test_not_usable_by_guest(self):
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   559
        self.assertRaises(NoSelectableObject,
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   560
                          self.vreg['controllers'].select, 'sendmail', self.request())
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   561
        self.vreg['controllers'].select('sendmail',
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   562
                                        self.request(subject='toto',
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   563
                                                     recipient='toto@logilab.fr',
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   564
                                                     mailbody='hop'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   565
        self.login('anon')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   566
        self.assertRaises(NoSelectableObject,
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   567
                          self.vreg['controllers'].select, 'sendmail', self.request())
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   568
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   569
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   570
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   571
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
   572
    tested_controller = 'ajax'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   573
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   574
    def ctrl(self, req=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   575
        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
   576
        return self.vreg['controllers'].select(self.tested_controller, req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   577
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   578
    def setup_database(self):
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   579
        req = self.request()
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   580
        self.pytag = req.create_entity('Tag', name=u'python')
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   581
        self.cubicwebtag = req.create_entity('Tag', name=u'cubicweb')
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   582
        self.john = self.create_user(req, u'John')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   583
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   584
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   585
    ## tests ##################################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   586
    def test_simple_exec(self):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   587
        req = self.request(rql='CWUser P WHERE P login "John"',
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   588
                           pageid='123', fname='view')
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   589
        ctrl = self.ctrl(req)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   590
        rset = self.john.as_rset()
1797
c2a80130b06d fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents: 1654
diff changeset
   591
        rset.req = req
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
   592
        source = ctrl.publish()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
   593
        self.assertTrue(source.startswith('<?xml version="1.0"?>\n' + STRICT_DOCTYPE +
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
   594
                                          u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">')
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
   595
                        )
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
   596
        req.xhtml_browser = lambda: False
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
   597
        source = ctrl.publish()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7702
diff changeset
   598
        self.assertTrue(source.startswith('<div>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   599
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   600
#     def test_json_exec(self):
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   601
#         rql = 'Any T,N WHERE T is Tag, T name N'
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   602
#         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
   603
#         self.assertEqual(ctrl.publish(),
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   604
#                           json_dumps(self.execute(rql).rows))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   605
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   606
    def test_remote_add_existing_tag(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   607
        self.remote_call('tag_entity', self.john.eid, ['python'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   608
        self.assertItemsEqual(
5223
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   609
            [tname for tname, in self.execute('Any N WHERE T is Tag, T name N')],
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   610
            ['python', 'cubicweb'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   611
        self.assertEqual(
5223
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   612
            self.execute('Any N WHERE T tags P, P is CWUser, T name N').rows,
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   613
            [['python']])
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   614
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   615
    def test_remote_add_new_tag(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   616
        self.remote_call('tag_entity', self.john.eid, ['javascript'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   617
        self.assertItemsEqual(
5223
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   618
            [tname for tname, in self.execute('Any N WHERE T is Tag, T name N')],
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   619
            ['python', 'cubicweb', 'javascript'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   620
        self.assertEqual(
5223
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   621
            self.execute('Any N WHERE T tags P, P is CWUser, T name N').rows,
6abd6e3599f4 #773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5174
diff changeset
   622
            [['javascript']])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   623
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   624
    def test_pending_insertion(self):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   625
        res, req = self.remote_call('add_pending_inserts', [['12', 'tags', '13']])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   626
        deletes = get_pending_deletes(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   627
        self.assertEqual(deletes, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   628
        inserts = get_pending_inserts(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   629
        self.assertEqual(inserts, ['12:tags:13'])
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   630
        res, req = self.remote_call('add_pending_inserts', [['12', 'tags', '14']])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   631
        deletes = get_pending_deletes(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   632
        self.assertEqual(deletes, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   633
        inserts = get_pending_inserts(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   634
        self.assertEqual(inserts, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   635
        inserts = get_pending_inserts(req, 12)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   636
        self.assertEqual(inserts, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   637
        inserts = get_pending_inserts(req, 13)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   638
        self.assertEqual(inserts, ['12:tags:13'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   639
        inserts = get_pending_inserts(req, 14)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   640
        self.assertEqual(inserts, ['12:tags:14'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   641
        req.remove_pending_operations()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   642
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   643
    def test_pending_deletion(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   644
        res, req = self.remote_call('add_pending_delete', ['12', 'tags', '13'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   645
        inserts = get_pending_inserts(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   646
        self.assertEqual(inserts, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   647
        deletes = get_pending_deletes(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   648
        self.assertEqual(deletes, ['12:tags:13'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   649
        res, req = self.remote_call('add_pending_delete', ['12', 'tags', '14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   650
        inserts = get_pending_inserts(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   651
        self.assertEqual(inserts, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   652
        deletes = get_pending_deletes(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   653
        self.assertEqual(deletes, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   654
        deletes = get_pending_deletes(req, 12)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   655
        self.assertEqual(deletes, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   656
        deletes = get_pending_deletes(req, 13)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   657
        self.assertEqual(deletes, ['12:tags:13'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   658
        deletes = get_pending_deletes(req, 14)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   659
        self.assertEqual(deletes, ['12:tags:14'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   660
        req.remove_pending_operations()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   661
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   662
    def test_remove_pending_operations(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   663
        self.remote_call('add_pending_delete', ['12', 'tags', '13'])
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   664
        _, req = self.remote_call('add_pending_inserts', [['12', 'tags', '14']])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   665
        inserts = get_pending_inserts(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   666
        self.assertEqual(inserts, ['12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   667
        deletes = get_pending_deletes(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   668
        self.assertEqual(deletes, ['12:tags:13'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   669
        req.remove_pending_operations()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   670
        self.assertEqual(get_pending_deletes(req), [])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   671
        self.assertEqual(get_pending_inserts(req), [])
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   672
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   673
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   674
    def test_add_inserts(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   675
        res, req = self.remote_call('add_pending_inserts',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   676
                                    [('12', 'tags', '13'), ('12', 'tags', '14')])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   677
        inserts = get_pending_inserts(req)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   678
        self.assertEqual(inserts, ['12:tags:13', '12:tags:14'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   679
        req.remove_pending_operations()
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   680
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   681
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   682
    # silly tests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   683
    def test_external_resource(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   684
        self.assertEqual(self.remote_call('external_resource', 'RSS_LOGO')[0],
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   685
                          json_dumps(self.config.uiprops['RSS_LOGO']))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   686
    def test_i18n(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   687
        self.assertEqual(self.remote_call('i18n', ['bimboom'])[0],
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   688
                          json_dumps(['bimboom']))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   689
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   690
    def test_format_date(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5941
diff changeset
   691
        self.assertEqual(self.remote_call('format_date', '2007-01-01 12:00:00')[0],
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   692
                          json_dumps('2007/01/01'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   693
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   694
    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
   695
        @ajaxfunc
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   696
        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
   697
            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
   698
        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
   699
        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
   700
        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
   701
        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
   702
        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
   703
        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
   704
        req = self.request()
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
   705
        f = appobject(req)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   706
        self.assertEqual(f(12, 13), 'hello')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   707
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   708
    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
   709
        @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
   710
        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
   711
            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
   712
        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
   713
        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
   714
        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
   715
        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
   716
        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
   717
        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
   718
        # no pageid
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   719
        req = self.request()
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
   720
        f = appobject(req)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   721
        self.assertRaises(RemoteCallFailed, f, 12, 13)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   722
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   723
    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
   724
        @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
   725
        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
   726
            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
   727
        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
   728
        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
   729
        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
   730
        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
   731
        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
   732
        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
   733
        # no pageid
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   734
        req = self.request()
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
   735
        f = appobject(req)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   736
        self.assertEqual(f(12, 13), '25')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   737
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   738
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   739
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
   740
    # 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
   741
    #       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
   742
    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
   743
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   744
    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
   745
        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
   746
        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
   747
                                     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
   748
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   749
    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
   750
        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
   751
        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
   752
            # 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
   753
            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
   754
                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
   755
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   756
    def test_monkeypatch_jsoncontroller(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   757
        self.assertRaises(RemoteCallFailed, self.remote_call, 'foo')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   758
        @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
   759
        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
   760
            return u'hello'
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   761
        res, req = self.remote_call('foo')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   762
        self.assertEqual(res, u'hello')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   763
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   764
    def test_monkeypatch_jsoncontroller_xhtmlize(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   765
        self.assertRaises(RemoteCallFailed, self.remote_call, 'foo')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   766
        @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
   767
        @xhtmlize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   768
        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
   769
            return u'hello'
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   770
        res, req = self.remote_call('foo')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   771
        self.assertEqual(res,
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   772
                         '<?xml version="1.0"?>\n' + STRICT_DOCTYPE +
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   773
                         u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">hello</div>')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   774
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   775
    def test_monkeypatch_jsoncontroller_jsonize(self):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   776
        self.assertRaises(RemoteCallFailed, self.remote_call, 'foo')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   777
        @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
   778
        @jsonize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   779
        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
   780
            return 12
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   781
        res, req = self.remote_call('foo')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   782
        self.assertEqual(res, '12')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   783
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
   784
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
   785
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
   786
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
   787
    def setup_database(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
   788
        req = self.request()
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
   789
        self.session.undo_actions = True
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
   790
        self.toto = self.create_user(req, 'toto', password='toto', groups=('users',),
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
   791
                                     commit=False)
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
   792
        self.txuuid_toto = self.commit()
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
   793
        self.toto_email = self.session.create_entity('EmailAddress',
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
   794
                                       address=u'toto@logilab.org',
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
   795
                                       reverse_use_email=self.toto)
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
   796
        self.txuuid_toto_email = self.commit()
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
   797
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
   798
    def test_no_such_transaction(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
   799
        req = self.request()
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
   800
        txuuid = u"12345acbd"
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
   801
        req.form['txuuid'] = txuuid
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
   802
        controller = self.vreg['controllers'].select('undo', req)
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
   803
        with self.assertRaises(tx.NoSuchTransaction) as cm:
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
   804
            result = controller.publish(rset=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
   805
        self.assertEqual(cm.exception.txuuid, txuuid)
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
   806
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
   807
    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
   808
        """ 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
   809
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
   810
        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
   811
        """
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
   812
        req = self.request()
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
   813
        scheme, netloc, path, query, fragment = urlsplit(url)
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
   814
        query_dict = url_parse_query(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
   815
        expected_url = urljoin(req.base_url(), 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
   816
        self.assertEqual( urlunsplit((scheme, netloc, path, None, None)), expected_url)
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
   817
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
   818
    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
   819
        "Check that the potential __redirectpath is honored"
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
   820
        req = self.request()
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
   821
        txuuid = self.txuuid_toto_email
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
   822
        req.form['txuuid'] = txuuid
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
   823
        rpath = "toto"
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
   824
        req.form['__redirectpath'] = rpath
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
   825
        controller = self.vreg['controllers'].select('undo', req)
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
   826
        with self.assertRaises(Redirect) as cm:
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
   827
            result = controller.publish(rset=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
   828
        self.assertURLPath(cm.exception.location, rpath)
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
   829
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
   830
    def test_redirect_default(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
   831
        req = self.request()
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
   832
        txuuid = self.txuuid_toto_email
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
   833
        req.form['txuuid'] = txuuid
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
   834
        req.session.data['breadcrumbs'] = [ urljoin(req.base_url(), 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
   835
                                            for path in ('tata', 'toto',)]
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
   836
        controller = self.vreg['controllers'].select('undo', req)
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
   837
        with self.assertRaises(Redirect) as cm:
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
   838
            result = controller.publish(rset=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
   839
        self.assertURLPath(cm.exception.location, 'toto')
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
   840
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
   841
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   842
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
   843
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   844
    def test_login_with_dest(self):
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   845
        req = self.request()
8487
017af22e7678 [web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8444
diff changeset
   846
        req.form = {'postlogin_path': 'elephants/babar'}
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   847
        with self.assertRaises(Redirect) as cm:
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   848
            self.ctrl_publish(req, ctrl='login')
8487
017af22e7678 [web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8444
diff changeset
   849
        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
   850
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   851
    def test_login_no_dest(self):
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   852
        req = self.request()
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   853
        with self.assertRaises(Redirect) as cm:
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   854
            self.ctrl_publish(req, ctrl='login')
8487
017af22e7678 [web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8444
diff changeset
   855
        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
   856
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   857
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   858
    unittest_main()