web/test/unittest_urlpublisher.py
author David Douard <david.douard@logilab.fr>
Thu, 07 Jan 2016 12:20:50 +0100
changeset 11054 aec47ca624b2
parent 9839 cf00a6a3f401
child 10467 73ea636a5562
permissions -rw-r--r--
[pkg] rql 0.34 and logilab-database 1.15 break cubicweb 3.21
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
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
from cubicweb.web import NotFound, Redirect
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')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    69
            self.assertEqual("Any X,AA,AB ORDERBY AA WHERE X is_instance_of CWEType, "
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    70
                             "X name AA, X modification_date AB",
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    71
                             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
    72
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    73
    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
    74
        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
    75
            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
    76
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    77
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    78
            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
    79
            self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    80
                             'X login AA, X firstname AB, X surname AC, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    81
                             'X modification_date AD, X login "admin"',
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    82
                             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
    83
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    84
    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
    85
        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
    86
            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
    87
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    88
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    89
            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
    90
            self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    91
                             'X login AA, X firstname AB, X surname AC, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    92
                             'X modification_date AD, X login "admin"',
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    93
                             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
    94
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    95
    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
    96
        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
    97
            ctrl, rset = self.process(req, 'cwuser/eid/%s' % self.user(req).eid)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    98
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
    99
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   100
            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
   101
            self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   102
                             'X login AA, X firstname AB, X surname AC, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   103
                             'X modification_date AD, X eid %s' % rset[0][0],
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   104
                             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
   105
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   106
    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
   107
        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
   108
            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
   109
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   110
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   111
            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
   112
            self.assertEqual(u'Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   113
                             u'X login AA, X firstname AB, X surname AC, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   114
                             u'X modification_date AD, X login "\xffsa\xffe"',
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   115
                             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
   116
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   117
    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
   118
        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
   119
            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
   120
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   121
            self.assertEqual(len(rset), 1)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   122
            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
   123
            self.assertEqual(u'Any X,AA,AB,AC WHERE X is_instance_of BlogEntry, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   124
                             'X creation_date AA, X title AB, X modification_date AC, '
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   125
                             'X title "hell\'o"',
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   126
                             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
   127
cd2ea273007a [web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   128
    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
   129
        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
   130
            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
   131
            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
   132
            self.assertRaises(NotFound, self.process, req, 'CWUser/inexistant_attribute/joe')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   133
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
    def test_action_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        """tests the action path resolution"""
9839
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   136
        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
   137
            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
   138
            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
   139
            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
   140
            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
   141
            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
   142
            self.assertRaises(NotFound, self.process, req, 'CWUser/login/admin/non_action')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    def test_regexp_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
        """tests the regexp 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
            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
   149
            self.assertEqual(ctrl, 'view')
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   150
            self.assertEqual(rset, None)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   151
            self.assertEqual(req.form, {'etype' : "Task", 'vid' : "creation"})
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, 'add/foo/bar')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    def test_nonascii_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
        oldrules = SimpleReqRewriter.rules
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        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
   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
            try:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   159
                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
   160
                ctrl, rset = self.process(req, path)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   161
                self.assertEqual(rset, None)
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   162
                self.assertEqual(req.form, {'vid' : "foo"})
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   163
            finally:
cf00a6a3f401 [webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9359
diff changeset
   164
                SimpleReqRewriter.rules = oldrules
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   165
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    unittest_main()