web/test/unittest_urlpublisher.py
author Julien Cristau <julien.cristau@logilab.fr>
Wed, 06 Jan 2016 11:47:08 +0100
changeset 11080 245f440b814a
parent 10890 504a67206fdc
permissions -rw-r--r--
[devtools] fix get_bounds Say an attribute has two IntervalBoundConstraints, one with minvalue=0 and the other with maxvalue=10 (not literally, or that could be a single constraint, but e.g. with references to other attributes). We don't want to override the minvalue of the former with None just because the latter happens last in the constraints list. This doesn't fix the case where two constraints both have a min or a max value. Meh.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
     2
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
# 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: 4252
diff changeset
     4
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
# 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: 4252
diff changeset
     6
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# 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: 4252
diff changeset
     8
# 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: 4252
diff changeset
     9
# 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: 4252
diff changeset
    10
# 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: 4252
diff changeset
    11
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    12
# 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: 4252
diff changeset
    13
# 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: 4252
diff changeset
    14
# 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: 4252
diff changeset
    15
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# 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: 4252
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6315
8ca3ee849bee [test] fix broken tests and minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    19
"""Unit tests for url publishing service"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
import re
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
from cubicweb.rset import ResultSet
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    26
from cubicweb.devtools.testlib import CubicWebTC
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    27
from cubicweb.devtools.fake import FakeRequest
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
    28
from cubicweb.web import NotFound, Redirect, views
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
from cubicweb.web.views.urlrewrite import SimpleReqRewriter
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    32
class URLPublisherTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
    """test suite for QSPreProcessor"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    def setup_database(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    36
        with self.admin_access.repo_cnx() as cnx:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    37
            self.create_user(cnx, u'ÿsaÿe')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    38
            b = cnx.create_entity('BlogEntry', title=u'hell\'o', content=u'blabla')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    39
            # take care: Tag's name normalized to lower case
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    40
            c = cnx.create_entity('Tag', name=u'yo')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    41
            cnx.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s',
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    42
                        {'c':c.eid, 'b':b.eid})
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    43
            cnx.commit()
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    44
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    45
    def process(self, req, url):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    46
        return self.app.url_resolver.process(req, url)
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    47
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    def test_raw_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        """tests raw path resolution'"""
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    50
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    51
            self.assertEqual(self.process(req, 'view'), ('view', None))
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    52
            self.assertEqual(self.process(req, 'edit'), ('edit', None))
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    53
            self.assertRaises(NotFound, self.process, req, 'whatever')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    def test_eid_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        """tests eid path resolution"""
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    57
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    58
            self.assertIsInstance(self.process(req, '123')[1], ResultSet)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    59
            self.assertEqual(len(self.process(req, '123')[1]), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    60
            self.assertRaises(NotFound, self.process, req, '123/345')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    61
            self.assertRaises(NotFound, self.process, req, 'not_eid')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    63
    def test_rest_path_etype(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        """tests the rest path resolution"""
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    65
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    66
            ctrl, rset = self.process(req, 'CWEType')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    67
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    68
            self.assertEqual(rset.description[0][0], 'CWEType')
10467
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
    69
            self.assertEqual("Any X,AA,AB ORDERBY AB WHERE X is_instance_of CWEType, "
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
    70
                             "X modification_date AA, X name AB",
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    71
                             rset.printable_rql())
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
    72
            self.assertEqual(req.form['vid'], 'sameetypelist')
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    73
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    74
    def test_rest_path_by_attr(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    75
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    76
            ctrl, rset = self.process(req, 'CWUser/login/admin')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    77
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    78
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    79
            self.assertEqual(rset.description[0][0], 'CWUser')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    80
            self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
10467
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
    81
                             'X firstname AA, X login AB, X modification_date AC, '
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
    82
                             'X surname AD, X login "admin"',
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    83
                             rset.printable_rql())
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    84
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    85
    def test_rest_path_unique_attr(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    86
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    87
            ctrl, rset = self.process(req, 'cwuser/admin')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    88
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    89
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    90
            self.assertEqual(rset.description[0][0], 'CWUser')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    91
            self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
10467
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
    92
                             'X firstname AA, X login AB, X modification_date AC, '
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
    93
                             'X surname AD, X login "admin"',
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    94
                             rset.printable_rql())
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
    95
            self.assertEqual(req.form['vid'], 'primary')
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    96
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    97
    def test_rest_path_eid(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    98
        with self.admin_access.web_request() as req:
10890
504a67206fdc [web/test] Remove use of old test API to silence warning
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10582
diff changeset
    99
            ctrl, rset = self.process(req, 'cwuser/eid/%s' % req.user.eid)
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   100
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   101
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   102
            self.assertEqual(rset.description[0][0], 'CWUser')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   103
            self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
10467
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
   104
                             'X firstname AA, X login AB, X modification_date AC, '
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
   105
                             'X surname AD, X eid %s' % rset[0][0],
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   106
                             rset.printable_rql())
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   107
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   108
    def test_rest_path_non_ascii_paths(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   109
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   110
            ctrl, rset = self.process(req, 'CWUser/login/%C3%BFsa%C3%BFe')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   111
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   112
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   113
            self.assertEqual(rset.description[0][0], 'CWUser')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   114
            self.assertEqual(u'Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
10467
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
   115
                             u'X firstname AA, X login AB, X modification_date AC, '
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
   116
                             u'X surname AD, X login "\xffsa\xffe"',
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   117
                             rset.printable_rql())
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   118
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   119
    def test_rest_path_quoted_paths(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   120
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   121
            ctrl, rset = self.process(req, 'BlogEntry/title/hell%27o')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   122
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   123
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   124
            self.assertEqual(rset.description[0][0], 'BlogEntry')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   125
            self.assertEqual(u'Any X,AA,AB,AC WHERE X is_instance_of BlogEntry, '
10467
73ea636a5562 [entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9839
diff changeset
   126
                             'X creation_date AA, X modification_date AB, X title AC, '
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   127
                             'X title "hell\'o"',
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   128
                             rset.printable_rql())
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   129
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   130
    def test_rest_path_use_vid_from_rset(self):
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   131
        with self.admin_access.web_request(headers={'Accept': 'application/rdf+xml'}) as req:
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   132
            views.VID_BY_MIMETYPE['application/rdf+xml'] = 'rdf'
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   133
            try:
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   134
                ctrl, rset = self.process(req, 'CWEType')
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   135
            finally:
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   136
                views.VID_BY_MIMETYPE.pop('application/rdf+xml')
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   137
            self.assertEqual(req.form['vid'], 'rdf')
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   138
7017
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   139
    def test_rest_path_errors(self):
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   140
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   141
            self.assertRaises(NotFound, self.process, req, 'CWUser/eid/30000')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   142
            self.assertRaises(NotFound, self.process, req, 'Workcases')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   143
            self.assertRaises(NotFound, self.process, req, 'CWUser/inexistant_attribute/joe')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   144
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    def test_action_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
        """tests the action path resolution"""
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   147
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   148
            self.assertRaises(Redirect, self.process, req, '1/edit')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   149
            self.assertRaises(Redirect, self.process, req, 'Tag/name/yo/edit')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   150
            self.assertRaises(Redirect, self.process, req, 'Tag/yo/edit')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   151
            self.assertRaises(NotFound, self.process, req, 'view/edit')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   152
            self.assertRaises(NotFound, self.process, req, '1/non_action')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   153
            self.assertRaises(NotFound, self.process, req, 'CWUser/login/admin/non_action')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    def test_regexp_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        """tests the regexp path resolution"""
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   157
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   158
            ctrl, rset = self.process(req, 'add/Task')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   159
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   160
            self.assertEqual(rset, None)
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   161
            self.assertEqual(req.form, {'etype': "Task", 'vid': "creation"})
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   162
            self.assertRaises(NotFound, self.process, req, 'add/foo/bar')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
    def test_nonascii_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        oldrules = SimpleReqRewriter.rules
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   166
        SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo'))]
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   167
        with self.admin_access.web_request() as req:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   168
            try:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   169
                path = str(FakeRequest().url_quote(u'été'))
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   170
                ctrl, rset = self.process(req, path)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   171
                self.assertEqual(rset, None)
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10467
diff changeset
   172
                self.assertEqual(req.form, {'vid': "foo"})
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   173
            finally:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   174
                SimpleReqRewriter.rules = oldrules
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   175
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    unittest_main()