author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Thu, 27 Jun 2013 19:14:22 +0200 | |
changeset 9124 | d1d4b3669e41 |
parent 9118 | bb9e19df9a05 |
child 9402 | 2c48c091b6a2 |
permissions | -rw-r--r-- |
8652
7812093e21f7
[testlib] test_view now parse json data, closes #2557467
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8628
diff
changeset
|
1 |
# copyright 2003-2013 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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
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:
5401
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5786
diff
changeset
|
18 |
"""this module contains base classes and utilities for cubicweb tests""" |
0 | 19 |
__docformat__ = "restructuredtext en" |
20 |
||
21 |
import sys |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
22 |
import re |
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6469
diff
changeset
|
23 |
import urlparse |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6590
diff
changeset
|
24 |
from os.path import dirname, join, abspath |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
25 |
from urllib import unquote |
0 | 26 |
from math import log |
5102
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
27 |
from contextlib import contextmanager |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
28 |
from warnings import warn |
7313
02fb1dcc99a2
[testlib] fix assertAuthFailure to consider both None and dbapi._NeedAuthAccessMock as meaning 'no connection has been set'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7307
diff
changeset
|
29 |
from types import NoneType |
8460
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
30 |
from itertools import chain |
0 | 31 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
32 |
import yams.schema |
0 | 33 |
|
5913
85240b3f9ee4
[test] add default generic test Tags to CubicWeb TestCase class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5875
diff
changeset
|
34 |
from logilab.common.testlib import TestCase, InnerTest, Tags |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
35 |
from logilab.common.pytest import nocoverage, pause_tracing, resume_tracing |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
36 |
from logilab.common.debugger import Debugger |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
37 |
from logilab.common.umessage import message_from_string |
7222
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
38 |
from logilab.common.decorators import cached, classproperty, clear_cache, iclassmethod |
6454
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6442
diff
changeset
|
39 |
from logilab.common.deprecation import deprecated, class_deprecated |
6720
43a38c093f6f
[testlib] Use logilab.common.shellutils.getlogin instead of local hack.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6589
diff
changeset
|
40 |
from logilab.common.shellutils import getlogin |
0 | 41 |
|
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8978
diff
changeset
|
42 |
from cubicweb import ValidationError, NoSelectableObject, AuthenticationError |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
43 |
from cubicweb import cwconfig, dbapi, devtools, web, server, repoapi |
8652
7812093e21f7
[testlib] test_view now parse json data, closes #2557467
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8628
diff
changeset
|
44 |
from cubicweb.utils import json |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
45 |
from cubicweb.sobjects import notification |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
46 |
from cubicweb.web import Redirect, application |
6398
ea26eb5fd388
[test] send mail synchronously during tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6369
diff
changeset
|
47 |
from cubicweb.server.hook import SendMailOp |
9117
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
48 |
from cubicweb.server.session import Session |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
49 |
from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
8930
6a02be304486
remove unused import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8725
diff
changeset
|
50 |
from cubicweb.devtools import fake, htmlparser, DEFAULT_EMPTY_DB_ID |
5389
809d3b5b3d31
[python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5377
diff
changeset
|
51 |
from cubicweb.utils import json |
0 | 52 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
53 |
# low-level utilities ########################################################## |
0 | 54 |
|
55 |
class CubicWebDebugger(Debugger): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
56 |
"""special debugger class providing a 'view' function which saves some |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
57 |
html into a temporary file and open a web browser to examinate it. |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
58 |
""" |
0 | 59 |
def do_view(self, arg): |
60 |
import webbrowser |
|
61 |
data = self._getval(arg) |
|
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
62 |
with file('/tmp/toto.html', 'w') as toto: |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
63 |
toto.write(data) |
0 | 64 |
webbrowser.open('file:///tmp/toto.html') |
65 |
||
66 |
def line_context_filter(line_no, center, before=3, after=None): |
|
67 |
"""return true if line are in context |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
68 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
69 |
if after is None: after = before |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
70 |
""" |
0 | 71 |
if after is None: |
72 |
after = before |
|
73 |
return center - before <= line_no <= center + after |
|
74 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
75 |
def unprotected_entities(schema, strict=False): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
76 |
"""returned a set of each non final entity type, excluding "system" entities |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
77 |
(eg CWGroup, CWUser...) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
78 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
79 |
if strict: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
80 |
protected_entities = yams.schema.BASE_TYPES |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
81 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
82 |
protected_entities = yams.schema.BASE_TYPES.union(SYSTEM_ENTITIES) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
83 |
return set(schema.entities()) - protected_entities |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
84 |
|
8652
7812093e21f7
[testlib] test_view now parse json data, closes #2557467
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8628
diff
changeset
|
85 |
class JsonValidator(object): |
7812093e21f7
[testlib] test_view now parse json data, closes #2557467
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8628
diff
changeset
|
86 |
def parse_string(self, data): |
8704
933f9693c53d
[testlib] make test_view load the json data
Julien Cristau <julien.cristau@logilab.fr>
parents:
8696
diff
changeset
|
87 |
return json.loads(data) |
8652
7812093e21f7
[testlib] test_view now parse json data, closes #2557467
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8628
diff
changeset
|
88 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
89 |
# email handling, to test emails sent by an application ######################## |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
90 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
91 |
MAILBOX = [] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
92 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
93 |
class Email: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
94 |
"""you'll get instances of Email into MAILBOX during tests that trigger |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
95 |
some notification. |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
96 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
97 |
* `msg` is the original message object |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
98 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
99 |
* `recipients` is a list of email address which are the recipients of this |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
100 |
message |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
101 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
102 |
def __init__(self, recipients, msg): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
103 |
self.recipients = recipients |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
104 |
self.msg = msg |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
105 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
106 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
107 |
def message(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
108 |
return message_from_string(self.msg) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
109 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
110 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
111 |
def subject(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
112 |
return self.message.get('Subject') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
113 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
114 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
115 |
def content(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
116 |
return self.message.get_payload(decode=True) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
117 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
118 |
def __repr__(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
119 |
return '<Email to %s with subject %s>' % (','.join(self.recipients), |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
120 |
self.message.get('Subject')) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
121 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
122 |
# the trick to get email into MAILBOX instead of actually sent: monkey patch |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
123 |
# cwconfig.SMTP object |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
124 |
class MockSMTP: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
125 |
def __init__(self, server, port): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
126 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
127 |
def close(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
128 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
129 |
def sendmail(self, helo_addr, recipients, msg): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
130 |
MAILBOX.append(Email(recipients, msg)) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
131 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
132 |
cwconfig.SMTP = MockSMTP |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
133 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
134 |
|
6165
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
135 |
class TestCaseConnectionProxy(object): |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
136 |
"""thin wrapper around `cubicweb.dbapi.Connection` context-manager |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
137 |
used in CubicWebTC (cf. `cubicweb.devtools.testlib.CubicWebTC.login` method) |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
138 |
|
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
139 |
It just proxies to the default connection context manager but |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
140 |
restores the original connection on exit. |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
141 |
""" |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
142 |
def __init__(self, testcase, cnx): |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
143 |
self.testcase = testcase |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
144 |
self.cnx = cnx |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
145 |
|
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
146 |
def __getattr__(self, attrname): |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
147 |
return getattr(self.cnx, attrname) |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
148 |
|
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
149 |
def __enter__(self): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
150 |
# already open |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
151 |
return self.cnx |
6165
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
152 |
|
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
153 |
def __exit__(self, exctype, exc, tb): |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
154 |
try: |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
155 |
return self.cnx.__exit__(exctype, exc, tb) |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
156 |
finally: |
7da7c270bbbd
[devtools] make CubiwebTC.login() context-manager restore the testcase connection on exit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6109
diff
changeset
|
157 |
self.testcase.restore_connection() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
158 |
|
9117
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
159 |
# Repoaccess utility ###############################################3########### |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
160 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
161 |
class RepoAccess(object): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
162 |
"""An helper to easily create object to access the repo as a specific user |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
163 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
164 |
Each RepoAccess have it own session. |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
165 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
166 |
A repo access can create three type of object: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
167 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
168 |
.. automethod:: cubicweb.testlib.RepoAccess.repo_cnx |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
169 |
.. automethod:: cubicweb.testlib.RepoAccess.client_cnx |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
170 |
.. automethod:: cubicweb.testlib.RepoAccess.web_request |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
171 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
172 |
The RepoAccess need to be closed to destroy the associated Session. |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
173 |
TestCase usually take care of this aspect for the user. |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
174 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
175 |
.. automethod:: cubicweb.testlib.RepoAccess.close |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
176 |
""" |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
177 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
178 |
def __init__(self, repo, login, requestcls): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
179 |
self._repo = repo |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
180 |
self._login = login |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
181 |
self.requestcls = requestcls |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
182 |
# opening session |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
183 |
# |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
184 |
# XXX this very hackish code should be cleaned and move on repo. |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
185 |
with repo.internal_cnx() as cnx: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
186 |
rset = cnx.execute('CWUser U WHERE U login %(u)s', {'u': login}) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
187 |
user = rset.get_entity(0, 0) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
188 |
user.groups |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
189 |
user.properties |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
190 |
self._session = Session(user, repo) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
191 |
repo._sessions[self._session.id] = self._session |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
192 |
self._session.user._cw = self._session |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
193 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
194 |
@ contextmanager |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
195 |
def repo_cnx(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
196 |
"""Context manager returning a server side connection for the user""" |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
197 |
with self._session.new_cnx() as cnx: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
198 |
yield cnx |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
199 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
200 |
@ contextmanager |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
201 |
def client_cnx(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
202 |
"""Context manager returning a client side connection for the user""" |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
203 |
with repoapi.ClientConnection(self._session) as cnx: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
204 |
yield cnx |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
205 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
206 |
@ contextmanager |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
207 |
def web_request(self, url=None, headers={}, **kwargs): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
208 |
"""Context manager returning a web request pre-linked to a client cnx |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
209 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
210 |
To commit and rollback use:: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
211 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
212 |
req.cnx.commit() |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
213 |
req.cnx.rolback() |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
214 |
""" |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
215 |
req = self.requestcls(self._repo.vreg, url=url, headers=headers, form=kwargs) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
216 |
clt_cnx = repoapi.ClientConnection(self._session) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
217 |
req.set_cnx(clt_cnx) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
218 |
with clt_cnx: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
219 |
yield req |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
220 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
221 |
def close(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
222 |
"""Close the session associated to the RepoAccess""" |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
223 |
if self._session is not None: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
224 |
self._repo.close(self._session.id) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
225 |
self._session = None |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
226 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
227 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
228 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
229 |
# base class for cubicweb tests requiring a full cw environments ############### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
230 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
231 |
class CubicWebTC(TestCase): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
232 |
"""abstract class for test using an apptest environment |
5267
7bac6791bbc2
[devtools] do not forbid use of postgres as a source for tests (but it still needs proper dump/restore support)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5229
diff
changeset
|
233 |
|
5229
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
234 |
attributes: |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
235 |
|
5229
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
236 |
* `vreg`, the vregistry |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
237 |
* `schema`, self.vreg.schema |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
238 |
* `config`, cubicweb configuration |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
239 |
* `cnx`, dbapi connection to the repository using an admin user |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
240 |
* `session`, server side session associated to `cnx` |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
241 |
* `app`, the cubicweb publisher (for web testing) |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
242 |
* `repo`, the repository object |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
243 |
* `admlogin`, login of the admin user |
67dbd07a05f3
[doc/book] expand tesing material
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5175
diff
changeset
|
244 |
* `admpassword`, password of the admin user |
6694
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
245 |
* `shell`, create and use shell environment |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
246 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
247 |
appid = 'data' |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
248 |
configcls = devtools.ApptestConfiguration |
6441
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6439
diff
changeset
|
249 |
tags = TestCase.tags | Tags('cubicweb', 'cw_repo') |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
250 |
test_db_id = DEFAULT_EMPTY_DB_ID |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
251 |
_cnxs = set() # establised connection |
9043
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
252 |
# stay on connection for leak detection purpose |
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
253 |
|
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
254 |
def __init__(self, *args, **kwargs): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
255 |
self._admin_session = None |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
256 |
self._admin_clt_cnx = None |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
257 |
self._current_session = None |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
258 |
self._current_clt_cnx = None |
9043
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
259 |
self.repo = None |
9117
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
260 |
self._open_access = set() |
9043
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
261 |
super(CubicWebTC, self).__init__(*args, **kwargs) |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
262 |
|
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
263 |
# repository connection handling ########################################### |
9117
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
264 |
def new_access(self, login): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
265 |
"""provide a new RepoAccess object for a given user |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
266 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
267 |
The access is automatically closed at the end of the test.""" |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
268 |
access = RepoAccess(self.repo, login, self.requestcls) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
269 |
self._open_access.add(access) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
270 |
return access |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
271 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
272 |
def _close_access(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
273 |
while self._open_access: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9114
diff
changeset
|
274 |
self._open_access.pop().close() |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
275 |
|
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
276 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9043
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
277 |
def set_cnx(self, cnx): |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
278 |
"""""" |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
279 |
# XXX we want to deprecate this |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
280 |
assert getattr(cnx, '_session', None) is not None |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
281 |
if cnx is self._admin_clt_cnx: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
282 |
self._pop_custom_cnx() |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
283 |
else: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
284 |
self._cnxs.add(cnx) # register the cns to make sure it is removed |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
285 |
self._current_session = cnx._session |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
286 |
self._current_clt_cnx = cnx |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
287 |
|
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
288 |
@property |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
289 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
290 |
def cnx(self): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
291 |
# XXX we want to deprecate this |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
292 |
clt_cnx = self._current_clt_cnx |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
293 |
if clt_cnx is None: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
294 |
clt_cnx = self._admin_clt_cnx |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
295 |
return clt_cnx |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
296 |
|
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
297 |
def _close_cnx(self): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
298 |
"""ensure that all cnx used by a test have been closed""" |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
299 |
for cnx in list(self._cnxs): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
300 |
if cnx._open and not cnx._session.closed: |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
301 |
cnx.rollback() |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
302 |
cnx.close() |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
303 |
self._cnxs.remove(cnx) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
304 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
305 |
@property |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
306 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
307 |
def session(self): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
308 |
"""return current server side session""" |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
309 |
# XXX We want to use a srv_connection instead and deprecate this |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
310 |
# property |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
311 |
session = self._current_session |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
312 |
if session is None: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
313 |
session = self._admin_session |
9111
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9071
diff
changeset
|
314 |
# bypassing all sanity to use the same repo cnx in the session we |
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9071
diff
changeset
|
315 |
# can't call set_cnx as the Connection is not managed by the |
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9071
diff
changeset
|
316 |
# session. |
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9071
diff
changeset
|
317 |
session._Session__threaddata.cnx = self._admin_clt_cnx._cnx |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
318 |
session.set_cnxset() |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
319 |
return session |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
320 |
|
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
321 |
@property |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
322 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
323 |
def websession(self): |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
324 |
return self.session |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
325 |
|
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
326 |
@property |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
327 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
328 |
def adminsession(self): |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
329 |
"""return current server side session (using default manager account)""" |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
330 |
return self._admin_session |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
331 |
|
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
332 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
333 |
def login(self, login, **kwargs): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
334 |
"""return a connection for the given login/password""" |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
335 |
__ = kwargs.pop('autoclose', True) # not used anymore |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
336 |
if login == self.admlogin: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
337 |
# definitly don't want autoclose when used as a context manager |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
338 |
clt_cnx = repoapi.ClientConnection(self._admin_session) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
339 |
else: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
340 |
if not kwargs: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
341 |
kwargs['password'] = str(login) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
342 |
clt_cnx = repoapi.connect(self.repo, login, **kwargs) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
343 |
self.set_cnx(clt_cnx) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
344 |
clt_cnx.__enter__() |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
345 |
return TestCaseConnectionProxy(self, clt_cnx) |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
346 |
|
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
347 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
348 |
def restore_connection(self): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
349 |
self._pop_custom_cnx() |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
350 |
|
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
351 |
def _pop_custom_cnx(self): |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
352 |
if self._current_clt_cnx is not None: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
353 |
if self._current_clt_cnx._open: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
354 |
self._current_clt_cnx.close() |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
355 |
if not self._current_session.closed: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
356 |
self.repo.close(self._current_session.id) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
357 |
self._current_clt_cnx = None |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
358 |
self._current_session = None |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
359 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
360 |
#XXX this doesn't need to a be classmethod anymore |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
361 |
def _init_repo(self): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
362 |
"""init the repository and connection to it. |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
363 |
""" |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
364 |
# setup configuration for test |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
365 |
self.init_config(self.config) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
366 |
# get or restore and working db. |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
367 |
db_handler = devtools.get_test_db_handler(self.config) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
368 |
db_handler.build_db_cache(self.test_db_id, self.pre_setup_database) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
369 |
|
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
370 |
db_handler.restore_database(self.test_db_id) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
371 |
self.repo = db_handler.get_repo(startup=True) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
372 |
# get an admin session (without actual login) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
373 |
sources = db_handler.config.sources() |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
374 |
login = unicode(sources['admin']['login']) |
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
|
375 |
self.admin_access = self.new_access(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
|
376 |
self._admin_session = self.admin_access._session |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
377 |
self._admin_clt_cnx = repoapi.ClientConnection(self._admin_session) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
378 |
self._cnxs.add(self._admin_clt_cnx) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
379 |
self._admin_clt_cnx.__enter__() |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
380 |
self.config.repository = lambda x=None: self.repo |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
381 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
382 |
# db api ################################################################## |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
383 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
384 |
@nocoverage |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
385 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
386 |
def cursor(self, req=None): |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
387 |
if req is not None: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
388 |
return req.cnx |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
389 |
else: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
390 |
return self.cnx |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
391 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
392 |
@nocoverage |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
393 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
394 |
def execute(self, rql, args=None, eidkey=None, req=None): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
395 |
"""executes <rql>, builds a resultset, and returns a couple (rset, req) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
396 |
where req is a FakeRequest |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
397 |
""" |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
398 |
if eidkey is not None: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
399 |
warn('[3.8] eidkey is deprecated, you can safely remove this argument', |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
400 |
DeprecationWarning, stacklevel=2) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
401 |
req = req or self.request(rql=rql) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
402 |
return req.execute(unicode(rql), args) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
403 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
404 |
@nocoverage |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
405 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
406 |
def commit(self): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
407 |
try: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
408 |
return self.cnx.commit() |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
409 |
finally: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
410 |
self.session.set_cnxset() # ensure cnxset still set after commit |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
411 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
412 |
@nocoverage |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
413 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
414 |
def rollback(self): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
415 |
try: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
416 |
self.cnx.rollback() |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
417 |
except dbapi.ProgrammingError: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
418 |
pass # connection closed |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
419 |
finally: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
420 |
self.session.set_cnxset() # ensure cnxset still set after commit |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
421 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
422 |
requestcls = fake.FakeRequest |
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
423 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
424 |
def request(self, rollbackfirst=False, url=None, headers={}, **kwargs): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
425 |
"""return a web ui request""" |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
426 |
if rollbackfirst: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
427 |
self.cnx.rollback() |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
428 |
req = self.requestcls(self.vreg, url=url, headers=headers, form=kwargs) |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
429 |
req.set_cnx(self.cnx) |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
430 |
return req |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
431 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
432 |
# server side db api ####################################################### |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
433 |
|
9124
d1d4b3669e41
[testlib] deprecated the older api to access the repo.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9118
diff
changeset
|
434 |
@deprecated('[4.0] explicitly use RepoAccess object in test instead') |
9044
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
435 |
def sexecute(self, rql, args=None, eid_key=None): |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
436 |
if eid_key is not None: |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
437 |
warn('[3.8] eid_key is deprecated, you can safely remove this argument', |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
438 |
DeprecationWarning, stacklevel=2) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
439 |
self.session.set_cnxset() |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
440 |
return self.session.execute(rql, args) |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
441 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
442 |
|
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
443 |
# config management ######################################################## |
cfec5cc46008
[testlib] gather all repository access logic in one place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9043
diff
changeset
|
444 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
445 |
@classproperty |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
446 |
def config(cls): |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
447 |
"""return the configuration object |
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
448 |
|
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
449 |
Configuration is cached on the test class. |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
450 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
451 |
try: |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
452 |
assert not cls is CubicWebTC, "Don't use CubicWebTC directly to prevent database caching issue" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
453 |
return cls.__dict__['_config'] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
454 |
except KeyError: |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6590
diff
changeset
|
455 |
home = abspath(join(dirname(sys.modules[cls.__module__].__file__), cls.appid)) |
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6469
diff
changeset
|
456 |
config = cls._config = cls.configcls(cls.appid, apphome=home) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
457 |
config.mode = 'test' |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
458 |
return config |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
459 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
460 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
461 |
def init_config(cls, config): |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
462 |
"""configuration initialization hooks. |
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
463 |
|
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
464 |
You may only want to override here the configuraton logic. |
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
465 |
|
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
466 |
Otherwise, consider to use a different :class:`ApptestConfiguration` |
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6410
diff
changeset
|
467 |
defined in the `configcls` class attribute""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
468 |
source = config.sources()['system'] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
469 |
cls.admlogin = unicode(source['db-user']) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
470 |
cls.admpassword = source['db-password'] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
471 |
# uncomment the line below if you want rql queries to be logged |
3163
edfe43ceaa35
backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
472 |
#config.global_set_option('query-log-file', |
edfe43ceaa35
backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
473 |
# '/tmp/test_rql_log.' + `os.getpid()`) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
474 |
config.global_set_option('log-file', None) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
475 |
# set default-dest-addrs to a dumb email address to avoid mailbox or |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
476 |
# mail queue pollution |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
477 |
config.global_set_option('default-dest-addrs', ['whatever']) |
6720
43a38c093f6f
[testlib] Use logilab.common.shellutils.getlogin instead of local hack.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6589
diff
changeset
|
478 |
send_to = '%s@logilab.fr' % getlogin() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
479 |
config.global_set_option('sender-addr', send_to) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
480 |
config.global_set_option('default-dest-addrs', send_to) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
481 |
config.global_set_option('sender-name', 'cubicweb-test') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
482 |
config.global_set_option('sender-addr', 'cubicweb-test@logilab.fr') |
6432
30bde2b7fea2
restore line dropped in 6424:f443a2b8a5c7 which is necessary to have proper base-url on test server config (used for ms tests at least)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
483 |
# default_base_url on config class isn't enough for TestServerConfiguration |
6439
fe0fb6f95ff0
[test] we must consider default_base_url()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6432
diff
changeset
|
484 |
config.global_set_option('base-url', config.default_base_url()) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
485 |
# web resources |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
486 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
487 |
config.global_set_option('embed-allowed', re.compile('.*')) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
488 |
except Exception: # not in server only configuration |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
489 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
490 |
|
9043
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
491 |
@property |
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
492 |
def vreg(self): |
97c3bb9a7c99
[testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9042
diff
changeset
|
493 |
return self.repo.vreg |
9029
5941cde49878
[devtools] vreg becomes a class ppty
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9028
diff
changeset
|
494 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
495 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
496 |
# global resources accessors ############################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
497 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
498 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
499 |
def schema(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
500 |
"""return the application schema""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
501 |
return self.vreg.schema |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
502 |
|
6694
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
503 |
def shell(self): |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
504 |
"""return a shell session object""" |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
505 |
from cubicweb.server.migractions import ServerMigrationHelper |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
506 |
return ServerMigrationHelper(None, repo=self.repo, cnx=self.cnx, |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
507 |
interactive=False, |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
508 |
# hack so it don't try to load fs schema |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
509 |
schema=1) |
d9eac4fd57dc
[devtools] make migration handler easily available from CubicWebTC through .shell() method
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6687
diff
changeset
|
510 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
511 |
def set_option(self, optname, value): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
512 |
self.config.global_set_option(optname, value) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
513 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
514 |
def set_debug(self, debugmode): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
515 |
server.set_debug(debugmode) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
516 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6425
diff
changeset
|
517 |
def debugged(self, debugmode): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6425
diff
changeset
|
518 |
return server.debugged(debugmode) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6425
diff
changeset
|
519 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
520 |
# default test setup and teardown ######################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
521 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
522 |
def setUp(self): |
6398
ea26eb5fd388
[test] send mail synchronously during tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6369
diff
changeset
|
523 |
# monkey patch send mail operation so emails are sent synchronously |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
524 |
self._patch_SendMailOp() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
525 |
pause_tracing() |
5020
30a539c2074d
When a TC failed to initiliase the database, the following test are SKIPPED
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4958
diff
changeset
|
526 |
previous_failure = self.__class__.__dict__.get('_repo_init_failed') |
30a539c2074d
When a TC failed to initiliase the database, the following test are SKIPPED
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4958
diff
changeset
|
527 |
if previous_failure is not None: |
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6346
diff
changeset
|
528 |
self.skipTest('repository is not initialised: %r' % previous_failure) |
5020
30a539c2074d
When a TC failed to initiliase the database, the following test are SKIPPED
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4958
diff
changeset
|
529 |
try: |
30a539c2074d
When a TC failed to initiliase the database, the following test are SKIPPED
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4958
diff
changeset
|
530 |
self._init_repo() |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
531 |
self.addCleanup(self._close_cnx) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
532 |
except Exception as ex: |
5020
30a539c2074d
When a TC failed to initiliase the database, the following test are SKIPPED
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4958
diff
changeset
|
533 |
self.__class__._repo_init_failed = ex |
30a539c2074d
When a TC failed to initiliase the database, the following test are SKIPPED
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4958
diff
changeset
|
534 |
raise |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
535 |
resume_tracing() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
536 |
self.setup_database() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
537 |
self.commit() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
538 |
MAILBOX[:] = [] # reset mailbox |
5175
6efb7a7ae570
[testlib] properly close connections opened during test in tearDown
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5128
diff
changeset
|
539 |
|
6efb7a7ae570
[testlib] properly close connections opened during test in tearDown
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5128
diff
changeset
|
540 |
def tearDown(self): |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
541 |
# XXX hack until logilab.common.testlib is fixed |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
542 |
if self._admin_clt_cnx is not None: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
543 |
if self._admin_clt_cnx._open: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
544 |
self._admin_clt_cnx.close() |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
545 |
self._admin_clt_cnx = None |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
546 |
if self._admin_session is not None: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
547 |
if not self._admin_session.closed: |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
548 |
self.repo.close(self._admin_session.id) |
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
549 |
self._admin_session = None |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
550 |
while self._cleanups: |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
551 |
cleanup, args, kwargs = self._cleanups.pop(-1) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
552 |
cleanup(*args, **kwargs) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
553 |
|
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
554 |
def _patch_SendMailOp(self): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
555 |
# monkey patch send mail operation so emails are sent synchronously |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
556 |
_old_mail_postcommit_event = SendMailOp.postcommit_event |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
557 |
SendMailOp.postcommit_event = SendMailOp.sendmails |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
558 |
def reverse_SendMailOp_monkey_patch(): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
559 |
SendMailOp.postcommit_event = _old_mail_postcommit_event |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
560 |
self.addCleanup(reverse_SendMailOp_monkey_patch) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
561 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
562 |
def setup_database(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
563 |
"""add your database setup code by overriding this method""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
564 |
|
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
565 |
@classmethod |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
566 |
def pre_setup_database(cls, session, config): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
567 |
"""add your pre database setup code by overriding this method |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
568 |
|
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
569 |
Do not forget to set the cls.test_db_id value to enable caching of the |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
570 |
result. |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
571 |
""" |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
572 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
573 |
# user / session management ############################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
574 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
575 |
def user(self, req=None): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
576 |
"""return the application schema""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
577 |
if req is None: |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9044
diff
changeset
|
578 |
return self.request().user |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
579 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
580 |
return req.user |
563
a690996639ca
[testlib] fix pb. related to class scoped variables
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
562
diff
changeset
|
581 |
|
7222
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
582 |
@iclassmethod # XXX turn into a class method |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
583 |
def create_user(self, req, login=None, groups=('users',), password=None, |
7337
67cd9d5b4c2e
[testlib] create_user may now create user's email address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7331
diff
changeset
|
584 |
email=None, commit=True, **kwargs): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
585 |
"""create and return a new user entity""" |
7222
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
586 |
if isinstance(req, basestring): |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
587 |
warn('[3.12] create_user arguments are now (req, login[, groups, password, commit, **kwargs])', |
7324
5f7813ae9fb8
[testlib] fix deprecation warning stack level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7313
diff
changeset
|
588 |
DeprecationWarning, stacklevel=2) |
7222
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
589 |
if not isinstance(groups, (tuple, list)): |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
590 |
password = groups |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
591 |
groups = login |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
592 |
elif isinstance(login, tuple): |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
593 |
groups = login |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
594 |
login = req |
7307
a650e6267e97
[CubicWebTC] fix create_user bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7222
diff
changeset
|
595 |
assert not isinstance(self, type) |
a650e6267e97
[CubicWebTC] fix create_user bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7222
diff
changeset
|
596 |
req = self._orig_cnx[0].request() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
597 |
if password is None: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
598 |
password = login.encode('utf8') |
5055
14906474c55d
[testlib] create_user support extra kwargs to give to create_entity(CWUser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5036
diff
changeset
|
599 |
user = req.create_entity('CWUser', login=unicode(login), |
14906474c55d
[testlib] create_user support extra kwargs to give to create_entity(CWUser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5036
diff
changeset
|
600 |
upassword=password, **kwargs) |
14906474c55d
[testlib] create_user support extra kwargs to give to create_entity(CWUser)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5036
diff
changeset
|
601 |
req.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)' |
7038
fe0afc4e8ebb
[testlib] fix rql generation bug w/ groups given as unicode string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6979
diff
changeset
|
602 |
% ','.join(repr(str(g)) for g in groups), |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
603 |
{'x': user.eid}) |
7337
67cd9d5b4c2e
[testlib] create_user may now create user's email address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7331
diff
changeset
|
604 |
if email is not None: |
67cd9d5b4c2e
[testlib] create_user may now create user's email address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7331
diff
changeset
|
605 |
req.create_entity('EmailAddress', address=unicode(email), |
67cd9d5b4c2e
[testlib] create_user may now create user's email address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7331
diff
changeset
|
606 |
reverse_primary_email=user) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
607 |
user.cw_clear_relation_cache('in_group', 'subject') |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
608 |
if commit: |
7222
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
609 |
try: |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
610 |
req.commit() # req is a session |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
611 |
except AttributeError: |
fcb8932082a5
[testlib] refactor create_user and grant_permission to make them usable from pre_setup_database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7163
diff
changeset
|
612 |
req.cnx.commit() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
613 |
return user |
563
a690996639ca
[testlib] fix pb. related to class scoped variables
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
562
diff
changeset
|
614 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
615 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
616 |
# other utilities ######################################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
617 |
|
5102
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
618 |
@contextmanager |
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
619 |
def temporary_appobjects(self, *appobjects): |
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
620 |
self.vreg._loadedmods.setdefault(self.__module__, {}) |
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
621 |
for obj in appobjects: |
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
622 |
self.vreg.register(obj) |
5128
e5d300d75519
[python] take care to this detail of @contextmanager: if an unhandled exception occurs in the block, it is reraised inside the generator at the point where the yield occurred
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5102
diff
changeset
|
623 |
try: |
e5d300d75519
[python] take care to this detail of @contextmanager: if an unhandled exception occurs in the block, it is reraised inside the generator at the point where the yield occurred
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5102
diff
changeset
|
624 |
yield |
e5d300d75519
[python] take care to this detail of @contextmanager: if an unhandled exception occurs in the block, it is reraised inside the generator at the point where the yield occurred
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5102
diff
changeset
|
625 |
finally: |
e5d300d75519
[python] take care to this detail of @contextmanager: if an unhandled exception occurs in the block, it is reraised inside the generator at the point where the yield occurred
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5102
diff
changeset
|
626 |
for obj in appobjects: |
e5d300d75519
[python] take care to this detail of @contextmanager: if an unhandled exception occurs in the block, it is reraised inside the generator at the point where the yield occurred
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5102
diff
changeset
|
627 |
self.vreg.unregister(obj) |
5102
04c84959cd85
[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5055
diff
changeset
|
628 |
|
8460
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
629 |
@contextmanager |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
630 |
def temporary_permissions(self, *perm_overrides, **perm_kwoverrides): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
631 |
"""Set custom schema permissions within context. |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
632 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
633 |
There are two ways to call this method, which may be used together : |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
634 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
635 |
* using positional argument(s): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
636 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
637 |
.. sourcecode:: python |
8480
086cff6a306a
[book] fix build warnings/errors. Closes #2430042
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8463
diff
changeset
|
638 |
|
8460
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
639 |
rdef = self.schema['CWUser'].rdef('login') |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
640 |
with self.temporary_permissions((rdef, {'read': ()})): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
641 |
... |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
642 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
643 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
644 |
* using named argument(s): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
645 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
646 |
.. sourcecode:: python |
8480
086cff6a306a
[book] fix build warnings/errors. Closes #2430042
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8463
diff
changeset
|
647 |
|
8460
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
648 |
rdef = self.schema['CWUser'].rdef('login') |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
649 |
with self.temporary_permissions(CWUser={'read': ()}): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
650 |
... |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
651 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
652 |
Usually the former will be prefered to override permissions on a |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
653 |
relation definition, while the latter is well suited for entity types. |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
654 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
655 |
The allowed keys in the permission dictionary depends on the schema type |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
656 |
(entity type / relation definition). Resulting permissions will be |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
657 |
similar to `orig_permissions.update(partial_perms)`. |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
658 |
""" |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
659 |
torestore = [] |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
660 |
for erschema, etypeperms in chain(perm_overrides, perm_kwoverrides.iteritems()): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
661 |
if isinstance(erschema, basestring): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
662 |
erschema = self.schema[erschema] |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
663 |
for action, actionperms in etypeperms.iteritems(): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
664 |
origperms = erschema.permissions[action] |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
665 |
erschema.set_action_permissions(action, actionperms) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
666 |
torestore.append([erschema, action, origperms]) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
667 |
yield |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
668 |
for erschema, action, permissions in torestore: |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
669 |
if action is None: |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
670 |
erschema.permissions = permissions |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
671 |
else: |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
672 |
erschema.set_action_permissions(action, permissions) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8004
diff
changeset
|
673 |
|
7039
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
674 |
def assertModificationDateGreater(self, entity, olddate): |
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
675 |
entity.cw_attr_cache.pop('modification_date', None) |
7763
31210a2ead63
drop unittest deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7441
diff
changeset
|
676 |
self.assertTrue(entity.modification_date > olddate) |
7039
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
677 |
|
7376
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7337
diff
changeset
|
678 |
def assertItemsEqual(self, it1, it2, *args, **kwargs): |
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7337
diff
changeset
|
679 |
it1 = set(getattr(x, 'eid', x) for x in it1) |
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7337
diff
changeset
|
680 |
it2 = set(getattr(x, 'eid', x) for x in it2) |
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7337
diff
changeset
|
681 |
super(CubicWebTC, self).assertItemsEqual(it1, it2, *args, **kwargs) |
7039
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
682 |
|
7441
b70f4f4c8620
[testlib] add convenience assertion method to check __message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7439
diff
changeset
|
683 |
def assertMessageEqual(self, req, params, msg): |
b70f4f4c8620
[testlib] add convenience assertion method to check __message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7439
diff
changeset
|
684 |
msg = req.session.data[params['_cwmsgid']] |
b70f4f4c8620
[testlib] add convenience assertion method to check __message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7439
diff
changeset
|
685 |
self.assertEqual(msg, msg) |
b70f4f4c8620
[testlib] add convenience assertion method to check __message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7439
diff
changeset
|
686 |
|
7039
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
687 |
# workflow utilities ####################################################### |
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
688 |
|
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
689 |
def assertPossibleTransitions(self, entity, expected): |
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
690 |
transitions = entity.cw_adapt_to('IWorkflowable').possible_transitions() |
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
691 |
self.assertListEqual(sorted(tr.name for tr in transitions), |
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
692 |
sorted(expected)) |
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
693 |
|
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
694 |
|
df0e8581b06f
[testlib] backport some useful testing utilities from tracker's testutils module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7038
diff
changeset
|
695 |
# views and actions registries inspection ################################## |
0 | 696 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
697 |
def pviews(self, req, rset): |
3468
b02fa4db2868
[tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3454
diff
changeset
|
698 |
return sorted((a.__regid__, a.__class__) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
699 |
for a in self.vreg['views'].possible_views(req, rset=rset)) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
700 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
701 |
def pactions(self, req, rset, |
6967
07d889e3f35d
[testlib] by default skip new 'manage' action's category
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
702 |
skipcategories=('addrelated', 'siteactions', 'useractions', |
07d889e3f35d
[testlib] by default skip new 'manage' action's category
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
703 |
'footer', 'manage')): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
704 |
return [(a.__regid__, a.__class__) |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2793
diff
changeset
|
705 |
for a in self.vreg['actions'].poss_visible_objects(req, rset=rset) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
706 |
if a.category not in skipcategories] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
707 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
708 |
def pactions_by_cats(self, req, rset, categories=('addrelated',)): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
709 |
return [(a.__regid__, a.__class__) |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2793
diff
changeset
|
710 |
for a in self.vreg['actions'].poss_visible_objects(req, rset=rset) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
711 |
if a.category in categories] |
0 | 712 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
713 |
def pactionsdict(self, req, rset, |
6967
07d889e3f35d
[testlib] by default skip new 'manage' action's category
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
714 |
skipcategories=('addrelated', 'siteactions', 'useractions', |
07d889e3f35d
[testlib] by default skip new 'manage' action's category
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
715 |
'footer', 'manage')): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
716 |
res = {} |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2793
diff
changeset
|
717 |
for a in self.vreg['actions'].poss_visible_objects(req, rset=rset): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
718 |
if a.category not in skipcategories: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
719 |
res.setdefault(a.category, []).append(a.__class__) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
720 |
return res |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
721 |
|
3230 | 722 |
def action_submenu(self, req, rset, id): |
723 |
return self._test_action(self.vreg['actions'].select(id, req, rset=rset)) |
|
724 |
||
725 |
def _test_action(self, action): |
|
726 |
class fake_menu(list): |
|
727 |
@property |
|
728 |
def items(self): |
|
729 |
return self |
|
730 |
class fake_box(object): |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6774
diff
changeset
|
731 |
def action_link(self, action, **kwargs): |
3230 | 732 |
return (action.title, action.url()) |
733 |
submenu = fake_menu() |
|
734 |
action.fill_menu(fake_box(), submenu) |
|
735 |
return submenu |
|
0 | 736 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
737 |
def list_views_for(self, rset): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
738 |
"""returns the list of views that can be applied on `rset`""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
739 |
req = rset.req |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
740 |
only_once_vids = ('primary', 'secondary', 'text') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
741 |
req.data['ex'] = ValueError("whatever") |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
742 |
viewsvreg = self.vreg['views'] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
743 |
for vid, views in viewsvreg.items(): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
744 |
if vid[0] == '_': |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
745 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
746 |
if rset.rowcount > 1 and vid in only_once_vids: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
747 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
748 |
views = [view for view in views |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
749 |
if view.category != 'startupview' |
6454
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6442
diff
changeset
|
750 |
and not issubclass(view, notification.NotificationView) |
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6442
diff
changeset
|
751 |
and not isinstance(view, class_deprecated)] |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
752 |
if views: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
753 |
try: |
2774 | 754 |
view = viewsvreg._select_best(views, req, rset=rset) |
7272
771f594c12a2
[vreg] vregistry._select_best was needlessly instanciating NoSelectableObject (closes #1626708)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7222
diff
changeset
|
755 |
if view is None: |
771f594c12a2
[vreg] vregistry._select_best was needlessly instanciating NoSelectableObject (closes #1626708)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7222
diff
changeset
|
756 |
raise NoSelectableObject((req,), {'rset':rset}, views) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
757 |
if view.linkable(): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
758 |
yield view |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
759 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
760 |
not_selected(self.vreg, view) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
761 |
# else the view is expected to be used as subview and should |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
762 |
# not be tested directly |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
763 |
except NoSelectableObject: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
764 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
765 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
766 |
def list_actions_for(self, rset): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
767 |
"""returns the list of actions that can be applied on `rset`""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
768 |
req = rset.req |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
769 |
for action in self.vreg['actions'].possible_objects(req, rset=rset): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
770 |
yield action |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
771 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
772 |
def list_boxes_for(self, rset): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
773 |
"""returns the list of boxes that can be applied on `rset`""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
774 |
req = rset.req |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
775 |
for box in self.vreg['ctxcomponents'].possible_objects(req, rset=rset): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
776 |
yield box |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
777 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
778 |
def list_startup_views(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
779 |
"""returns the list of startup views""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
780 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
781 |
for view in self.vreg['views'].possible_views(req, None): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
782 |
if view.category == 'startupview': |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
783 |
yield view.__regid__ |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
784 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
785 |
not_selected(self.vreg, view) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
786 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
787 |
# web ui testing utilities ################################################# |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
788 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
789 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
790 |
@cached |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
791 |
def app(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
792 |
"""return a cubicweb publisher""" |
9031
6ff29f2879da
web/application: instantiate the repository outside of CubicWebPublisher
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9030
diff
changeset
|
793 |
publisher = application.CubicWebPublisher(self.repo, self.config) |
4137
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
794 |
def raise_error_handler(*args, **kwargs): |
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
795 |
raise |
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
796 |
publisher.error_handler = raise_error_handler |
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
797 |
return publisher |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
798 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
799 |
def remote_call(self, fname, *args): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
800 |
"""remote json call simulation""" |
5377
84d14ddfae13
[python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5268
diff
changeset
|
801 |
dump = json.dumps |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
802 |
args = [dump(arg) for arg in args] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
803 |
req = self.request(fname=fname, pageid='123', arg=args) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8004
diff
changeset
|
804 |
ctrl = self.vreg['controllers'].select('ajax', req) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
805 |
return ctrl.publish(), req |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
806 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
807 |
def app_handle_request(self, req, path='view'): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
808 |
return self.app.core_handle(req, path) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
809 |
|
8363
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
810 |
@deprecated("[3.15] app_handle_request is the new and better way" |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
811 |
" (beware of small semantic changes)") |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
812 |
def app_publish(self, *args, **kwargs): |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
813 |
return self.app_handle_request(*args, **kwargs) |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
814 |
|
8720
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
815 |
def ctrl_publish(self, req, ctrl='edit', rset=None): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
816 |
"""call the publish method of the edit controller""" |
5942
f7768f44b4ac
[tests] make sure controllers created by ctrl_publish() have a valid appli attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5813
diff
changeset
|
817 |
ctrl = self.vreg['controllers'].select(ctrl, req, appli=self.app) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
818 |
try: |
8720
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
819 |
result = ctrl.publish(rset) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
820 |
req.cnx.commit() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
821 |
except web.Redirect: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
822 |
req.cnx.commit() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
823 |
raise |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
824 |
return result |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
825 |
|
6166
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
826 |
def req_from_url(self, url): |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
827 |
"""parses `url` and builds the corresponding CW-web request |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
828 |
|
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
829 |
req.form will be setup using the url's query string |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
830 |
""" |
8720
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
831 |
req = self.request(url=url) |
6166
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
832 |
if isinstance(url, unicode): |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
833 |
url = url.encode(req.encoding) # req.setup_params() expects encoded strings |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
834 |
querystring = urlparse.urlparse(url)[-2] |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
835 |
params = urlparse.parse_qs(querystring) |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
836 |
req.setup_params(params) |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
837 |
return req |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
838 |
|
8720
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
839 |
def url_publish(self, url, data=None): |
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
840 |
"""takes `url`, uses application's app_resolver to find the appropriate |
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
841 |
controller and result set, then publishes the result. |
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
842 |
|
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
843 |
To simulate post of www-form-encoded data, give a `data` dictionary |
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
844 |
containing desired key/value associations. |
6166
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
845 |
|
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
846 |
This should pretty much correspond to what occurs in a real CW server |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
847 |
except the apache-rewriter component is not called. |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
848 |
""" |
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
849 |
req = self.req_from_url(url) |
8720
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
850 |
if data is not None: |
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
851 |
req.form.update(data) |
6166
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
852 |
ctrlid, rset = self.app.url_resolver.process(req, req.relative_path(False)) |
8720
d2f01aaae8c0
[testlib] url_publish should give url to the request and the rset returned by the path evaluator to ctrl_publish. Closes #2557468
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8696
diff
changeset
|
853 |
return self.ctrl_publish(req, ctrlid, rset) |
6166
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
854 |
|
8721
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
855 |
def http_publish(self, url, data=None): |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
856 |
"""like `url_publish`, except this returns a http response, even in case of errors""" |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
857 |
req = self.req_from_url(url) |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
858 |
if data is not None: |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
859 |
req.form.update(data) |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
860 |
# remove the monkey patched error handler |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
861 |
fake_error_handler = self.app.error_handler |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
862 |
del self.app.error_handler |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
863 |
try: |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
864 |
result = self.app_handle_request(req, req.relative_path(False)) |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
865 |
finally: |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
866 |
self.app.error_handler = fake_error_handler |
b399c87df63c
[devtools] add http_publish to CubicWebTC (closes #2565882)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8720
diff
changeset
|
867 |
return result, req |
6166
fc47b4e06d94
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6165
diff
changeset
|
868 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
869 |
@staticmethod |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
870 |
def _parse_location(req, location): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
871 |
try: |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
872 |
path, params = location.split('?', 1) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
873 |
except ValueError: |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
874 |
path = location |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
875 |
params = {} |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
876 |
else: |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
877 |
cleanup = lambda p: (p[0], unquote(p[1])) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
878 |
params = dict(cleanup(p.split('=', 1)) for p in params.split('&') if p) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
879 |
if path.startswith(req.base_url()): # may be relative |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
880 |
path = path[len(req.base_url()):] |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
881 |
return path, params |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
882 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
883 |
def expect_redirect(self, callback, req): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
884 |
"""call the given callback with req as argument, expecting to get a |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
885 |
Redirect exception |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
886 |
""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
887 |
try: |
4719
aaed3f813ef8
kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4690
diff
changeset
|
888 |
callback(req) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
889 |
except Redirect as ex: |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
890 |
return self._parse_location(req, ex.location) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
891 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
892 |
self.fail('expected a Redirect exception') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
893 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
894 |
def expect_redirect_handle_request(self, req, path='edit'): |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
895 |
"""call the publish method of the application publisher, expecting to |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
896 |
get a Redirect exception |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
897 |
""" |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
898 |
result = self.app_handle_request(req, path) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
899 |
self.assertTrue(300 <= req.status_out <400, req.status_out) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
900 |
location = req.get_response_header('location') |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
901 |
return self._parse_location(req, location) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
902 |
|
8363
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
903 |
@deprecated("[3.15] expect_redirect_handle_request is the new and better way" |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
904 |
" (beware of small semantic changes)") |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
905 |
def expect_redirect_publish(self, *args, **kwargs): |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
906 |
return self.expect_redirect_handle_request(*args, **kwargs) |
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
907 |
|
3f3b4e4c63f5
[devtool-testlib] add deprecated entry point for publish method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8318
diff
changeset
|
908 |
|
7163
d6d905d0344f
[web test] extract a set_auth_mode method from init_authentication and use it in test_fb_login_concept to avoid bad test interaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7088
diff
changeset
|
909 |
def set_auth_mode(self, authmode, anonuser=None): |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
910 |
self.set_option('auth-mode', authmode) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
911 |
self.set_option('anonymous-user', anonuser) |
7071
db7608cb32bc
[devtools] fix anonymous user handling in test classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7060
diff
changeset
|
912 |
if anonuser is None: |
db7608cb32bc
[devtools] fix anonymous user handling in test classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7060
diff
changeset
|
913 |
self.config.anonymous_credential = None |
db7608cb32bc
[devtools] fix anonymous user handling in test classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7060
diff
changeset
|
914 |
else: |
db7608cb32bc
[devtools] fix anonymous user handling in test classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7060
diff
changeset
|
915 |
self.config.anonymous_credential = (anonuser, anonuser) |
7163
d6d905d0344f
[web test] extract a set_auth_mode method from init_authentication and use it in test_fb_login_concept to avoid bad test interaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7088
diff
changeset
|
916 |
|
d6d905d0344f
[web test] extract a set_auth_mode method from init_authentication and use it in test_fb_login_concept to avoid bad test interaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7088
diff
changeset
|
917 |
def init_authentication(self, authmode, anonuser=None): |
d6d905d0344f
[web test] extract a set_auth_mode method from init_authentication and use it in test_fb_login_concept to avoid bad test interaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7088
diff
changeset
|
918 |
self.set_auth_mode(authmode, anonuser) |
9039
488255d1cf3b
[testlib] rework request building in init_authentication
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9031
diff
changeset
|
919 |
req = self.requestcls(self.vreg, url='login') |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
920 |
sh = self.app.session_handler |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
921 |
authm = sh.session_manager.authmanager |
4916 | 922 |
authm.anoninfo = self.vreg.config.anonymous_user() |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5177
diff
changeset
|
923 |
authm.anoninfo = authm.anoninfo[0], {'password': authm.anoninfo[1]} |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
924 |
# not properly cleaned between tests |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
925 |
self.open_sessions = sh.session_manager._sessions = {} |
9039
488255d1cf3b
[testlib] rework request building in init_authentication
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9031
diff
changeset
|
926 |
return req, self.websession |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
927 |
|
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5177
diff
changeset
|
928 |
def assertAuthSuccess(self, req, origsession, nbsessions=1): |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
929 |
sh = self.app.session_handler |
9019
e08f9c55dab5
[application] call req.set_session in application.main_handle_request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9017
diff
changeset
|
930 |
session = self.app.get_session(req) |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9070
diff
changeset
|
931 |
clt_cnx = repoapi.ClientConnection(session) |
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9070
diff
changeset
|
932 |
req.set_cnx(clt_cnx) |
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6346
diff
changeset
|
933 |
self.assertEqual(len(self.open_sessions), nbsessions, self.open_sessions) |
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6346
diff
changeset
|
934 |
self.assertEqual(session.login, origsession.login) |
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6346
diff
changeset
|
935 |
self.assertEqual(session.anonymous_session, False) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
936 |
|
3676
fa170564e1a0
optional nbsessions arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3657
diff
changeset
|
937 |
def assertAuthFailure(self, req, nbsessions=0): |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8978
diff
changeset
|
938 |
with self.assertRaises(AuthenticationError): |
9019
e08f9c55dab5
[application] call req.set_session in application.main_handle_request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9017
diff
changeset
|
939 |
self.app.get_session(req) |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8978
diff
changeset
|
940 |
# +0 since we do not track the opened session |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8978
diff
changeset
|
941 |
self.assertEqual(len(self.open_sessions), nbsessions) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
942 |
clear_cache(req, 'get_authorization') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
943 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
944 |
# content validation ####################################################### |
0 | 945 |
|
946 |
# validators are used to validate (XML, DTD, whatever) view's content |
|
947 |
# validators availables are : |
|
948 |
# DTDValidator : validates XML + declared DTD |
|
949 |
# SaxOnlyValidator : guarantees XML is well formed |
|
950 |
# None : do not try to validate anything |
|
951 |
# validators used must be imported from from.devtools.htmlparser |
|
534
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
952 |
content_type_validators = { |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
953 |
# maps MIME type : validator name |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
954 |
# |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
955 |
# do not set html validators here, we need HTMLValidator for html |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
956 |
# snippets |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
957 |
#'text/html': DTDValidator, |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
958 |
#'application/xhtml+xml': DTDValidator, |
8971
062e40f41b57
[testlib] SaxOnlyValidator is deprecated, use XMLValidator instead
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
959 |
'application/xml': htmlparser.XMLValidator, |
062e40f41b57
[testlib] SaxOnlyValidator is deprecated, use XMLValidator instead
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
960 |
'text/xml': htmlparser.XMLValidator, |
8652
7812093e21f7
[testlib] test_view now parse json data, closes #2557467
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8628
diff
changeset
|
961 |
'application/json': JsonValidator, |
534
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
962 |
'text/plain': None, |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
963 |
'text/comma-separated-values': None, |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
964 |
'text/x-vcard': None, |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
965 |
'text/calendar': None, |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
966 |
'image/png': None, |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
967 |
} |
562
bdadb26c4a3c
old .validators attribute is now .vid_validators
sylvain.thenault@logilab.fr
parents:
549
diff
changeset
|
968 |
# maps vid : validator name (override content_type_validators) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
969 |
vid_validators = dict((vid, htmlparser.VALMAP[valkey]) |
562
bdadb26c4a3c
old .validators attribute is now .vid_validators
sylvain.thenault@logilab.fr
parents:
549
diff
changeset
|
970 |
for vid, valkey in VIEW_VALIDATORS.iteritems()) |
1605 | 971 |
|
0 | 972 |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
973 |
def view(self, vid, rset=None, req=None, template='main-template', |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
974 |
**kwargs): |
0 | 975 |
"""This method tests the view `vid` on `rset` using `template` |
976 |
||
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5974
diff
changeset
|
977 |
If no error occurred while rendering the view, the HTML is analyzed |
0 | 978 |
and parsed. |
979 |
||
980 |
:returns: an instance of `cubicweb.devtools.htmlparser.PageInfo` |
|
981 |
encapsulation the generated HTML |
|
982 |
""" |
|
8628
b236b91836c0
[test] fix req default value handling in CubicWebTC.view (closes #2544376)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8497
diff
changeset
|
983 |
if req is None: |
b236b91836c0
[test] fix req default value handling in CubicWebTC.view (closes #2544376)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8497
diff
changeset
|
984 |
if rset is None: |
b236b91836c0
[test] fix req default value handling in CubicWebTC.view (closes #2544376)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8497
diff
changeset
|
985 |
req = self.request() |
b236b91836c0
[test] fix req default value handling in CubicWebTC.view (closes #2544376)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8497
diff
changeset
|
986 |
else: |
b236b91836c0
[test] fix req default value handling in CubicWebTC.view (closes #2544376)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8497
diff
changeset
|
987 |
req = rset.req |
0 | 988 |
req.form['vid'] = vid |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2234
diff
changeset
|
989 |
viewsreg = self.vreg['views'] |
8497
7f71e366cb5e
[testlib] consider rset for template / view selection (closes #2447183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8480
diff
changeset
|
990 |
view = viewsreg.select(vid, req, rset=rset, **kwargs) |
0 | 991 |
# set explicit test description |
992 |
if rset is not None: |
|
5875
e707d481219e
[testlib] improve test description messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5815
diff
changeset
|
993 |
self.set_description("testing vid=%s defined in %s with (%s)" % ( |
2070 | 994 |
vid, view.__module__, rset.printable_rql())) |
0 | 995 |
else: |
5875
e707d481219e
[testlib] improve test description messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5815
diff
changeset
|
996 |
self.set_description("testing vid=%s defined in %s without rset" % ( |
2070 | 997 |
vid, view.__module__)) |
0 | 998 |
if template is None: # raw view testing, no template |
1773 | 999 |
viewfunc = view.render |
829
ea092805d8f8
The main template is now a simple view, there's no need to monkey patch TheMainTemplate._select_view_and_rset
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
1000 |
else: |
ea092805d8f8
The main template is now a simple view, there's no need to monkey patch TheMainTemplate._select_view_and_rset
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
1001 |
kwargs['view'] = view |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2234
diff
changeset
|
1002 |
viewfunc = lambda **k: viewsreg.main_template(req, template, |
8497
7f71e366cb5e
[testlib] consider rset for template / view selection (closes #2447183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8480
diff
changeset
|
1003 |
rset=rset, **kwargs) |
829
ea092805d8f8
The main template is now a simple view, there's no need to monkey patch TheMainTemplate._select_view_and_rset
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
1004 |
return self._test_view(viewfunc, view, template, kwargs) |
0 | 1005 |
|
1006 |
||
829
ea092805d8f8
The main template is now a simple view, there's no need to monkey patch TheMainTemplate._select_view_and_rset
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
823
diff
changeset
|
1007 |
def _test_view(self, viewfunc, view, template='main-template', kwargs={}): |
0 | 1008 |
"""this method does the actual call to the view |
1009 |
||
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5974
diff
changeset
|
1010 |
If no error occurred while rendering the view, the HTML is analyzed |
0 | 1011 |
and parsed. |
1012 |
||
1013 |
:returns: an instance of `cubicweb.devtools.htmlparser.PageInfo` |
|
1014 |
encapsulation the generated HTML |
|
1015 |
""" |
|
1016 |
try: |
|
1017 |
output = viewfunc(**kwargs) |
|
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1018 |
except Exception: |
0 | 1019 |
# hijack exception: generative tests stop when the exception |
1020 |
# is not an AssertionError |
|
1021 |
klass, exc, tcbk = sys.exc_info() |
|
1022 |
try: |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
1023 |
msg = '[%s in %s] %s' % (klass, view.__regid__, exc) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1024 |
except Exception: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
1025 |
msg = '[%s in %s] undisplayable exception' % (klass, view.__regid__) |
0 | 1026 |
raise AssertionError, msg, tcbk |
6806
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1027 |
return self._check_html(output, view, template) |
427
e894eec21a1b
move selection of entity types to test in a method to ease overriding
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
1028 |
|
6978
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1029 |
def get_validator(self, view=None, content_type=None, output=None): |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1030 |
if view is not None: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1031 |
try: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1032 |
return self.vid_validators[view.__regid__]() |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1033 |
except KeyError: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1034 |
if content_type is None: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1035 |
content_type = view.content_type |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1036 |
if content_type is None: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1037 |
content_type = 'text/html' |
8978
269548f2306e
[testlib] fix page validator selection. Closes #2869456
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8975
diff
changeset
|
1038 |
if content_type in ('text/html', 'application/xhtml+xml') and output: |
269548f2306e
[testlib] fix page validator selection. Closes #2869456
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8975
diff
changeset
|
1039 |
if output.startswith('<!DOCTYPE html>'): |
269548f2306e
[testlib] fix page validator selection. Closes #2869456
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8975
diff
changeset
|
1040 |
# only check XML well-formness since HTMLValidator isn't html5 |
269548f2306e
[testlib] fix page validator selection. Closes #2869456
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8975
diff
changeset
|
1041 |
# compatible and won't like various other extensions |
269548f2306e
[testlib] fix page validator selection. Closes #2869456
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8975
diff
changeset
|
1042 |
default_validator = htmlparser.XMLSyntaxValidator |
269548f2306e
[testlib] fix page validator selection. Closes #2869456
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8975
diff
changeset
|
1043 |
elif output.startswith('<?xml'): |
6978
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1044 |
default_validator = htmlparser.DTDValidator |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1045 |
else: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1046 |
default_validator = htmlparser.HTMLValidator |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1047 |
else: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1048 |
default_validator = None |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1049 |
validatorclass = self.content_type_validators.get(content_type, |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1050 |
default_validator) |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1051 |
if validatorclass is None: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1052 |
return |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1053 |
return validatorclass() |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1054 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1055 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1056 |
def _check_html(self, output, view, template='main-template'): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1057 |
"""raises an exception if the HTML is invalid""" |
6772
68bb0943d192
[test, html validation] make validator selection somewhat smarter (at least it works properly when content is demoted from xhtml to html, making the XMLDemotingValidator class useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6721
diff
changeset
|
1058 |
output = output.strip() |
6978
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1059 |
validator = self.get_validator(view, output=output) |
6979
a8fbcf9b6572
[testlib] take care, validator may be None
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6978
diff
changeset
|
1060 |
if validator is None: |
7821
3ecd114f6d75
[testlib] make self.view() return raw output if no validator is used
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7797
diff
changeset
|
1061 |
return output # return raw output if no validator is defined |
4346
02f12f39bae5
XXX quick fix html validation by removing <canvas>
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1062 |
if isinstance(validator, htmlparser.DTDValidator): |
02f12f39bae5
XXX quick fix html validation by removing <canvas>
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1063 |
# XXX remove <canvas> used in progress widget, unknown in html dtd |
02f12f39bae5
XXX quick fix html validation by removing <canvas>
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1064 |
output = re.sub('<canvas.*?></canvas>', '', output) |
6806
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1065 |
return self.assertWellFormed(validator, output.strip(), context= view.__regid__) |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1066 |
|
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1067 |
def assertWellFormed(self, validator, content, context=None): |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1068 |
try: |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1069 |
return validator.parse_string(content) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1070 |
except Exception: |
6806
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1071 |
# hijack exception: generative tests stop when the exception |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1072 |
# is not an AssertionError |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1073 |
klass, exc, tcbk = sys.exc_info() |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1074 |
if context is None: |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1075 |
msg = u'[%s]' % (klass,) |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1076 |
else: |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1077 |
msg = u'[%s in %s]' % (klass, context) |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1078 |
msg = msg.encode(sys.getdefaultencoding(), 'replace') |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1079 |
|
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1080 |
try: |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1081 |
str_exc = str(exc) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1082 |
except Exception: |
6806
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1083 |
str_exc = 'undisplayable exception' |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1084 |
msg += str_exc |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1085 |
if content is not None: |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1086 |
position = getattr(exc, "position", (0,))[0] |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1087 |
if position: |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1088 |
# define filter |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1089 |
if isinstance(content, str): |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1090 |
content = unicode(content, sys.getdefaultencoding(), 'replace') |
8975
045e449617ad
[testlib] repreprocess content so contextual display has a chance to show the proper line. Closes #2869481
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8971
diff
changeset
|
1091 |
content = validator.preprocess_data(content) |
6806
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1092 |
content = content.splitlines() |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1093 |
width = int(log(len(content), 10)) + 1 |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1094 |
line_template = " %" + ("%i" % width) + "i: %s" |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1095 |
# XXX no need to iterate the whole file except to get |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1096 |
# the line number |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1097 |
content = u'\n'.join(line_template % (idx + 1, line) |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1098 |
for idx, line in enumerate(content) |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1099 |
if line_context_filter(idx+1, position)) |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1100 |
msg += u'\nfor content:\n%s' % content |
8291f5e0c9f6
[testlib] extract validation logic into a ``assertWellFormed`` method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6800
diff
changeset
|
1101 |
raise AssertionError, msg, tcbk |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1102 |
|
6978
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1103 |
def assertDocTestFile(self, testfile): |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1104 |
# doctest returns tuple (failure_count, test_count) |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1105 |
result = self.shell().process_script(testfile) |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1106 |
if result[0] and result[1]: |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1107 |
raise self.failureException("doctest file '%s' failed" |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1108 |
% testfile) |
cac71b8a8711
[testlib] extract get_validator method from _check_html, move assertDocTestFile
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6806
diff
changeset
|
1109 |
|
7060
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1110 |
# notifications ############################################################ |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1111 |
|
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1112 |
def assertSentEmail(self, subject, recipients=None, nb_msgs=None): |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1113 |
"""test recipients in system mailbox for given email subject |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1114 |
|
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1115 |
:param subject: email subject to find in mailbox |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1116 |
:param recipients: list of email recipients |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1117 |
:param nb_msgs: expected number of entries |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1118 |
:returns: list of matched emails |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1119 |
""" |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1120 |
messages = [email for email in MAILBOX |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1121 |
if email.message.get('Subject') == subject] |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1122 |
if recipients is not None: |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1123 |
sent_to = set() |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1124 |
for msg in messages: |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1125 |
sent_to.update(msg.recipients) |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1126 |
self.assertSetEqual(set(recipients), sent_to) |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1127 |
if nb_msgs is not None: |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1128 |
self.assertEqual(len(MAILBOX), nb_msgs) |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1129 |
return messages |
f26a1cbddc91
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7039
diff
changeset
|
1130 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1131 |
# deprecated ############################################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1132 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1133 |
@deprecated('[3.8] use self.execute(...).get_entity(0, 0)') |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1134 |
def entity(self, rql, args=None, eidkey=None, req=None): |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1135 |
if eidkey is not None: |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1136 |
warn('[3.8] eidkey is deprecated, you can safely remove this argument', |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1137 |
DeprecationWarning, stacklevel=2) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1138 |
return self.execute(rql, args, req=req).get_entity(0, 0) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
1139 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1140 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1141 |
# auto-populating test classes and utilities ################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1142 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1143 |
from cubicweb.devtools.fill import insert_entity_queries, make_relations_queries |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1144 |
|
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1145 |
# XXX cleanup unprotected_entities & all mess |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1146 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1147 |
def how_many_dict(schema, cursor, how_many, skip): |
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1148 |
"""given a schema, compute how many entities by type we need to be able to |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1149 |
satisfy relations cardinality. |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1150 |
|
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1151 |
The `how_many` argument tells how many entities of which type we want at |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1152 |
least. |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1153 |
|
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1154 |
Return a dictionary with entity types as key, and the number of entities for |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1155 |
this type as value. |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1156 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1157 |
relmap = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1158 |
for rschema in schema.relations(): |
3720 | 1159 |
if rschema.final: |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1160 |
continue |
4053
7cc66b1d9183
more api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4036
diff
changeset
|
1161 |
for subj, obj in rschema.rdefs: |
7cc66b1d9183
more api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4036
diff
changeset
|
1162 |
card = rschema.rdef(subj, obj).cardinality |
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1163 |
# if the relation is mandatory, we'll need at least as many subj and |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1164 |
# obj to satisfy it |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1165 |
if card[0] in '1+' and card[1] in '1?': |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1166 |
# subj has to be linked to at least one obj, |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1167 |
# but obj can be linked to only one subj |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1168 |
# -> we need at least as many subj as obj to satisfy |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1169 |
# cardinalities for this relation |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1170 |
relmap.setdefault((rschema, subj), []).append(str(obj)) |
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1171 |
if card[1] in '1+' and card[0] in '1?': |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1172 |
# reverse subj and obj in the above explanation |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1173 |
relmap.setdefault((rschema, obj), []).append(str(subj)) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1174 |
unprotected = unprotected_entities(schema) |
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1175 |
for etype in skip: # XXX (syt) duh? explain or kill |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1176 |
unprotected.add(etype) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1177 |
howmanydict = {} |
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1178 |
# step 1, compute a base number of each entity types: number of already |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1179 |
# existing entities of this type + `how_many` |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1180 |
for etype in unprotected_entities(schema, strict=True): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1181 |
howmanydict[str(etype)] = cursor.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1182 |
if etype in unprotected: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1183 |
howmanydict[str(etype)] += how_many |
4513
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1184 |
# step 2, augment nb entity per types to satisfy cardinality constraints, |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1185 |
# by recomputing for each relation that constrained an entity type: |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1186 |
# |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1187 |
# new num for etype = max(current num, sum(num for possible target etypes)) |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1188 |
# |
8abf464d2ffe
fix and begin to document autofill algorithm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4367
diff
changeset
|
1189 |
# XXX we should first check there is no cycle then propagate changes |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1190 |
for (rschema, etype), targets in relmap.iteritems(): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1191 |
relfactor = sum(howmanydict[e] for e in targets) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1192 |
howmanydict[str(etype)] = max(relfactor, howmanydict[etype]) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1193 |
return howmanydict |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1194 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1195 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1196 |
class AutoPopulateTest(CubicWebTC): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1197 |
"""base class for test with auto-populating of the database""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1198 |
__abstract__ = True |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1199 |
|
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
1200 |
test_db_id = 'autopopulate' |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
1201 |
|
5913
85240b3f9ee4
[test] add default generic test Tags to CubicWeb TestCase class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5875
diff
changeset
|
1202 |
tags = CubicWebTC.tags | Tags('autopopulated') |
85240b3f9ee4
[test] add default generic test Tags to CubicWeb TestCase class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5875
diff
changeset
|
1203 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1204 |
pdbclass = CubicWebDebugger |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1205 |
# this is a hook to be able to define a list of rql queries |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1206 |
# that are application dependent and cannot be guessed automatically |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1207 |
application_rql = [] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1208 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1209 |
no_auto_populate = () |
3734
b2107f68176c
ignored_relations should be a set
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
1210 |
ignored_relations = set() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1211 |
|
427
e894eec21a1b
move selection of entity types to test in a method to ease overriding
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
1212 |
def to_test_etypes(self): |
e894eec21a1b
move selection of entity types to test in a method to ease overriding
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
1213 |
return unprotected_entities(self.schema, strict=True) |
1605 | 1214 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1215 |
def custom_populate(self, how_many, cursor): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1216 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1217 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1218 |
def post_populate(self, cursor): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1219 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1220 |
|
3720 | 1221 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1222 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1223 |
def auto_populate(self, how_many): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1224 |
"""this method populates the database with `how_many` entities |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1225 |
of each possible type. It also inserts random relations between them |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1226 |
""" |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8543
diff
changeset
|
1227 |
with self.session.security_enabled(read=False, write=False): |
5004
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4958
diff
changeset
|
1228 |
self._auto_populate(how_many) |
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4958
diff
changeset
|
1229 |
|
4cc020ee70e2
le patch rql26 a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4958
diff
changeset
|
1230 |
def _auto_populate(self, how_many): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1231 |
cu = self.cursor() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1232 |
self.custom_populate(how_many, cu) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1233 |
vreg = self.vreg |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1234 |
howmanydict = how_many_dict(self.schema, cu, how_many, self.no_auto_populate) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1235 |
for etype in unprotected_entities(self.schema): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1236 |
if etype in self.no_auto_populate: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1237 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1238 |
nb = howmanydict.get(etype, how_many) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1239 |
for rql, args in insert_entity_queries(etype, self.schema, vreg, nb): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1240 |
cu.execute(rql, args) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1241 |
edict = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1242 |
for etype in unprotected_entities(self.schema, strict=True): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1243 |
rset = cu.execute('%s X' % etype) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1244 |
edict[str(etype)] = set(row[0] for row in rset.rows) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1245 |
existingrels = {} |
4036
137be4878127
[mq]: fix_set_addition
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
4016
diff
changeset
|
1246 |
ignored_relations = SYSTEM_RELATIONS | self.ignored_relations |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1247 |
for rschema in self.schema.relations(): |
3720 | 1248 |
if rschema.final or rschema in ignored_relations: |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1249 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1250 |
rset = cu.execute('DISTINCT Any X,Y WHERE X %s Y' % rschema) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1251 |
existingrels.setdefault(rschema.type, set()).update((x, y) for x, y in rset) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1252 |
q = make_relations_queries(self.schema, edict, cu, ignored_relations, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1253 |
existingrels=existingrels) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1254 |
for rql, args in q: |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
1255 |
try: |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
1256 |
cu.execute(rql, args) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
1257 |
except ValidationError as ex: |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
1258 |
# failed to satisfy some constraint |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
1259 |
print 'error in automatic db population', ex |
6469
82cf41ae8b89
[test] reset uncommitable flag on ValidationError raised during automatic db population
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
1260 |
self.session.commit_state = None # reset uncommitable flag |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1261 |
self.post_populate(cu) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1262 |
self.commit() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1263 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1264 |
def iter_individual_rsets(self, etypes=None, limit=None): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1265 |
etypes = etypes or self.to_test_etypes() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1266 |
for etype in etypes: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1267 |
if limit: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1268 |
rql = 'Any X LIMIT %s WHERE X is %s' % (limit, etype) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1269 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1270 |
rql = 'Any X WHERE X is %s' % etype |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1271 |
rset = self.execute(rql) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1272 |
for row in xrange(len(rset)): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1273 |
if limit and row > limit: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1274 |
break |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1275 |
# XXX iirk |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1276 |
rset2 = rset.limit(limit=1, offset=row) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1277 |
yield rset2 |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1278 |
|
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
1279 |
def iter_automatic_rsets(self, limit=10): |
0 | 1280 |
"""generates basic resultsets for each entity type""" |
427
e894eec21a1b
move selection of entity types to test in a method to ease overriding
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
1281 |
etypes = self.to_test_etypes() |
2219
bb5098e74b82
protect against empty etypes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2070
diff
changeset
|
1282 |
if not etypes: |
bb5098e74b82
protect against empty etypes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2070
diff
changeset
|
1283 |
return |
0 | 1284 |
for etype in etypes: |
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
1285 |
yield self.execute('Any X LIMIT %s WHERE X is %s' % (limit, etype)) |
0 | 1286 |
etype1 = etypes.pop() |
1775
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
1287 |
try: |
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
1288 |
etype2 = etypes.pop() |
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
1289 |
except KeyError: |
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
1290 |
etype2 = etype1 |
0 | 1291 |
# test a mixed query (DISTINCT/GROUP to avoid getting duplicate |
1292 |
# X which make muledit view failing for instance (html validation fails |
|
1293 |
# because of some duplicate "id" attributes) |
|
1294 |
yield self.execute('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is %s, Y is %s' % (etype1, etype2)) |
|
1295 |
# test some application-specific queries if defined |
|
1296 |
for rql in self.application_rql: |
|
1297 |
yield self.execute(rql) |
|
1298 |
||
1299 |
def _test_everything_for(self, rset): |
|
1300 |
"""this method tries to find everything that can be tested |
|
1301 |
for `rset` and yields a callable test (as needed in generative tests) |
|
1302 |
""" |
|
1303 |
propdefs = self.vreg['propertydefs'] |
|
1304 |
# make all components visible |
|
1305 |
for k, v in propdefs.items(): |
|
1306 |
if k.endswith('visible') and not v['default']: |
|
1307 |
propdefs[k]['default'] = True |
|
1308 |
for view in self.list_views_for(rset): |
|
3764
034aa14b740a
drop _prepare_copy method from rset in favor of a more generic copy method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1309 |
backup_rset = rset.copy(rset.rows, rset.description) |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
1310 |
yield InnerTest(self._testname(rset, view.__regid__, 'view'), |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
1311 |
self.view, view.__regid__, rset, |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
563
diff
changeset
|
1312 |
rset.req.reset_headers(), 'main-template') |
0 | 1313 |
# We have to do this because some views modify the |
1314 |
# resultset's syntax tree |
|
1315 |
rset = backup_rset |
|
1316 |
for action in self.list_actions_for(rset): |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
1317 |
yield InnerTest(self._testname(rset, action.__regid__, 'action'), self._test_action, action) |
0 | 1318 |
for box in self.list_boxes_for(rset): |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
1319 |
w = [].append |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
1320 |
yield InnerTest(self._testname(rset, box.__regid__, 'box'), box.render, w) |
0 | 1321 |
|
1322 |
@staticmethod |
|
1323 |
def _testname(rset, objid, objtype): |
|
1324 |
return '%s_%s_%s' % ('_'.join(rset.column_types(0)), objid, objtype) |
|
1605 | 1325 |
|
0 | 1326 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1327 |
# concrete class for automated application testing ############################ |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1328 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1329 |
class AutomaticWebTest(AutoPopulateTest): |
0 | 1330 |
"""import this if you wan automatic tests to be ran""" |
5913
85240b3f9ee4
[test] add default generic test Tags to CubicWeb TestCase class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5875
diff
changeset
|
1331 |
|
85240b3f9ee4
[test] add default generic test Tags to CubicWeb TestCase class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5875
diff
changeset
|
1332 |
tags = AutoPopulateTest.tags | Tags('web', 'generated') |
85240b3f9ee4
[test] add default generic test Tags to CubicWeb TestCase class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5875
diff
changeset
|
1333 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1334 |
def setUp(self): |
8004 | 1335 |
assert not self.__class__ is AutomaticWebTest, 'Please subclass AutomaticWebTest to prevent database caching issue' |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
1336 |
super(AutomaticWebTest, self).setUp() |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7071
diff
changeset
|
1337 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1338 |
# access to self.app for proper initialization of the authentication |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1339 |
# machinery (else some views may fail) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1340 |
self.app |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1341 |
|
0 | 1342 |
## one each |
1343 |
def test_one_each_config(self): |
|
1344 |
self.auto_populate(1) |
|
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
1345 |
for rset in self.iter_automatic_rsets(limit=1): |
0 | 1346 |
for testargs in self._test_everything_for(rset): |
1347 |
yield testargs |
|
1348 |
||
1349 |
## ten each |
|
1350 |
def test_ten_each_config(self): |
|
1351 |
self.auto_populate(10) |
|
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
1352 |
for rset in self.iter_automatic_rsets(limit=10): |
0 | 1353 |
for testargs in self._test_everything_for(rset): |
1354 |
yield testargs |
|
1605 | 1355 |
|
0 | 1356 |
## startup views |
1357 |
def test_startup_views(self): |
|
1358 |
for vid in self.list_startup_views(): |
|
1359 |
req = self.request() |
|
1360 |
yield self.view, vid, None, req |
|
1361 |
||
1362 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1363 |
# registry instrumentization ################################################### |
0 | 1364 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
1365 |
def not_selected(vreg, appobject): |
534
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
1366 |
try: |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
1367 |
vreg._selected[appobject.__class__] -= 1 |
534
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
1368 |
except (KeyError, AttributeError): |
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
1369 |
pass |
1605 | 1370 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1371 |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1372 |
# def vreg_instrumentize(testclass): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1373 |
# # XXX broken |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1374 |
# from cubicweb.devtools.apptest import TestEnvironment |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1375 |
# env = testclass._env = TestEnvironment('data', configcls=testclass.configcls) |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
1376 |
# for reg in env.vreg.itervalues(): |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1377 |
# reg._selected = {} |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1378 |
# try: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1379 |
# orig_select_best = reg.__class__.__orig_select_best |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1380 |
# except Exception: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1381 |
# orig_select_best = reg.__class__._select_best |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1382 |
# def instr_select_best(self, *args, **kwargs): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1383 |
# selected = orig_select_best(self, *args, **kwargs) |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1384 |
# try: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1385 |
# self._selected[selected.__class__] += 1 |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1386 |
# except KeyError: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1387 |
# self._selected[selected.__class__] = 1 |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1388 |
# except AttributeError: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1389 |
# pass # occurs on reg used to restore database |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1390 |
# return selected |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1391 |
# reg.__class__._select_best = instr_select_best |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1392 |
# reg.__class__.__orig_select_best = orig_select_best |
534
1368c80276bc
refactor validator selection using a content type based dictionnary (which may be overriden by view id) + functions to instrumentize the registry to check what's tested and what's not
sylvain.thenault@logilab.fr
parents:
514
diff
changeset
|
1393 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1394 |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1395 |
# def print_untested_objects(testclass, skipregs=('hooks', 'etypes')): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1396 |
# for regname, reg in testclass._env.vreg.iteritems(): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1397 |
# if regname in skipregs: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1398 |
# continue |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1399 |
# for appobjects in reg.itervalues(): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1400 |
# for appobject in appobjects: |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1401 |
# if not reg._selected.get(appobject): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
1402 |
# print 'not tested', regname, appobject |