1
|
import ConfigParser
|
2
|
import os
|
3
|
import tempfile
|
4
|
|
5
|
from webtest import TestApp
|
6
|
from quixote.wsgi import QWIP
|
7
|
|
8
|
from qommon.publisher import set_publisher_class
|
9
|
import wcs
|
10
|
import publisher
|
11
|
from wcs.qommon.http_request import HTTPRequest
|
12
|
|
13
|
QWIP.request_class = HTTPRequest
|
14
|
|
15
|
def create_temporary_pub():
|
16
|
config = ConfigParser.ConfigParser()
|
17
|
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(
|
21
|
os.path.join(os.path.dirname(wcs.__file__), '..', 'data'))
|
22
|
config.add_section('extra')
|
23
|
config.set('extra', 'auquotidien', os.path.join(os.path.dirname(__file__), '..', 'auquotidien'))
|
24
|
publisher.WcsPublisher.configure(config)
|
25
|
pub = publisher.WcsPublisher.create_publisher()
|
26
|
# allow saving the user
|
27
|
pub.app_dir = os.path.join(APP_DIR, 'example.net')
|
28
|
os.mkdir(pub.app_dir)
|
29
|
return pub
|
30
|
|
31
|
def get_app(pub):
|
32
|
return TestApp(QWIP(pub), extra_environ={'HTTP_HOST': 'example.net'})
|
33
|
|
34
|
def login(app, username='admin', password='admin'):
|
35
|
login_page = app.get('/login/')
|
36
|
login_form = login_page.forms['login-form']
|
37
|
login_form['username'] = username
|
38
|
login_form['password'] = password
|
39
|
resp = login_form.submit()
|
40
|
assert resp.status_int == 302
|
41
|
return app
|