Révision 3cae8f26
Ajouté par Frédéric Péters il y a plus de 6 ans
tests/utilities.py | ||
---|---|---|
3 | 3 |
import tempfile |
4 | 4 |
|
5 | 5 |
from webtest import TestApp |
6 |
from quixote.wsgi import QWIP |
|
6 |
from quixote import cleanup, get_publisher |
|
7 |
from django.conf import settings |
|
7 | 8 |
|
8 | 9 |
from qommon.publisher import set_publisher_class |
9 | 10 |
import wcs |
10 |
import publisher
|
|
11 |
import wcs.wsgi
|
|
11 | 12 |
from wcs.qommon.http_request import HTTPRequest |
13 |
from wcs import publisher, compat |
|
12 | 14 |
|
13 |
QWIP.request_class = HTTPRequest |
|
15 |
import wcs.middleware |
|
16 |
|
|
17 |
wcs.middleware.AfterJobsMiddleware.ASYNC = False |
|
14 | 18 |
|
15 | 19 |
def create_temporary_pub(): |
16 | 20 |
config = ConfigParser.ConfigParser() |
17 | 21 |
APP_DIR = tempfile.mkdtemp() |
18 |
set_publisher_class(publisher.WcsPublisher) |
|
19 |
publisher.WcsPublisher.APP_DIR = APP_DIR |
|
20 |
publisher.WcsPublisher.DATA_DIR = os.path.abspath( |
|
22 |
compat.CompatWcsPublisher.APP_DIR = APP_DIR |
|
23 |
compat.CompatWcsPublisher.DATA_DIR = os.path.abspath( |
|
21 | 24 |
os.path.join(os.path.dirname(wcs.__file__), '..', 'data')) |
25 |
compat.CompatWcsPublisher.cronjobs = None |
|
22 | 26 |
config.add_section('extra') |
23 | 27 |
config.set('extra', 'auquotidien', os.path.join(os.path.dirname(__file__), '..', 'auquotidien')) |
24 |
publisher.WcsPublisher.configure(config) |
|
25 |
pub = publisher.WcsPublisher.create_publisher() |
|
28 |
compat.CompatWcsPublisher._initialized = False |
|
29 |
compat.CompatWcsPublisher.configure(config) |
|
30 |
compat.CompatWcsPublisher.init_publisher_class() |
|
31 |
pub = compat.CompatWcsPublisher.create_publisher() |
|
26 | 32 |
# allow saving the user |
27 | 33 |
pub.app_dir = os.path.join(APP_DIR, 'example.net') |
28 | 34 |
os.mkdir(pub.app_dir) |
29 | 35 |
return pub |
30 | 36 |
|
31 |
def get_app(pub): |
|
32 |
return TestApp(QWIP(pub), extra_environ={'HTTP_HOST': 'example.net'}) |
|
37 |
def get_app(pub, https=False): |
|
38 |
extra_environ = {'HTTP_HOST': 'example.net', 'REMOTE_ADDR': '127.0.0.1'} |
|
39 |
if https: |
|
40 |
settings.SECURE_PROXY_SSL_HEADER = ('HTTPS', 'on') |
|
41 |
extra_environ['HTTPS'] = 'on' |
|
42 |
else: |
|
43 |
extra_environ['HTTPS'] = 'off' |
|
44 |
return TestApp(wcs.wsgi.application, extra_environ=extra_environ) |
|
33 | 45 |
|
34 | 46 |
def login(app, username='admin', password='admin'): |
35 | 47 |
login_page = app.get('/login/') |
Formats disponibles : Unified diff
tests: adapt initialization after django switch