|
a/AlluraTesting/alluratest/controller.py |
|
b/AlluraTesting/alluratest/controller.py |
1 |
"""Unit and functional test suite for allura."""
|
1 |
"""Unit and functional test suite for allura."""
|
2 |
import os
|
2 |
import os
|
3 |
import urllib
|
3 |
import urllib
|
4 |
|
4 |
|
|
|
5 |
from formencode import variabledecode
|
5 |
import mock
|
6 |
import mock
|
6 |
import beaker.session
|
7 |
import beaker.session
|
7 |
from paste.deploy import loadapp
|
8 |
from paste.deploy import loadapp
|
8 |
from paste.script.appinstall import SetupCommand
|
9 |
from paste.script.appinstall import SetupCommand
|
9 |
from pylons import c, g, h, url, request, response, session
|
10 |
from pylons import c, g, h, url, request, response, session
|
10 |
import tg
|
11 |
import tg
|
11 |
from webtest import TestApp
|
12 |
from webtest import TestApp
|
12 |
from webob import Request, Response
|
13 |
from webob import Request, Response
|
13 |
import ew
|
14 |
import ew
|
14 |
from ming.orm import ThreadLocalORMSession
|
15 |
from ming.orm import ThreadLocalORMSession
|
|
|
16 |
import ming.orm
|
15 |
|
17 |
|
16 |
from allura import model as M
|
18 |
from allura import model as M
|
17 |
from allura.lib.app_globals import Globals
|
19 |
from allura.lib.app_globals import Globals
|
18 |
from allura.lib.custom_middleware import environ as ENV, MagicalC
|
20 |
from allura.lib.custom_middleware import environ as ENV, MagicalC
|
|
|
21 |
from .validation import ValidatingTestApp
|
19 |
|
22 |
|
20 |
from .validation import ValidatingTestApp
|
|
|
21 |
|
23 |
|
22 |
DFL_APP_NAME = 'main_without_authn'
|
24 |
DFL_APP_NAME = 'main_without_authn'
|
23 |
|
25 |
|
24 |
def get_config_file(config=None):
|
26 |
def get_config_file(config=None):
|
25 |
if not config:
|
27 |
if not config:
|
|
... |
|
... |
90 |
pass
|
92 |
pass
|
91 |
|
93 |
|
92 |
def webflash(self, response):
|
94 |
def webflash(self, response):
|
93 |
"Extract webflash content from response."
|
95 |
"Extract webflash content from response."
|
94 |
return urllib.unquote(response.cookies_set.get('webflash', ''))
|
96 |
return urllib.unquote(response.cookies_set.get('webflash', ''))
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
class TestRestApiBase(TestController):
|
|
|
100 |
|
|
|
101 |
def setUp(self):
|
|
|
102 |
super(TestRestApiBase, self).setUp()
|
|
|
103 |
setup_global_objects()
|
|
|
104 |
# h.set_context('test', 'home')
|
|
|
105 |
user = M.User.query.get(username='test-admin')
|
|
|
106 |
self.token = M.ApiToken(user_id=user._id)
|
|
|
107 |
ming.orm.session(self.token).flush()
|
|
|
108 |
|
|
|
109 |
def api_post(self, path, api_key=None, api_timestamp=None, api_signature=None,
|
|
|
110 |
**params):
|
|
|
111 |
params = variabledecode.variable_encode(params, add_repetitions=False)
|
|
|
112 |
if api_key: params['api_key'] = api_key
|
|
|
113 |
if api_timestamp: params['api_timestamp'] = api_timestamp
|
|
|
114 |
if api_signature: params['api_signature'] = api_signature
|
|
|
115 |
params = self.token.sign_request(path, params)
|
|
|
116 |
response = self.app.post(
|
|
|
117 |
str(path),
|
|
|
118 |
params=params,
|
|
|
119 |
status=[200, 302, 400, 403, 404])
|
|
|
120 |
if response.status_int == 302:
|
|
|
121 |
return response.follow()
|
|
|
122 |
else:
|
|
|
123 |
return response
|