web/test/unittest_views_basecontrollers.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 17 Sep 2012 17:48:55 +0200
changeset 8556 bbe0d6985e59
parent 8544 3d049071957e
child 8594 001159e2e4f3
permissions -rw-r--r--
[validation error] refactor validation error handling so translation is done on the web side Users should now use cubicweb.validation_error helper function that will activate the feature with other handy behaviours. Also test testing for message in errors should call exception.tr(unicode) before comparing. Using bare ValidationError keep backward compat.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8544
3d049071957e massive copyright update to avoid clutering later patches
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8504
diff changeset
     1
# copyright 2003-2012 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)
8556
bbe0d6985e59 [validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8544
diff changeset
    80
        cm.exception.tr(unicode)
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
    81
        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
    82
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    def test_user_editing_itself(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
        """checking that a manager user can edit itself
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        user = self.user()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    87
        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
    88
        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
    89
        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
    90
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    91
        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
    92
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    93
            '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
    94
            '_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
    95
            'login-subject:'+eid:     u(user.login),
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    96
            'surname-subject:'+eid: u'Th\xe9nault',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    97
            'firstname-subject:'+eid:   u'Sylvain',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    98
            'in_group-subject:'+eid:  groups,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   100
        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
   101
        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
   102
        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
   103
        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
   104
        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
   105
        self.assertEqual([g.eid for g in e.in_group], groupeids)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    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
   108
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   109
        user = self.create_user(req, 'user')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        cnx = self.login('user')
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   111
        eid = u(user.eid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   113
            'eid': eid, '__maineid' : eid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   114
            '__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
   115
            '_cw_entity_fields:'+eid: 'upassword-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   116
            'upassword-subject:'+eid: 'tournicoton',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   117
            'upassword-subject-confirm:'+eid: 'tournicoton',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   119
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        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
   121
        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
   122
        self.assertFalse('vid' in params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   124
    def test_user_editing_itself_no_relation(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        """checking we can edit an entity without specifying some required
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        relations (meaning no changes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
        user = self.user()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   129
        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
   130
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   131
        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
   132
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   133
            'eid':       eid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   134
            '__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
   135
            '_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
   136
            'login-subject:'+eid:     u(user.login),
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   137
            'firstname-subject:'+eid: u'Th\xe9nault',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   138
            'surname-subject:'+eid:   u'Sylvain',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   140
        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
   141
        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
   142
        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
   143
        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
   144
        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
   145
        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
   146
        self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   147
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   148
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
    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
   150
        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
   151
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   152
        req.form = {'eid': ['X', 'Y'], '__maineid' : 'X',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   154
                    '__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
   155
                    '_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
   156
                    'login-subject:X': u'adim',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   157
                    '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
   158
                    'surname-subject:X': u'Di Mascio',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   159
                    'in_group-subject:X': u(gueid),
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   160
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   161
                    '__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
   162
                    '_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
   163
                    'address-subject:Y': u'dima@logilab.fr',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   164
                    '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
   165
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   166
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
        # 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
   168
        self.assertEqual(path, 'cwuser/adim')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
        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
   170
        self.assertEqual(e.surname, 'Di Mascio')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        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
   172
        self.assertEqual(email.address, 'dima@logilab.fr')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   173
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    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
   175
        req = self.request()
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   176
        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
   177
        req.form = {'eid': [peid, 'Y'], '__maineid': peid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   178
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   179
                    '__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
   180
                    '_cw_entity_fields:'+peid: u'surname-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   181
                    'surname-subject:'+peid: u'Di Masci',
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   182
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   183
                    '__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
   184
                    '_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
   185
                    'address-subject:Y': u'dima@logilab.fr',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   186
                    '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
   187
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   188
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
        # 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
   190
        self.assertEqual(path, 'cwuser/adim')
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   191
        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
   192
        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
   193
        self.assertEqual(email.address, 'dima@logilab.fr')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   194
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   195
        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
   196
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   197
        req.form = {'eid': [peid, emaileid],
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   198
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   199
                    '__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
   200
                    '_cw_entity_fields:'+peid: u'surname-subject',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   201
                    'surname-subject:'+peid: u'Di Masci',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   202
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   203
                    '__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
   204
                    '_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
   205
                    'address-subject:'+emaileid: u'adim@logilab.fr',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   206
                    'use_email-object:'+emaileid: peid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   207
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   208
        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
   209
        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
   210
        self.assertEqual(email.address, 'adim@logilab.fr')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   212
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    def test_password_confirm(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        """test creation of two linked entities
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   215
        """
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
        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
   217
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   218
        req.form = {'eid': 'X',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   219
                    '__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
   220
                    '_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
   221
                    'login-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   222
                    '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
   223
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   224
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   225
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   226
        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
   227
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   228
        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
   229
                    '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
   230
                    '_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
   231
                    'login-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   232
                    'upassword-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   233
                    '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
   234
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   235
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   236
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   237
        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
   238
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
    def test_interval_bound_constraint_success(self):
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   241
        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
   242
                            {'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
   243
        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
   244
        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
   245
        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
   246
                    '__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
   247
                    '_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
   248
                    'amount-subject:X': u'-10',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   249
                    '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
   250
                }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   251
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   252
            self.ctrl_publish(req)
8556
bbe0d6985e59 [validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8544
diff changeset
   253
        cm.exception.tr(unicode)
7442
aee55fb4633c [test] fix failure introduced by yams'changeset 644:f9c79356b758
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7293
diff changeset
   254
        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
   255
        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
   256
        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
   257
                    '__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
   258
                    '_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
   259
                    'amount-subject:X': u'110',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   260
                    '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
   261
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   262
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   263
            self.ctrl_publish(req)
8556
bbe0d6985e59 [validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8544
diff changeset
   264
        cm.exception.tr(unicode)
7442
aee55fb4633c [test] fix failure introduced by yams'changeset 644:f9c79356b758
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7293
diff changeset
   265
        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
   266
        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
   267
        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
   268
                    '__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
   269
                    '_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
   270
                    'amount-subject:X': u'10',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   271
                    '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
   272
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   273
        self.expect_redirect_handle_request(req, 'edit')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   274
        # should be redirected on the created
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
        #eid = params['rql'].split()[-1]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
        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
   277
        self.assertEqual(e.amount, 10)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   278
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
    def test_req_pending_insert(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   280
        """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
   281
        tmpgroup = self.request().create_entity('CWGroup', name=u"test")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   282
        user = self.user()
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   283
        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
   284
        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
   285
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   286
        usergroups = [gname for gname, in
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   287
                      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
   288
        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
   289
        self.assertEqual(get_pending_inserts(req), [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   290
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   292
    def test_req_pending_delete(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
        """make sure req's pending deletions are taken into account"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
        user = self.user()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   295
        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
   296
                                {'x': user.eid})[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
        usergroups = [gname for gname, in
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
                      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
   299
        # 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
   300
        self.assertItemsEqual(usergroups, ['managers', 'test'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
        # now try to delete the relation
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   302
        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
   303
        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
   304
        path, params = self.expect_redirect_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
        usergroups = [gname for gname, in
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
                      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
   307
        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
   308
        self.assertEqual(get_pending_deletes(req), [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
    def test_redirect_apply_button(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
        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
   312
        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
   313
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   314
            '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
   315
            '__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
   316
            'content-subject:A': u'"13:03:43"',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   317
            '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
   318
            '__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
   319
            '__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
   320
            '__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
   321
            '__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
   322
            '__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
   323
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   324
        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
   325
        self.assertTrue(path.startswith('blogentry/'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
        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
   327
        self.assertEqual(params['vid'], 'edition')
6412
370357e68837 [test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6410
diff changeset
   328
        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
   329
        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
   330
        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
   331
        self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
    def test_redirect_ok_button(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
        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
   335
        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
   336
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   337
            '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
   338
            '__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
   339
            'content-subject:A': u'"13:03:43"',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   340
            '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
   341
            '__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
   342
            '__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
   343
            '__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
   344
            '__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
   345
            }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   346
        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
   347
        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
   348
        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
   349
        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
   350
        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
   351
        self.assertEqual(params['toto'], 'tutu')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
    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
   354
        req = self.request()
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   355
        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
   356
        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
   357
                    '__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
   358
        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
   359
        self.assertEqual(path, 'blogentry')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   360
        self.assertIn('_cwmsgid', params)
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   361
        eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
        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
   363
                     {'x': self.session.user.eid, 'e': eid})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
        self.commit()
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   365
        req = req
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   366
        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
   367
                    '__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
   368
        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
   369
        self.assertEqual(path, 'cwuser/admin')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   370
        self.assertIn('_cwmsgid', params)
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   371
        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
   372
        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
   373
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   374
        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
   375
                    '__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
   376
                    '__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
   377
                    '__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
   378
        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
   379
        self.assertEqual(path, 'view')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   380
        self.assertIn('_cwmsgid', params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
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
   382
    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
   383
        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
   384
        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
   385
        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
   386
                                      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
   387
        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
   388
        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
   389
                    '__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
   390
                    '_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
   391
                    '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
   392
                    '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
   393
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   394
        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
   395
        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
   396
        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
   397
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
    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
   399
        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
   400
        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
   401
        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
   402
                                      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
   403
        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
   404
        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
   405
            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
   406
            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
   407
                        '__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
   408
                        '_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
   409
                        '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
   410
                        '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
   411
                        }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   412
            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
   413
            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
   414
            # 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
   415
            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
   416
        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
   417
            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
   418
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
    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
   420
        """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
   421
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   422
        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
   423
        groups = [u(eid) for eid in groupeids]
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   424
        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
   425
        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
   426
        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
   427
        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
   428
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   429
            'eid':      cwetypeeid,
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   430
            '__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
   431
            '_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
   432
            'name-subject:'+cwetypeeid:     u'CWEType',
4390
0285c1fa1459 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4389
diff changeset
   433
            'final-subject:'+cwetypeeid:    '',
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   434
            'description-subject:'+cwetypeeid:     u'users group',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   435
            '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
   436
            }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
        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
   438
            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
   439
            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
   440
            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
   441
            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
   442
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
            # restore
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   444
            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
   445
            self.commit()
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   446
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
    def test_nonregr_strange_text_input(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   448
        """non-regression test checking text input containing "13:03:43"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
        this seems to be postgres (tsearch?) specific
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   451
        """
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   452
        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
   453
        req.form = {
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   454
            '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
   455
            '__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
   456
            'title-subject:A': u'"13:03:40"',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   457
            '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
   458
        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
   459
        self.assertTrue(path.startswith('blogentry/'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   460
        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
   461
        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
   462
        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
   463
        self.assertEqual(e.content, '"13:03:43"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   464
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   465
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   466
    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
   467
        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
   468
        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
   469
        req.form = {'eid': ['X', 'Y'],
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   470
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   471
                    '__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
   472
                    '_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
   473
                    'login-subject:X': u'adim',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   474
                    '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
   475
                    'in_group-subject:X': `gueid`,
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   476
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   477
                    '__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
   478
                    '_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
   479
                    'address-subject:Y': u'',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   480
                    'alias-subject:Y': u'',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   481
                    '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
   482
                    }
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   483
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   484
            self.ctrl_publish(req)
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6412
diff changeset
   485
        self.assertEqual(cm.exception.errors, {'address-subject': u'required field'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
    def test_nonregr_copy(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
        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
   489
        req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   490
        req.form = {'__maineid' : 'X', 'eid': 'X',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   491
                    '__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
   492
                    '_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
   493
                    'login-subject:X': u'toto',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   494
                    '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
   495
                    }
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8311
diff changeset
   496
        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
   497
        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
   498
        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
   499
        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
   500
        self.assertEqual(e.in_group[0].name, 'managers')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
    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
   504
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   505
        p = self.create_user(req, "doe")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
        # do not try to skip 'primary_email' for this test
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
        old_skips = p.__class__.skip_copy_for
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
        p.__class__.skip_copy_for = ()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
        try:
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   510
            e = self.request().create_entity('EmailAddress', address=u'doe@doe.com')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
            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
   512
                         {'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
   513
            req = self.request()
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   514
            req.form = {'eid': 'X',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   515
                        '__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
   516
                        '_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
   517
                        'login-subject': u'dodo',
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   518
                        '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
   519
                        '__errorurl' : "whatever but required",
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   520
                        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   521
            # try to emulate what really happens in the web application
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   522
            # 1/ validate form => EditController.publish raises a ValidationError
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   523
            #    which fires a Redirect
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   524
            # 2/ When re-publishing the copy form, the publisher implicitly commits
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   525
            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
   526
                self.app_handle_request(req, 'edit')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   527
            except Redirect:
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
   528
                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
   529
                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
   530
                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
   531
                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
   532
            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
   533
            self.assertEqual(len(rset), 0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   534
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   535
            p.__class__.skip_copy_for = old_skips
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
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   538
class EmbedControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   539
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   540
    def test_nonregr_embed_publish(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   541
        # This test looks a bit stupid but at least it will probably
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   542
        # fail if the controller API changes and if EmbedController is not
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   543
        # updated (which is what happened before this test)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   544
        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
   545
        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
   546
        controller = self.vreg['controllers'].select('embed', req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   547
        result = controller.publish(rset=None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   548
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   549
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
class ReportBugControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   551
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   552
    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
   553
        self.login('anon')
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   554
        self.assertRaises(NoSelectableObject,
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   555
                          self.vreg['controllers'].select, 'reportbug', self.request())
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   556
        self.vreg['controllers'].select('reportbug', self.request(description='hop'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   557
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   558
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   559
class SendMailControllerTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   560
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6875
diff changeset
   561
    def test_not_usable_by_guest(self):
4918
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   562
        self.assertRaises(NoSelectableObject,
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   563
                          self.vreg['controllers'].select, 'sendmail', self.request())
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   564
        self.vreg['controllers'].select('sendmail',
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   565
                                        self.request(subject='toto',
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   566
                                                     recipient='toto@logilab.fr',
520e7fb542cf test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4824
diff changeset
   567
                                                     mailbody='hop'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   568
        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
   569
        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
   570
                          self.vreg['controllers'].select, 'sendmail', self.request())
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   571
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   572
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   573
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   574
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
   575
    tested_controller = 'ajax'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   576
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   577
    def ctrl(self, req=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   578
        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
   579
        return self.vreg['controllers'].select(self.tested_controller, req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   580
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   581
    def setup_database(self):
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   582
        req = self.request()
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   583
        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
   584
        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
   585
        self.john = self.create_user(req, u'John')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   586
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   587
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   588
    ## tests ##################################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   589
    def test_simple_exec(self):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   590
        req = self.request(rql='CWUser P WHERE P login "John"',
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   591
                           pageid='123', fname='view')
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   592
        ctrl = self.ctrl(req)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   593
        rset = self.john.as_rset()
1797
c2a80130b06d fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents: 1654
diff changeset
   594
        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
   595
        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
   596
        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
   597
                                          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
   598
                        )
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
   599
        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
   600
        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
   601
        self.assertTrue(source.startswith('<div>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   602
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   603
#     def test_json_exec(self):
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   604
#         rql = 'Any T,N WHERE T is Tag, T name N'
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   605
#         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
   606
#         self.assertEqual(ctrl.publish(),
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   607
#                           json_dumps(self.execute(rql).rows))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   608
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   609
    def test_remote_add_existing_tag(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   610
        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
   611
        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
   612
            [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
   613
            ['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
   614
        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
   615
            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
   616
            [['python']])
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   617
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   618
    def test_remote_add_new_tag(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   619
        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
   620
        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
   621
            [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
   622
            ['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
   623
        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
   624
            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
   625
            [['javascript']])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   626
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   627
    def test_pending_insertion(self):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   628
        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
   629
        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
   630
        self.assertEqual(deletes, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   631
        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
   632
        self.assertEqual(inserts, ['12:tags:13'])
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   633
        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
   634
        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
   635
        self.assertEqual(deletes, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   636
        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
   637
        self.assertEqual(inserts, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   638
        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
   639
        self.assertEqual(inserts, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   640
        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
   641
        self.assertEqual(inserts, ['12:tags:13'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   642
        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
   643
        self.assertEqual(inserts, ['12:tags:14'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   644
        req.remove_pending_operations()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   645
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   646
    def test_pending_deletion(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   647
        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
   648
        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
   649
        self.assertEqual(inserts, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   650
        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
   651
        self.assertEqual(deletes, ['12:tags:13'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   652
        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
   653
        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
   654
        self.assertEqual(inserts, [])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   655
        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
   656
        self.assertEqual(deletes, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   657
        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
   658
        self.assertEqual(deletes, ['12:tags:13', '12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   659
        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
   660
        self.assertEqual(deletes, ['12:tags:13'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   661
        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
   662
        self.assertEqual(deletes, ['12:tags:14'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   663
        req.remove_pending_operations()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   664
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   665
    def test_remove_pending_operations(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   666
        self.remote_call('add_pending_delete', ['12', 'tags', '13'])
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1426
diff changeset
   667
        _, 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
   668
        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
   669
        self.assertEqual(inserts, ['12:tags:14'])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   670
        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
   671
        self.assertEqual(deletes, ['12:tags:13'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   672
        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
   673
        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
   674
        self.assertEqual(get_pending_inserts(req), [])
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   675
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   676
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   677
    def test_add_inserts(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   678
        res, req = self.remote_call('add_pending_inserts',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   679
                                    [('12', 'tags', '13'), ('12', 'tags', '14')])
4292
3fc808b0490b test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4266
diff changeset
   680
        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
   681
        self.assertEqual(inserts, ['12:tags:13', '12:tags:14'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   682
        req.remove_pending_operations()
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   683
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   684
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   685
    # silly tests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   686
    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
   687
        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
   688
                          json_dumps(self.config.uiprops['RSS_LOGO']))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   689
    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
   690
        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
   691
                          json_dumps(['bimboom']))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   692
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   693
    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
   694
        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
   695
                          json_dumps('2007/01/01'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   696
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   697
    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
   698
        @ajaxfunc
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   699
        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
   700
            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
   701
        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
   702
        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
   703
        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
   704
        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
   705
        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
   706
        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
   707
        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
   708
        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
   709
        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
   710
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   711
    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
   712
        @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
   713
        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
   714
            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
   715
        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
   716
        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
   717
        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
   718
        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
   719
        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
   720
        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
   721
        # 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
   722
        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
   723
        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
   724
        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
   725
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   726
    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
   727
        @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
   728
        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
   729
            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
   730
        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
   731
        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
   732
        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
   733
        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
   734
        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
   735
        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
   736
        # 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
   737
        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
   738
        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
   739
        self.assertEqual(f(12, 13), '25')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   740
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   741
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   742
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
   743
    # 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
   744
    #       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
   745
    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
   746
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   747
    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
   748
        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
   749
        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
   750
                                     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
   751
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   752
    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
   753
        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
   754
        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
   755
            # 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
   756
            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
   757
                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
   758
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 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
   760
        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
   761
        @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
   762
        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
   763
            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
   764
        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
   765
        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
   766
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   767
    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
   768
        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
   769
        @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
   770
        @xhtmlize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   771
        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
   772
            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
   773
        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
   774
        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
   775
                         '<?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
   776
                         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
   777
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   778
    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
   779
        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
   780
        @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
   781
        @jsonize
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   782
        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
   783
            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
   784
        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
   785
        self.assertEqual(res, '12')
1426
379261551578 remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   786
8504
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   787
    def test_monkeypatch_jsoncontroller_stdfunc(self):
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   788
        @monkeypatch(JSonController)
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   789
        @jsonize
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   790
        def js_reledit_form(self):
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   791
            return 12
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   792
        res, req = self.remote_call('reledit_form')
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   793
        self.assertEqual(res, '12')
f21c72928662 [ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8487
diff changeset
   794
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
   795
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
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
   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 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
   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
        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
   801
        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
   802
                                     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
   803
        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
   804
        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
   805
                                       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
   806
                                       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
   807
        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
   808
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
    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
   810
        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
   811
        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
   812
        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
   813
        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
   814
        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
   815
            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
   816
        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
   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 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
   819
        """ 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
   820
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
        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
   822
        """
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
        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
   824
        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
   825
        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
   826
        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
   827
        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
   828
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
    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
   830
        "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
   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
        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
   835
        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
   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, 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
   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
    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
   842
        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
   843
        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
   844
        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
   845
        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
   846
                                            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
   847
        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
   848
        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
   849
            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
   850
        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
   851
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
   852
8311
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   853
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
   854
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   855
    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
   856
        req = self.request()
8487
017af22e7678 [web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8444
diff changeset
   857
        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
   858
        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
   859
            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
   860
        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
   861
76a44a0d7f4b [login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8267
diff changeset
   862
    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
   863
        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
   864
        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
   865
            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
   866
        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
   867
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   868
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   869
    unittest_main()