1
|
import ConfigParser
|
2
|
import os
|
3
|
import tempfile
|
4
|
|
5
|
from webtest import TestApp
|
6
|
from quixote import cleanup, get_publisher
|
7
|
from django.conf import settings
|
8
|
|
9
|
from qommon.publisher import set_publisher_class
|
10
|
import wcs
|
11
|
import wcs.wsgi
|
12
|
from wcs.qommon.http_request import HTTPRequest
|
13
|
from wcs import publisher, compat
|
14
|
|
15
|
import wcs.middleware
|
16
|
|
17
|
wcs.middleware.AfterJobsMiddleware.ASYNC = False
|
18
|
|
19
|
def create_temporary_pub():
|
20
|
config = ConfigParser.ConfigParser()
|
21
|
APP_DIR = tempfile.mkdtemp()
|
22
|
compat.CompatWcsPublisher.APP_DIR = APP_DIR
|
23
|
compat.CompatWcsPublisher.DATA_DIR = os.path.abspath(
|
24
|
os.path.join(os.path.dirname(wcs.__file__), '..', 'data'))
|
25
|
compat.CompatWcsPublisher.cronjobs = None
|
26
|
config.add_section('extra')
|
27
|
config.set('extra', 'auquotidien', os.path.join(os.path.dirname(__file__), '..', 'auquotidien'))
|
28
|
compat.CompatWcsPublisher._initialized = False
|
29
|
compat.CompatWcsPublisher.configure(config)
|
30
|
compat.CompatWcsPublisher.init_publisher_class()
|
31
|
pub = compat.CompatWcsPublisher.create_publisher()
|
32
|
# allow saving the user
|
33
|
pub.app_dir = os.path.join(APP_DIR, 'example.net')
|
34
|
os.mkdir(pub.app_dir)
|
35
|
return pub
|
36
|
|
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)
|
45
|
|
46
|
def login(app, username='admin', password='admin'):
|
47
|
login_page = app.get('/login/')
|
48
|
login_form = login_page.forms['login-form']
|
49
|
login_form['username'] = username
|
50
|
login_form['password'] = password
|
51
|
resp = login_form.submit()
|
52
|
assert resp.status_int == 302
|
53
|
return app
|