devtools/test/unittest_testlib.py
author Rabah Meradi <rabah.meradi@logilab.fr>
Tue, 23 Jun 2015 13:08:48 +0200
changeset 10456 e7ee508a8b2f
parent 10219 eacb8ea38bf5
child 10468 3f27669634d2
child 10639 1ed205146ee2
permissions -rw-r--r--
[js] Using appropriate http method when calling a remote function to respect REST principles. closes #5355952
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
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: 5390
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6776
eebe86b89285 [tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6341
diff changeset
    18
"""unittests for cw.devtools.testlib module"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
from cStringIO import StringIO
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
6776
eebe86b89285 [tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6341
diff changeset
    22
from unittest import TextTestRunner
9212
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
    23
6776
eebe86b89285 [tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6341
diff changeset
    24
from logilab.common.testlib import TestSuite, TestCase, unittest_main
9212
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
    25
from logilab.common.registry import yes
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
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
from cubicweb.devtools import htmlparser
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    28
from cubicweb.devtools.testlib import CubicWebTC
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4473
diff changeset
    29
from cubicweb.pytestconf import clean_repo_test_cls
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
10219
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    31
class FakeFormTC(TestCase):
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    32
    def test_fake_form(self):
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    33
        class entity:
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    34
            cw_etype = 'Entity'
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    35
            eid = 0
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    36
        sio = StringIO('hop\n')
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    37
        form = CubicWebTC.fake_form('import',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    38
                                    {'file': ('filename.txt', sio),
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    39
                                     'encoding': u'utf-8',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    40
                                    }, [(entity, {'field': 'value'})])
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    41
        self.assertEqual(form, {'__form_id': 'import',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    42
                                '__maineid': 0,
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    43
                                '__type:0': 'Entity',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    44
                                '_cw_entity_fields:0': '__type,field',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    45
                                '_cw_fields': 'file,encoding',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    46
                                'eid': [0],
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    47
                                'encoding': u'utf-8',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    48
                                'field:0': 'value',
eacb8ea38bf5 [devtools] add a method on CubicWebTC to fake data posted by standard cw forms. Closes #4985805
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9864
diff changeset
    49
                                'file': ('filename.txt', sio)})
6776
eebe86b89285 [tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6341
diff changeset
    50
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
class WebTestTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
    def setUp(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        output = StringIO()
6776
eebe86b89285 [tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6341
diff changeset
    55
        self.runner = TextTestRunner(stream=output)
5390
a40ffdce549d cleanup debugging trace
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5389
diff changeset
    56
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
    def test_error_raised(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    58
        class MyWebTest(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
            def test_error_view(self):
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
    61
                with self.admin_access.web_request() as req:
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
    62
                    req.create_entity('Bug', title=u"bt")
9864
f60a80592224 [webtests] finish to give all self.view(....) a req=req parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9857
diff changeset
    63
                    self.view('raising', req.execute('Bug B'), template=None, req=req)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
    64
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            def test_correct_view(self):
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
    66
                with self.admin_access.web_request() as req:
9864
f60a80592224 [webtests] finish to give all self.view(....) a req=req parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9857
diff changeset
    67
                    self.view('primary', req.execute('CWUser U'), template=None, req=req)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
    68
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        tests = [MyWebTest('test_error_view'), MyWebTest('test_correct_view')]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        result = self.runner.run(TestSuite(tests))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    71
        self.assertEqual(result.testsRun, 2)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    72
        self.assertEqual(len(result.errors), 0)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    73
        self.assertEqual(len(result.failures), 1)
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4473
diff changeset
    74
        clean_repo_test_cls(MyWebTest)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
HTML_PAGE = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
<html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
  <head><title>need a title</title></head>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
  <body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    <h1>Hello World !</h1>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
  </body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
</html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
HTML_PAGE2 = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
<html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
 <head><title>need a title</title></head>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
 <body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
   <h1>Test</h1>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
   <h1>Hello <a href="http://www.google.com">world</a> !</h1>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
   <h2>h2 title</h2>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
   <h3>h3 title</h3>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
   <h2>antoher h2 title</h2>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
   <h4>h4 title</h4>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
   <p><a href="http://www.logilab.org">Logilab</a> introduces CW !</p>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
 </body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
</html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
HTML_PAGE_ERROR = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
<html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
 <head><title>need a title</title></head>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
 <body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
   Logilab</a> introduces CW !
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
 </body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
</html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
HTML_NON_STRICT = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
<html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
  <head><title>need a title</title></head>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
  <body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
    <h1><a href="something.com">title</h1>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
  </body>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
</html>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
class HTMLPageInfoTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    """test cases for PageInfo"""
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   122
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
    def setUp(self):
8941
7b26fe71404f drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
   124
        parser = htmlparser.HTMLValidator()
7b26fe71404f drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
   125
        # disable cleanup that would remove doctype
7b26fe71404f drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
   126
        parser.preprocess_data = lambda data: data
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        self.page_info = parser.parse_string(HTML_PAGE2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
    def test_source1(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        """make sure source is stored correctly"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   131
        self.assertEqual(self.page_info.source, HTML_PAGE2)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   132
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    def test_source2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        """make sure source is stored correctly - raise exception"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        parser = htmlparser.DTDValidator()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        self.assertRaises(AssertionError, parser.parse_string, HTML_PAGE_ERROR)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    def test_has_title_no_level(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        """tests h? tags information"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   140
        self.assertEqual(self.page_info.has_title('Test'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   141
        self.assertEqual(self.page_info.has_title('Test '), False)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   142
        self.assertEqual(self.page_info.has_title('Tes'), False)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   143
        self.assertEqual(self.page_info.has_title('Hello world !'), True)
0
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_has_title_level(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
        """tests h? tags information"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   147
        self.assertEqual(self.page_info.has_title('Test', level = 1), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   148
        self.assertEqual(self.page_info.has_title('Test', level = 2), False)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   149
        self.assertEqual(self.page_info.has_title('Test', level = 3), False)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   150
        self.assertEqual(self.page_info.has_title('Test', level = 4), False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
        self.assertRaises(IndexError, self.page_info.has_title, 'Test', level = 5)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    def test_has_title_regexp_no_level(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        """tests has_title_regexp() with no particular level specified"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   155
        self.assertEqual(self.page_info.has_title_regexp('h[23] title'), True)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
    def test_has_title_regexp_level(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
        """tests has_title_regexp() with a particular level specified"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   159
        self.assertEqual(self.page_info.has_title_regexp('h[23] title', 2), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   160
        self.assertEqual(self.page_info.has_title_regexp('h[23] title', 3), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   161
        self.assertEqual(self.page_info.has_title_regexp('h[23] title', 4), False)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   162
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
    def test_appears(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        """tests PageInfo.appears()"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   165
        self.assertEqual(self.page_info.appears('CW'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   166
        self.assertEqual(self.page_info.appears('Logilab'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   167
        self.assertEqual(self.page_info.appears('Logilab introduces'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   168
        self.assertEqual(self.page_info.appears('H2 title'), False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
    def test_has_link(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        """tests has_link()"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   172
        self.assertEqual(self.page_info.has_link('Logilab'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   173
        self.assertEqual(self.page_info.has_link('logilab'), False)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   174
        self.assertEqual(self.page_info.has_link('Logilab', 'http://www.logilab.org'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   175
        self.assertEqual(self.page_info.has_link('Logilab', 'http://www.google.com'), False)
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
    def test_has_link_regexp(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
        """test has_link_regexp()"""
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   179
        self.assertEqual(self.page_info.has_link_regexp('L[oi]gilab'), True)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   180
        self.assertEqual(self.page_info.has_link_regexp('L[ai]gilab'), False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
8460
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   183
class CWUtilitiesTC(CubicWebTC):
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   184
8460
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   185
    def test_temporary_permissions_eschema(self):
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   186
        eschema = self.schema['CWUser']
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   187
        with self.temporary_permissions(CWUser={'read': ()}):
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   188
            self.assertEqual(eschema.permissions['read'], ())
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   189
            self.assertTrue(eschema.permissions['add'])
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   190
        self.assertTrue(eschema.permissions['read'], ())
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   191
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   192
    def test_temporary_permissions_rdef(self):
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   193
        rdef = self.schema['CWUser'].rdef('in_group')
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   194
        with self.temporary_permissions((rdef, {'read': ()})):
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   195
            self.assertEqual(rdef.permissions['read'], ())
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   196
            self.assertTrue(rdef.permissions['add'])
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   197
        self.assertTrue(rdef.permissions['read'], ())
b1f6777fc839 [testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6776
diff changeset
   198
9212
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   199
    def test_temporary_appobjects_registered(self):
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   200
9212
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   201
        class AnAppobject(object):
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   202
            __registries__ = ('hip',)
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   203
            __regid__ = 'hop'
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   204
            __select__ = yes()
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   205
            registered = None
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   206
9212
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   207
            @classmethod
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   208
            def __registered__(cls, reg):
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   209
                cls.registered = reg
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   210
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   211
        with self.temporary_appobjects(AnAppobject):
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   212
            self.assertEqual(self.vreg['hip'], AnAppobject.registered)
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   213
            self.assertIn(AnAppobject, self.vreg['hip']['hop'])
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   214
        self.assertNotIn(AnAppobject, self.vreg['hip']['hop'])
0d346a0a1451 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   215
9472
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   216
    def test_login(self):
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   217
        """Calling login should not break hook control"""
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   218
        with self.admin_access.repo_cnx() as cnx:
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   219
            self.hook_executed = False
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   220
            self.create_user(cnx, 'babar')
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   221
            cnx.commit()
9472
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   222
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   223
        from cubicweb.server import hook
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   224
        from cubicweb.predicates import is_instance
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   225
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   226
        class MyHook(hook.Hook):
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   227
            __regid__ = 'whatever'
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   228
            __select__ = hook.Hook.__select__ & is_instance('CWProperty')
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   229
            category = 'test-hook'
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   230
            events = ('after_add_entity',)
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   231
            test = self
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   232
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   233
            def __call__(self):
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   234
                self.test.hook_executed = True
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   235
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   236
        with self.new_access('babar').repo_cnx() as cnx:
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   237
            with self.temporary_appobjects(MyHook):
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   238
                with cnx.allow_all_hooks_but('test-hook'):
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   239
                    prop = cnx.create_entity('CWProperty', pkey=u'ui.language', value=u'en')
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   240
                    cnx.commit()
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   241
                    self.assertFalse(self.hook_executed)
9472
ae97167956b1 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
Julien Cristau <julien.cristau@logilab.fr>
parents: 9402
diff changeset
   242
9402
2c48c091b6a2 merge 3.18.0 in 3.19 branch
Julien Cristau <julien.cristau@logilab.fr>
parents: 9118 9212
diff changeset
   243
9117
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   244
class RepoAccessTC(CubicWebTC):
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   245
9117
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   246
    def test_repo_connection(self):
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   247
        acc = self.new_access('admin')
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   248
        with acc.repo_cnx() as cnx:
9117
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   249
            rset = cnx.execute('Any X WHERE X is CWUser')
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   250
            self.assertTrue(rset)
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   251
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   252
    def test_client_connection(self):
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   253
        acc = self.new_access('admin')
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   254
        with acc.client_cnx() as cnx:
9117
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   255
            rset = cnx.execute('Any X WHERE X is CWUser')
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   256
            self.assertTrue(rset)
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   257
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   258
    def test_web_request(self):
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   259
        acc = self.new_access('admin')
9857
618d45655865 [testlib] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9472
diff changeset
   260
        with acc.web_request(elephant='babar') as req:
9117
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   261
            rset = req.execute('Any X WHERE X is CWUser')
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   262
            self.assertTrue(rset)
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   263
            self.assertEqual('babar', req.form['elephant'])
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   264
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   265
    def test_close(self):
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   266
        acc = self.new_access('admin')
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   267
        acc.close()
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   268
9118
bb9e19df9a05 [testlib] add an default testcase.adminaccess (and use it for default session)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 9117
diff changeset
   269
    def test_admin_access(self):
bb9e19df9a05 [testlib] add an default testcase.adminaccess (and use it for default session)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 9117
diff changeset
   270
        with self.admin_access.client_cnx() as cnx:
bb9e19df9a05 [testlib] add an default testcase.adminaccess (and use it for default session)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 9117
diff changeset
   271
            self.assertEqual('admin', cnx.user.login)
bb9e19df9a05 [testlib] add an default testcase.adminaccess (and use it for default session)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 9117
diff changeset
   272
9117
e25c5abc667c [testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8941
diff changeset
   273
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
    unittest_main()