author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 25 Jan 2010 19:13:17 +0100 | |
changeset 4337 | 27ea69e2cfea |
parent 4252 | 6c4f109c2b03 |
child 4346 | 02f12f39bae5 |
permissions | -rw-r--r-- |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
1 |
"""this module contains base classes and utilities for cubicweb tests |
0 | 2 |
|
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3956
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1775
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
10 |
import os |
0 | 11 |
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
|
12 |
import re |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
13 |
from urllib import unquote |
0 | 14 |
from math import log |
15 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
16 |
import simplejson |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
17 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
18 |
import yams.schema |
0 | 19 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
20 |
from logilab.common.testlib import TestCase, InnerTest |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
21 |
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
|
22 |
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
|
23 |
from logilab.common.umessage import message_from_string |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
24 |
from logilab.common.decorators import cached, classproperty, clear_cache |
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 logilab.common.deprecation import deprecated |
0 | 26 |
|
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
27 |
from cubicweb import ValidationError, NoSelectableObject, AuthenticationError |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
28 |
from cubicweb import cwconfig, devtools, web, server |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
29 |
from cubicweb.dbapi import repo_connect, ConnectionProperties, ProgrammingError |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
30 |
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
|
31 |
from cubicweb.web import Redirect, application |
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 |
from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
33 |
from cubicweb.devtools import fake, htmlparser |
0 | 34 |
|
35 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
36 |
# low-level utilities ########################################################## |
0 | 37 |
|
38 |
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
|
39 |
"""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
|
40 |
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
|
41 |
""" |
0 | 42 |
def do_view(self, arg): |
43 |
import webbrowser |
|
44 |
data = self._getval(arg) |
|
45 |
file('/tmp/toto.html', 'w').write(data) |
|
46 |
webbrowser.open('file:///tmp/toto.html') |
|
47 |
||
48 |
def line_context_filter(line_no, center, before=3, after=None): |
|
49 |
"""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
|
50 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
51 |
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
|
52 |
""" |
0 | 53 |
if after is None: |
54 |
after = before |
|
55 |
return center - before <= line_no <= center + after |
|
56 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
57 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
58 |
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
|
59 |
"""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
|
60 |
(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
|
61 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
62 |
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
|
63 |
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
|
64 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
|
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 |
def get_versions(self, checkversions=False): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
70 |
"""return the a dictionary containing cubes used by this instance |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
71 |
as key with their version as value, including cubicweb version. This is a |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
72 |
public method, not requiring a session id. |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
73 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
74 |
replace Repository.get_versions by this method if you don't want versions |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
75 |
checking |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
76 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
77 |
vcconf = {'cubicweb': self.config.cubicweb_version()} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
78 |
self.config.bootstrap_cubes() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
79 |
for pk in self.config.cubes(): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
80 |
version = self.config.cube_version(pk) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
81 |
vcconf[pk] = version |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
82 |
self.config._cubes = None |
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 vcconf |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
84 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
85 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
86 |
def refresh_repo(repo): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
87 |
devtools.reset_test_database(repo.config) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
88 |
for pool in repo.pools: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
89 |
pool.reconnect() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
90 |
repo._type_source_cache = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
91 |
repo._extid_cache = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
92 |
repo.querier._rql_cache = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
93 |
for source in repo.sources: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
94 |
source.reset_caches() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
95 |
|
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 |
# 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
|
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 |
MAILBOX = [] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
100 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
101 |
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
|
102 |
"""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
|
103 |
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
|
104 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
105 |
* `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
|
106 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
107 |
* `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
|
108 |
message |
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 |
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
|
111 |
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
|
112 |
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
|
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 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
|
116 |
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
|
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 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
119 |
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
|
120 |
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
|
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 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
130 |
# 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
|
131 |
# 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
|
132 |
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
|
133 |
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
|
134 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
135 |
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
|
136 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
140 |
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
|
141 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
142 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
143 |
# 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
|
144 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
145 |
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
|
146 |
"""abstract class for test using an apptest environment |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
147 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
148 |
attributes: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
149 |
`vreg`, the vregistry |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
150 |
`schema`, 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
|
151 |
`config`, cubicweb configuration |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
152 |
`cnx`, dbapi connection to the repository using an admin user |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
153 |
`session`, server side session associated to `cnx` |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
154 |
`app`, the cubicweb publisher (for web testing) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
155 |
`repo`, the repository object |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
156 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
157 |
`admlogin`, login of the admin user |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
158 |
`admpassword`, password of the admin user |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
159 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
160 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
161 |
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
|
162 |
configcls = devtools.ApptestConfiguration |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
163 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
164 |
@classproperty |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
165 |
def config(cls): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
166 |
"""return the configuration object. Configuration is cached on the test |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
167 |
class. |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
168 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
169 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
170 |
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
|
171 |
except KeyError: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
172 |
config = cls._config = cls.configcls(cls.appid) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
176 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
177 |
def init_config(cls, config): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
178 |
"""configuration initialization hooks. You may want to override this.""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
# 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
|
183 |
#config.global_set_option('query-log-file', |
edfe43ceaa35
backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
184 |
# '/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
|
185 |
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
|
186 |
# 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
|
187 |
# 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
|
188 |
config.global_set_option('default-dest-addrs', ['whatever']) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
189 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
190 |
send_to = '%s@logilab.fr' % os.getlogin() |
3163
edfe43ceaa35
backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
191 |
# AttributeError since getlogin not available under all platforms |
edfe43ceaa35
backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
192 |
except (OSError, AttributeError): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
193 |
send_to = '%s@logilab.fr' % (os.environ.get('USER') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
194 |
or os.environ.get('USERNAME') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
195 |
or os.environ.get('LOGNAME')) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
config.global_set_option('sender-addr', 'cubicweb-test@logilab.fr') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
200 |
# 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
|
201 |
config.global_set_option('base-url', devtools.BASE_URL) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
202 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
203 |
config.global_set_option('embed-allowed', re.compile('.*')) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
204 |
except: # not in server only configuration |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
205 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
206 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
207 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
208 |
def _init_repo(cls): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
209 |
"""init the repository and connection to it. |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
210 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
211 |
Repository and connection are cached on the test class. Once |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
212 |
initialized, we simply reset connections and repository caches. |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
213 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
214 |
if not 'repo' in cls.__dict__: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
215 |
cls._build_repo() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
216 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
217 |
cls.cnx.rollback() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
218 |
cls._refresh_repo() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
219 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
220 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
221 |
def _build_repo(cls): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
222 |
cls.repo, cls.cnx = devtools.init_test_database(config=cls.config) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
223 |
cls.init_config(cls.config) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
224 |
cls.vreg = cls.repo.vreg |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
225 |
cls._orig_cnx = cls.cnx |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
226 |
cls.config.repository = lambda x=None: cls.repo |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
227 |
# necessary for authentication tests |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
228 |
cls.cnx.login = cls.admlogin |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
229 |
cls.cnx.authinfo = {'password': cls.admpassword} |
2773
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 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
232 |
def _refresh_repo(cls): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
233 |
refresh_repo(cls.repo) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
234 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
235 |
# 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
|
236 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
237 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
238 |
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
|
239 |
"""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
|
240 |
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
|
241 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
242 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
243 |
def session(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
244 |
"""return current server side session (using default manager account)""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
245 |
return self.repo._sessions[self.cnx.sessionid] |
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 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
248 |
def adminsession(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
249 |
"""return current server side session (using default manager account)""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
250 |
return self.repo._sessions[self._orig_cnx.sessionid] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
251 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
255 |
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
|
256 |
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
|
257 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
258 |
# 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
|
259 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
260 |
def setUp(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
261 |
pause_tracing() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
262 |
self._init_repo() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
MAILBOX[:] = [] # reset mailbox |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
267 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
268 |
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
|
269 |
"""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
|
270 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
271 |
# 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
|
272 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
273 |
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
|
274 |
"""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
|
275 |
if req 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
|
276 |
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
|
277 |
return self.cnx.user(req) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
278 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
279 |
return req.user |
563
a690996639ca
[testlib] fix pb. related to class scoped variables
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
562
diff
changeset
|
280 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
281 |
def create_user(self, login, groups=('users',), password=None, 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
|
282 |
commit=True): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
283 |
"""create and return a new user entity""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
284 |
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
|
285 |
password = login.encode('utf8') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
286 |
cursor = self._orig_cnx.cursor(req or self.request()) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2813
diff
changeset
|
287 |
rset = cursor.execute('INSERT CWUser X: X login %(login)s, X upassword %(passwd)s', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
288 |
{'login': unicode(login), 'passwd': password}) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
289 |
user = rset.get_entity(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
|
290 |
cursor.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)' |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
291 |
% ','.join(repr(g) for g in groups), |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
292 |
{'x': user.eid}, 'x') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
293 |
user.clear_related_cache('in_group', 'subject') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
294 |
if commit: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
295 |
self._orig_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
|
296 |
return user |
563
a690996639ca
[testlib] fix pb. related to class scoped variables
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
562
diff
changeset
|
297 |
|
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
298 |
def login(self, login, **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
|
299 |
"""return a connection for the given login/password""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
300 |
if login == self.admlogin: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
301 |
self.restore_connection() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
302 |
else: |
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
303 |
if not kwargs: |
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
304 |
kwargs['password'] = str(login) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
305 |
self.cnx = repo_connect(self.repo, unicode(login), |
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
306 |
cnxprops=ConnectionProperties('inmemory'), |
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
307 |
**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
|
308 |
if login == self.vreg.config.anonymous_user()[0]: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
309 |
self.cnx.anonymous_connection = True |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
310 |
return self.cnx |
563
a690996639ca
[testlib] fix pb. related to class scoped variables
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
562
diff
changeset
|
311 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
312 |
def restore_connection(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
313 |
if not self.cnx is self._orig_cnx: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
314 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
315 |
self.cnx.close() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
316 |
except ProgrammingError: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
317 |
pass # already closed |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
318 |
self.cnx = self._orig_cnx |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
319 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
320 |
# db api ################################################################## |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
321 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
322 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
323 |
def cursor(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
|
324 |
return self.cnx.cursor(req or 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
|
325 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
326 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
327 |
def execute(self, rql, args=None, eidkey=None, 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
|
328 |
"""executes <rql>, builds a resultset, and returns a couple (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
|
329 |
where req is a FakeRequest |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
330 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
331 |
req = req or self.request(rql=rql) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
332 |
return self.cnx.cursor(req).execute(unicode(rql), args, eidkey) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
333 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
334 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
335 |
def commit(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
336 |
self.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
|
337 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
338 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
339 |
def rollback(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
340 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
341 |
self.cnx.rollback() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
342 |
except ProgrammingError: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
343 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
344 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
345 |
# # server side db api ####################################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
346 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
347 |
def sexecute(self, rql, args=None, eid_key=None): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
348 |
self.session.set_pool() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
349 |
return self.session.execute(rql, args, eid_key) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
350 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
351 |
# 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
|
352 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
353 |
def entity(self, rql, args=None, eidkey=None, 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
|
354 |
return self.execute(rql, args, eidkey, req=req).get_entity(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
|
355 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
356 |
# vregistry inspection utilities ########################################### |
0 | 357 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
358 |
def pviews(self, req, rset): |
3468
b02fa4db2868
[tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3454
diff
changeset
|
359 |
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
|
360 |
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
|
361 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
362 |
def pactions(self, req, rset, |
3589
a5432f99f2d9
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3468
diff
changeset
|
363 |
skipcategories=('addrelated', 'siteactions', 'useractions', 'footer')): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
364 |
return [(a.__regid__, a.__class__) |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2793
diff
changeset
|
365 |
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
|
366 |
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
|
367 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
368 |
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
|
369 |
return [(a.__regid__, a.__class__) |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2793
diff
changeset
|
370 |
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
|
371 |
if a.category in categories] |
0 | 372 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
373 |
def pactionsdict(self, req, rset, |
3589
a5432f99f2d9
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3468
diff
changeset
|
374 |
skipcategories=('addrelated', 'siteactions', 'useractions', 'footer')): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
375 |
res = {} |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2793
diff
changeset
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
|
3230 | 381 |
def action_submenu(self, req, rset, id): |
382 |
return self._test_action(self.vreg['actions'].select(id, req, rset=rset)) |
|
383 |
||
384 |
def _test_action(self, action): |
|
385 |
class fake_menu(list): |
|
386 |
@property |
|
387 |
def items(self): |
|
388 |
return self |
|
389 |
class fake_box(object): |
|
390 |
def mk_action(self, label, url, **kwargs): |
|
391 |
return (label, url) |
|
392 |
def box_action(self, action, **kwargs): |
|
393 |
return (action.title, action.url()) |
|
394 |
submenu = fake_menu() |
|
395 |
action.fill_menu(fake_box(), submenu) |
|
396 |
return submenu |
|
0 | 397 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
398 |
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
|
399 |
"""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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
407 |
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
|
408 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
409 |
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
|
410 |
if view.category != 'startupview' |
3454
ad1cddc06997
[testlib] added some new required attributes on FakeRequest, fix dummy NameError
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
411 |
and not issubclass(view, notification.NotificationView)] |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
412 |
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
|
413 |
try: |
2774 | 414 |
view = viewsvreg._select_best(views, 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
|
415 |
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
|
416 |
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
|
417 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
418 |
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
|
419 |
# 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
|
420 |
# 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
|
421 |
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
|
422 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
423 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
424 |
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
|
425 |
"""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
|
426 |
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
|
427 |
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
|
428 |
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
|
429 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
430 |
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
|
431 |
"""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
|
432 |
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
|
433 |
for box in self.vreg['boxes'].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
|
434 |
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
|
435 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
436 |
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
|
437 |
"""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
|
438 |
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
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
443 |
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
|
444 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
445 |
# 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
|
446 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
447 |
@property |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
448 |
@cached |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
449 |
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
|
450 |
"""return a cubicweb publisher""" |
4137
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
451 |
publisher = application.CubicWebPublisher(self.config, vreg=self.vreg) |
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
452 |
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
|
453 |
raise |
3a2d6c38bcd9
override publisher's error handler to ease debugging
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
454 |
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
|
455 |
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
|
456 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
457 |
requestcls = fake.FakeRequest |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
458 |
def request(self, *args, **kwargs): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
459 |
"""return a web ui request""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
460 |
req = self.requestcls(self.vreg, form=kwargs) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
461 |
req.set_connection(self.cnx) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
462 |
return req |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
463 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
464 |
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
|
465 |
"""remote json call simulation""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
466 |
dump = simplejson.dumps |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
467 |
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
|
468 |
req = self.request(fname=fname, pageid='123', arg=args) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
469 |
ctrl = self.vreg['controllers'].select('json', req) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
470 |
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
|
471 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
472 |
def app_publish(self, req, path='view'): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
473 |
return self.app.publish(path, req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
474 |
|
4138
d087a3a3b16f
clearer api: distinguish app_publish / ctrl_publish
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4137
diff
changeset
|
475 |
def ctrl_publish(self, 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
|
476 |
"""call the publish method of the edit controller""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
477 |
ctrl = self.vreg['controllers'].select('edit', req) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
478 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
479 |
result = ctrl.publish() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
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
|
483 |
raise |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
484 |
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
|
485 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
486 |
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
|
487 |
"""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
|
488 |
Redirect exception |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
489 |
""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
490 |
try: |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
491 |
res = callback(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
492 |
except Redirect, ex: |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
493 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
494 |
path, params = ex.location.split('?', 1) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
495 |
except ValueError: |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
496 |
path = ex.location |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
497 |
params = {} |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
498 |
else: |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
499 |
cleanup = lambda p: (p[0], unquote(p[1])) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
500 |
params = dict(cleanup(p.split('=', 1)) for p in params.split('&') if p) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
501 |
path = path[len(req.base_url()):] |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
502 |
return path, params |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
503 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
504 |
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
|
505 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
506 |
def expect_redirect_publish(self, req, path='view'): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
507 |
"""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
|
508 |
get a Redirect exception |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
509 |
""" |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4053
diff
changeset
|
510 |
return self.expect_redirect(lambda x: self.app_publish(x, path), req) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
511 |
|
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
512 |
def init_authentication(self, authmode, anonuser=None): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
513 |
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
|
514 |
self.set_option('anonymous-user', anonuser) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
515 |
req = self.request() |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
516 |
origcnx = req.cnx |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
517 |
req.cnx = None |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
518 |
sh = self.app.session_handler |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
519 |
authm = sh.session_manager.authmanager |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
520 |
authm.authinforetreivers[-1].anoninfo = self.vreg.config.anonymous_user() |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
521 |
# not properly cleaned between tests |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
522 |
self.open_sessions = sh.session_manager._sessions = {} |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
523 |
return req, origcnx |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
524 |
|
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
525 |
def assertAuthSuccess(self, req, origcnx, nbsessions=1): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
526 |
sh = self.app.session_handler |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
527 |
path, params = self.expect_redirect(lambda x: self.app.connect(x), req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
528 |
cnx = req.cnx |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
529 |
self.assertEquals(len(self.open_sessions), nbsessions, self.open_sessions) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
530 |
self.assertEquals(cnx.login, origcnx.login) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
531 |
self.assertEquals(cnx.anonymous_connection, False) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
532 |
self.assertEquals(path, 'view') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
533 |
self.assertEquals(params, {'__message': 'welcome %s !' % cnx.user().login}) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
534 |
|
3676
fa170564e1a0
optional nbsessions arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3657
diff
changeset
|
535 |
def assertAuthFailure(self, req, nbsessions=0): |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
536 |
self.assertRaises(AuthenticationError, self.app.connect, req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
537 |
self.assertEquals(req.cnx, None) |
3676
fa170564e1a0
optional nbsessions arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3657
diff
changeset
|
538 |
self.assertEquals(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
|
539 |
clear_cache(req, 'get_authorization') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3647
diff
changeset
|
540 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
541 |
# content validation ####################################################### |
0 | 542 |
|
543 |
# validators are used to validate (XML, DTD, whatever) view's content |
|
544 |
# validators availables are : |
|
545 |
# DTDValidator : validates XML + declared DTD |
|
546 |
# SaxOnlyValidator : guarantees XML is well formed |
|
547 |
# None : do not try to validate anything |
|
548 |
# 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
|
549 |
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
|
550 |
# 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
|
551 |
# |
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
|
552 |
# 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
|
553 |
# 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
|
554 |
#'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
|
555 |
#'application/xhtml+xml': DTDValidator, |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
556 |
'application/xml': htmlparser.SaxOnlyValidator, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
557 |
'text/xml': htmlparser.SaxOnlyValidator, |
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
|
558 |
'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
|
559 |
'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
|
560 |
'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
|
561 |
'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
|
562 |
'application/json': 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
|
563 |
'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
|
564 |
} |
562
bdadb26c4a3c
old .validators attribute is now .vid_validators
sylvain.thenault@logilab.fr
parents:
549
diff
changeset
|
565 |
# 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
|
566 |
vid_validators = dict((vid, htmlparser.VALMAP[valkey]) |
562
bdadb26c4a3c
old .validators attribute is now .vid_validators
sylvain.thenault@logilab.fr
parents:
549
diff
changeset
|
567 |
for vid, valkey in VIEW_VALIDATORS.iteritems()) |
1605 | 568 |
|
0 | 569 |
|
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
|
570 |
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
|
571 |
**kwargs): |
0 | 572 |
"""This method tests the view `vid` on `rset` using `template` |
573 |
||
574 |
If no error occured while rendering the view, the HTML is analyzed |
|
575 |
and parsed. |
|
576 |
||
577 |
:returns: an instance of `cubicweb.devtools.htmlparser.PageInfo` |
|
578 |
encapsulation the generated HTML |
|
579 |
""" |
|
1142 | 580 |
req = req or rset and rset.req or self.request() |
0 | 581 |
req.form['vid'] = vid |
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
|
582 |
kwargs['rset'] = rset |
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
|
583 |
viewsreg = self.vreg['views'] |
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
|
584 |
view = viewsreg.select(vid, req, **kwargs) |
0 | 585 |
# set explicit test description |
586 |
if rset is not None: |
|
2070 | 587 |
self.set_description("testing %s, mod=%s (%s)" % ( |
588 |
vid, view.__module__, rset.printable_rql())) |
|
0 | 589 |
else: |
2070 | 590 |
self.set_description("testing %s, mod=%s (no rset)" % ( |
591 |
vid, view.__module__)) |
|
0 | 592 |
if template is None: # raw view testing, no template |
1773 | 593 |
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
|
594 |
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
|
595 |
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
|
596 |
templateview = viewsreg.select(template, req, **kwargs) |
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
|
597 |
viewfunc = lambda **k: viewsreg.main_template(req, template, |
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
|
598 |
**kwargs) |
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
|
599 |
kwargs.pop('rset') |
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
|
600 |
return self._test_view(viewfunc, view, template, kwargs) |
0 | 601 |
|
602 |
||
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
|
603 |
def _test_view(self, viewfunc, view, template='main-template', kwargs={}): |
0 | 604 |
"""this method does the actual call to the view |
605 |
||
606 |
If no error occured while rendering the view, the HTML is analyzed |
|
607 |
and parsed. |
|
608 |
||
609 |
:returns: an instance of `cubicweb.devtools.htmlparser.PageInfo` |
|
610 |
encapsulation the generated HTML |
|
611 |
""" |
|
612 |
output = None |
|
613 |
try: |
|
614 |
output = viewfunc(**kwargs) |
|
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
|
615 |
return self._check_html(output, view, template) |
0 | 616 |
except (SystemExit, KeyboardInterrupt): |
617 |
raise |
|
618 |
except: |
|
619 |
# hijack exception: generative tests stop when the exception |
|
620 |
# is not an AssertionError |
|
621 |
klass, exc, tcbk = sys.exc_info() |
|
622 |
try: |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
623 |
msg = '[%s in %s] %s' % (klass, view.__regid__, exc) |
0 | 624 |
except: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
625 |
msg = '[%s in %s] undisplayable exception' % (klass, view.__regid__) |
0 | 626 |
if output is not None: |
627 |
position = getattr(exc, "position", (0,))[0] |
|
628 |
if position: |
|
629 |
# define filter |
|
630 |
output = output.splitlines() |
|
631 |
width = int(log(len(output), 10)) + 1 |
|
632 |
line_template = " %" + ("%i" % width) + "i: %s" |
|
633 |
# XXX no need to iterate the whole file except to get |
|
634 |
# the line number |
|
635 |
output = '\n'.join(line_template % (idx + 1, line) |
|
636 |
for idx, line in enumerate(output) |
|
637 |
if line_context_filter(idx+1, position)) |
|
1133 | 638 |
msg += '\nfor output:\n%s' % output |
0 | 639 |
raise AssertionError, msg, tcbk |
640 |
||
427
e894eec21a1b
move selection of entity types to test in a method to ease overriding
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
641 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
642 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
643 |
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
|
644 |
"""raises an exception if the HTML is invalid""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
645 |
try: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
646 |
validatorclass = self.vid_validators[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
|
647 |
except KeyError: |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
648 |
if view.content_type in ('text/html', 'application/xhtml+xml'): |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
649 |
if template is None: |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
650 |
default_validator = htmlparser.HTMLValidator |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
651 |
else: |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
652 |
default_validator = htmlparser.DTDValidator |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
653 |
else: |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
654 |
default_validator = 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
|
655 |
validatorclass = self.content_type_validators.get(view.content_type, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
656 |
default_validator) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
657 |
if validatorclass 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
|
658 |
return None |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
659 |
validator = validatorclass() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
660 |
return validator.parse_string(output.strip()) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
661 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
662 |
# deprecated ############################################################### |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
663 |
|
4016
250784a2d105
deprecated one more custom add_entity in favor of req.create_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
664 |
@deprecated('[3.6] use self.request().create_entity(...)') |
250784a2d105
deprecated one more custom add_entity in favor of req.create_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
665 |
def add_entity(self, etype, req=None, **kwargs): |
250784a2d105
deprecated one more custom add_entity in favor of req.create_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
666 |
if req is None: |
250784a2d105
deprecated one more custom add_entity in favor of req.create_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
667 |
req = self.request() |
250784a2d105
deprecated one more custom add_entity in favor of req.create_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
668 |
return req.create_entity(etype, **kwargs) |
250784a2d105
deprecated one more custom add_entity in favor of req.create_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
669 |
|
2793
bfb21f7a0d13
R put version info in deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2774
diff
changeset
|
670 |
@deprecated('[3.4] use self.vreg["etypes"].etype_class(etype)(self.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
|
671 |
def etype_instance(self, etype, 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
|
672 |
req = req or 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
|
673 |
e = self.vreg['etypes'].etype_class(etype)(req) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
674 |
e.eid = None |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
675 |
return e |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
676 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
677 |
@nocoverage |
2793
bfb21f7a0d13
R put version info in deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2774
diff
changeset
|
678 |
@deprecated('[3.4] use req = self.request(); rset = req.execute()') |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
679 |
def rset_and_req(self, rql, optional_args=None, args=None, eidkey=None): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
680 |
"""executes <rql>, builds a resultset, and returns a |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
681 |
couple (rset, req) where req is a FakeRequest |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
682 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
683 |
return (self.execute(rql, args, eidkey), |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
684 |
self.request(rql=rql, **optional_args or {})) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
685 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
686 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
687 |
# 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
|
688 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
689 |
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
|
690 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
691 |
def how_many_dict(schema, cursor, how_many, skip): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
692 |
"""compute how many entities by type we need to be able to satisfy relations |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
693 |
cardinality |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
694 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
695 |
# compute how many entities by type we need to be able to satisfy relation constraint |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
696 |
relmap = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
697 |
for rschema in schema.relations(): |
3720 | 698 |
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
|
699 |
continue |
4053
7cc66b1d9183
more api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4036
diff
changeset
|
700 |
for subj, obj in rschema.rdefs: |
7cc66b1d9183
more api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4036
diff
changeset
|
701 |
card = rschema.rdef(subj, obj).cardinality |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
702 |
if card[0] in '1?' and len(rschema.subjects(obj)) == 1: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
703 |
relmap.setdefault((rschema, subj), []).append(str(obj)) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
704 |
if card[1] in '1?' and len(rschema.objects(subj)) == 1: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
705 |
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
|
706 |
unprotected = unprotected_entities(schema) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
707 |
for etype in skip: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
708 |
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
|
709 |
howmanydict = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
710 |
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
|
711 |
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
|
712 |
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
|
713 |
howmanydict[str(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
|
714 |
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
|
715 |
# XXX should 1. check no cycle 2. propagate changes |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
720 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
721 |
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
|
722 |
"""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
|
723 |
__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
|
724 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
725 |
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
|
726 |
# 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
|
727 |
# 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
|
728 |
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
|
729 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
730 |
no_auto_populate = () |
3734
b2107f68176c
ignored_relations should be a set
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
731 |
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
|
732 |
|
427
e894eec21a1b
move selection of entity types to test in a method to ease overriding
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
733 |
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
|
734 |
return unprotected_entities(self.schema, strict=True) |
1605 | 735 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
736 |
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
|
737 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
738 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
739 |
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
|
740 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
741 |
|
3720 | 742 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
743 |
@nocoverage |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
744 |
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
|
745 |
"""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
|
746 |
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
|
747 |
""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
748 |
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
|
749 |
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
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
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
|
754 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
755 |
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
|
756 |
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
|
757 |
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
|
758 |
edict = {} |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
759 |
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
|
760 |
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
|
761 |
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
|
762 |
existingrels = {} |
4036
137be4878127
[mq]: fix_set_addition
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
4016
diff
changeset
|
763 |
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
|
764 |
for rschema in self.schema.relations(): |
3720 | 765 |
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
|
766 |
continue |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
767 |
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
|
768 |
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
|
769 |
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
|
770 |
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
|
771 |
for rql, args in q: |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
772 |
try: |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
773 |
cu.execute(rql, args) |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
774 |
except ValidationError, ex: |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
775 |
# failed to satisfy some constraint |
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
776 |
print 'error in automatic db population', ex |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
777 |
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
|
778 |
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
|
779 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
780 |
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
|
781 |
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
|
782 |
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
|
783 |
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
|
784 |
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
|
785 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
786 |
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
|
787 |
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
|
788 |
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
|
789 |
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
|
790 |
break |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
791 |
# 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
|
792 |
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
|
793 |
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
|
794 |
|
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
795 |
def iter_automatic_rsets(self, limit=10): |
0 | 796 |
"""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
|
797 |
etypes = self.to_test_etypes() |
2219
bb5098e74b82
protect against empty etypes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2070
diff
changeset
|
798 |
if not etypes: |
bb5098e74b82
protect against empty etypes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2070
diff
changeset
|
799 |
return |
0 | 800 |
for etype in etypes: |
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
801 |
yield self.execute('Any X LIMIT %s WHERE X is %s' % (limit, etype)) |
0 | 802 |
etype1 = etypes.pop() |
1775
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
803 |
try: |
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
804 |
etype2 = etypes.pop() |
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
805 |
except KeyError: |
f450f1594992
fix in case only one type is tested
sylvain.thenault@logilab.fr
parents:
1773
diff
changeset
|
806 |
etype2 = etype1 |
0 | 807 |
# test a mixed query (DISTINCT/GROUP to avoid getting duplicate |
808 |
# X which make muledit view failing for instance (html validation fails |
|
809 |
# because of some duplicate "id" attributes) |
|
810 |
yield self.execute('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is %s, Y is %s' % (etype1, etype2)) |
|
811 |
# test some application-specific queries if defined |
|
812 |
for rql in self.application_rql: |
|
813 |
yield self.execute(rql) |
|
814 |
||
815 |
def _test_everything_for(self, rset): |
|
816 |
"""this method tries to find everything that can be tested |
|
817 |
for `rset` and yields a callable test (as needed in generative tests) |
|
818 |
""" |
|
819 |
propdefs = self.vreg['propertydefs'] |
|
820 |
# make all components visible |
|
821 |
for k, v in propdefs.items(): |
|
822 |
if k.endswith('visible') and not v['default']: |
|
823 |
propdefs[k]['default'] = True |
|
824 |
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
|
825 |
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
|
826 |
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
|
827 |
self.view, view.__regid__, rset, |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
563
diff
changeset
|
828 |
rset.req.reset_headers(), 'main-template') |
0 | 829 |
# We have to do this because some views modify the |
830 |
# resultset's syntax tree |
|
831 |
rset = backup_rset |
|
832 |
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
|
833 |
yield InnerTest(self._testname(rset, action.__regid__, 'action'), self._test_action, action) |
0 | 834 |
for box in self.list_boxes_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
|
835 |
yield InnerTest(self._testname(rset, box.__regid__, 'box'), box.render) |
0 | 836 |
|
837 |
@staticmethod |
|
838 |
def _testname(rset, objid, objtype): |
|
839 |
return '%s_%s_%s' % ('_'.join(rset.column_types(0)), objid, objtype) |
|
1605 | 840 |
|
0 | 841 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
842 |
# 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
|
843 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
844 |
class AutomaticWebTest(AutoPopulateTest): |
0 | 845 |
"""import this if you wan automatic tests to be ran""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
846 |
def setUp(self): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
847 |
AutoPopulateTest.setUp(self) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
848 |
# 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
|
849 |
# 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
|
850 |
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
|
851 |
|
0 | 852 |
## one each |
853 |
def test_one_each_config(self): |
|
854 |
self.auto_populate(1) |
|
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
855 |
for rset in self.iter_automatic_rsets(limit=1): |
0 | 856 |
for testargs in self._test_everything_for(rset): |
857 |
yield testargs |
|
858 |
||
859 |
## ten each |
|
860 |
def test_ten_each_config(self): |
|
861 |
self.auto_populate(10) |
|
1004
625e59773119
fix automatic test: ensure we actually have
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
563
diff
changeset
|
862 |
for rset in self.iter_automatic_rsets(limit=10): |
0 | 863 |
for testargs in self._test_everything_for(rset): |
864 |
yield testargs |
|
1605 | 865 |
|
0 | 866 |
## startup views |
867 |
def test_startup_views(self): |
|
868 |
for vid in self.list_startup_views(): |
|
869 |
req = self.request() |
|
870 |
yield self.view, vid, None, req |
|
871 |
||
872 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
873 |
# registry instrumentization ################################################### |
0 | 874 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
875 |
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
|
876 |
try: |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
877 |
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
|
878 |
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
|
879 |
pass |
1605 | 880 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
881 |
|
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
|
882 |
def vreg_instrumentize(testclass): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
883 |
# XXX broken |
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
|
884 |
from cubicweb.devtools.apptest import TestEnvironment |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
885 |
env = testclass._env = TestEnvironment('data', configcls=testclass.configcls) |
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
|
886 |
for reg in env.vreg.values(): |
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
|
887 |
reg._selected = {} |
2668
979c7ccb4a86
[testlib] take care of re-monkeypatching which'll cause infinite recursion error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
888 |
try: |
979c7ccb4a86
[testlib] take care of re-monkeypatching which'll cause infinite recursion error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
889 |
orig_select_best = reg.__class__.__orig_select_best |
979c7ccb4a86
[testlib] take care of re-monkeypatching which'll cause infinite recursion error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
890 |
except: |
2770
356e9d7c356d
R propagate registry API changes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2668
diff
changeset
|
891 |
orig_select_best = reg.__class__._select_best |
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
|
892 |
def instr_select_best(self, *args, **kwargs): |
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
|
893 |
selected = orig_select_best(self, *args, **kwargs) |
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
|
894 |
try: |
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
|
895 |
self._selected[selected.__class__] += 1 |
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
|
896 |
except KeyError: |
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
|
897 |
self._selected[selected.__class__] = 1 |
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
|
898 |
except AttributeError: |
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
|
899 |
pass # occurs on reg used to restore database |
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
|
900 |
return selected |
2770
356e9d7c356d
R propagate registry API changes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2668
diff
changeset
|
901 |
reg.__class__._select_best = instr_select_best |
2668
979c7ccb4a86
[testlib] take care of re-monkeypatching which'll cause infinite recursion error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
902 |
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
|
903 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2668
diff
changeset
|
904 |
|
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
|
905 |
def print_untested_objects(testclass, skipregs=('hooks', 'etypes')): |
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
|
906 |
for regname, reg in testclass._env.vreg.iteritems(): |
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
|
907 |
if regname in skipregs: |
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
|
908 |
continue |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
909 |
for appobjects in reg.itervalues(): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
910 |
for appobject in appobjects: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
911 |
if not reg._selected.get(appobject): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
912 |
print 'not tested', regname, appobject |