0001-allow-override-of-app-s-settings-19763.patch
mandayejs/applications.py | ||
---|---|---|
29 | 29 |
def get_app_settings(): |
30 | 30 |
module_name, app_settings = tuple(settings.SITE_APP.rsplit('.', 1)) |
31 | 31 |
module = import_module(module_name) |
32 |
return getattr(module, app_settings) |
|
32 |
return getattr(module, app_settings)()
|
|
33 | 33 | |
34 | 34 | |
35 | 35 |
def app_web_services(request, path): |
... | ... | |
63 | 63 |
'one of these settings ({}) must be defined' |
64 | 64 |
.format(('SITE_FORCE_REDIRECT_URL', 'SITE_FORCE_REDIRECT_LOCATOR'))) |
65 | 65 | |
66 |
# Script asserting phantomjs authentication |
|
67 |
dct['SITE_AUTH_CHECKER'] = os.path.join(settings.STATIC_ROOT, dct['SITE_AUTH_CHECKER']) |
|
68 | ||
69 | 66 |
# Default form submit element |
70 | 67 |
if not dct.get('SITE_FORM_SUBMIT_ELEMENT', None): |
71 | 68 |
dct['SITE_FORM_SUBMIT_ELEMENT'] = 'input[type=submit], button' |
72 | 69 | |
73 |
if dct.get('SITE_LOGIN_PATH_PREFIX', None): |
|
74 |
parent = bases[0] |
|
75 |
dct['SITE_LOGIN_PATH'] = os.path.join(dct['SITE_LOGIN_PATH_PREFIX'], parent.SITE_LOGIN_PATH.strip('/')) |
|
76 | 70 |
return super(AppSettingsMeta, cls).__new__(cls, name, bases, dct) |
77 | 71 | |
78 | 72 | |
79 | 73 |
class AppSettings(object): |
80 | 74 |
__metaclass__ = AppSettingsMeta |
81 | 75 | |
76 |
def __getattribute__(self, name): |
|
77 |
value = getattr(settings, name, None) |
|
78 |
if value is not None: |
|
79 |
return value |
|
80 |
return super(AppSettings, self).__getattribute__(name) |
|
81 | ||
82 | 82 | |
83 | 83 |
# Test App Settings |
84 | 84 |
class Test(AppSettings): |
... | ... | |
228 | 228 |
SITE_LOGOUT_LOCATOR = '#espace-login form input[type=submit]' |
229 | 229 | |
230 | 230 | |
231 |
class ArpegeVincennesTest(Arpege): |
|
232 |
SITE_LOGIN_PATH = '/vincennes-test/index.do' |
|
233 | ||
234 | ||
235 | 231 |
class Imuse(AppSettings): |
236 | 232 |
SITE_LOGIN_PATH = 'extranet/login/gen_index_groupe.php?nav=autre' |
237 | 233 | |
... | ... | |
265 | 261 |
SITE_FORM_SUBMIT_ELEMENT = '#INDEX_BT_LOGIN' |
266 | 262 | |
267 | 263 | |
268 |
class ImuseTeacher(Imuse): |
|
269 |
SITE_LOGIN_PATH = '/extranet/login/ens_index_enseignant.php' |
|
270 | ||
271 | ||
272 |
class ImuseFamily(Imuse): |
|
273 |
SITE_LOGIN_PATH = '/extranet/login/usa_index_famille.php' |
|
274 | ||
275 |
SITE_LOGOUT_LOCATOR = '#MENU_FAMILLE_QUITTER' |
|
276 | ||
277 | ||
278 |
class ImuseFamilyMontpellier(ImuseFamily): |
|
279 |
SITE_LOGIN_PATH_PREFIX = '/montpellier/' |
|
280 | ||
281 | ||
282 | 264 |
class Sezhame(AppSettings): |
283 | 265 |
SITE_LOGIN_PATH = '/sezhame/page/connexion-abonne?destination=user' |
284 | 266 | |
... | ... | |
344 | 326 |
SITE_FORCE_REDIRECT_LOCATOR = '#loginForm' |
345 | 327 | |
346 | 328 |
SITE_LOGOUT_LOCATOR = ".infoUtilisateur[alt=Deconnexion]" |
347 | ||
348 | ||
349 |
class TeamnetMeyzieu(Teamnet): |
|
350 |
SITE_LOGIN_PATH_PREFIX = '/meyzieu/' |
mandayejs/mandaye/utils.py | ||
---|---|---|
133 | 133 |
"""Returns phantomjs login prerequis |
134 | 134 |
""" |
135 | 135 |
app_settings = get_app_settings() |
136 | ||
136 |
auth_checker = os.path.join( |
|
137 |
settings.STATIC_ROOT, app_settings.SITE_AUTH_CHECKER) |
|
137 | 138 |
return { |
138 | 139 |
'address': request.build_absolute_uri(app_settings.SITE_LOGIN_PATH), |
139 | 140 |
'cookies': [], |
140 | 141 |
'locators': [credentials.to_login_info()], |
141 |
'auth_checker': app_settings.SITE_AUTH_CHECKER,
|
|
142 |
'auth_checker': auth_checker,
|
|
142 | 143 |
'form_submit_element': app_settings.SITE_FORM_SUBMIT_ELEMENT |
143 | 144 |
} |
144 | 145 |
tests/test_mandayejs.py | ||
---|---|---|
3 | 3 |
import json |
4 | 4 |
import time |
5 | 5 |
import mock |
6 |
import os |
|
6 | 7 |
import pytest |
7 | 8 | |
8 | 9 |
from django.conf import settings |
... | ... | |
13 | 14 |
from django.core.urlresolvers import reverse |
14 | 15 | |
15 | 16 |
from mandayejs.mandaye.models import UserCredentials |
16 |
from mandayejs.mandaye.utils import exec_phantom |
|
17 |
from mandayejs.mandaye.utils import exec_phantom, get_login_info
|
|
17 | 18 |
from mandayejs.mandaye.forms import FormFactory |
18 | 19 |
from mandayejs.mandaye.views import post_login_do |
19 | 20 | |
... | ... | |
409 | 410 |
request.user = user_john |
410 | 411 |
response = post_login_do(request) |
411 | 412 |
assert 'window.top.location = "http://example.net/"' in response.content |
413 | ||
414 | ||
415 |
@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS) |
|
416 |
def test_app_settings_overriding(settings, cred_john): |
|
417 |
request = RequestFactory().get('/') |
|
418 |
data = get_login_info(request, cred_john) |
|
419 |
assert data['address'] == 'http://testserver/' |
|
420 |
assert data['auth_checker'] == os.path.join(settings.STATIC_ROOT, 'js/test/auth.checker.js') |
|
421 |
assert data['form_submit_element'] == 'input[type=submit], button' |
|
422 |
# when overriding settings |
|
423 |
settings.SITE_LOGIN_PATH = 'account/login' |
|
424 |
settings.SITE_AUTH_CHECKER = 'js/global.auth.checker.js' |
|
425 |
settings.SITE_FORM_SUBMIT_ELEMENT = 'button' |
|
426 |
data = get_login_info(request, cred_john) |
|
427 |
assert data['address'] == 'http://testserver/account/login' |
|
428 |
assert data['auth_checker'] == os.path.join(settings.STATIC_ROOT, 'js/global.auth.checker.js') |
|
429 |
assert data['form_submit_element'] == 'button' |
|
430 |
settings.SITE_LOGIN_PATH = '' |
|
431 |
settings.SITE_FORM_SUBMIT_ELEMENT = '' |
|
432 |
data = get_login_info(request, cred_john) |
|
433 |
assert data['address'] == 'http://testserver/' |
|
434 |
assert data['form_submit_element'] == '' |
|
412 |
- |