1
from ..strategy import BaseStrategy, BaseTemplateStrategy
4
TEST_URI = 'http://myapp.com'
5
TEST_HOST = 'myapp.com'
8
class Redirect(object):
9
def __init__(self, url):
13
class TestTemplateStrategy(BaseTemplateStrategy):
14
def render_template(self, tpl, context):
17
def render_string(self, html, context):
21
class TestStrategy(BaseStrategy):
22
DEFAULT_TEMPLATE_STRATEGY = TestTemplateStrategy
24
def __init__(self, storage, tpl=None):
25
self._request_data = {}
28
super(TestStrategy, self).__init__(storage, tpl)
30
def redirect(self, url):
33
def get_setting(self, name):
34
"""Return value for given setting name"""
35
return self._settings[name]
37
def html(self, content):
38
"""Return HTTP response with given content"""
41
def render_html(self, tpl=None, html=None, context=None):
42
"""Render given template or raw html with given context"""
45
def request_data(self, merge=True):
46
"""Return current request data (POST or GET)"""
47
return self._request_data
49
def request_host(self):
50
"""Return current host value"""
53
def request_is_secure(self):
54
""" Is the request using HTTPS? """
57
def request_path(self):
58
""" path of the current request """
61
def request_port(self):
62
""" Port in use for this request """
65
def request_get(self):
66
""" Request GET data """
67
return self._request_data.copy()
69
def request_post(self):
70
""" Request POST data """
71
return self._request_data.copy()
73
def session_get(self, name, default=None):
74
"""Return session value for given key"""
75
return self._session.get(name, default)
77
def session_set(self, name, value):
78
"""Set session value for given key"""
79
self._session[name] = value
81
def session_pop(self, name):
82
"""Pop session value for given key"""
83
return self._session.pop(name, None)
85
def build_absolute_uri(self, path=None):
86
"""Build absolute URI with given (optional) path"""
88
if path.startswith('http://') or path.startswith('https://'):
90
return TEST_URI + path
92
def set_settings(self, values):
93
self._settings.update(values)
95
def set_request_data(self, values, backend):
96
self._request_data.update(values)
97
backend.data = self._request_data
99
def remove_from_request_data(self, name):
100
self._request_data.pop(name, None)
102
def authenticate(self, *args, **kwargs):
103
user = super(TestStrategy, self).authenticate(*args, **kwargs)
104
if isinstance(user, self.storage.user.user_model()):
105
self.session_set('username', user.username)
108
def get_pipeline(self, backend=None):
112
'social_core.pipeline.social_auth.social_details',
113
'social_core.pipeline.social_auth.social_uid',
114
'social_core.pipeline.social_auth.auth_allowed',
115
'social_core.pipeline.social_auth.social_user',
116
'social_core.pipeline.user.get_username',
117
'social_core.pipeline.social_auth.associate_by_email',
118
'social_core.pipeline.user.create_user',
119
'social_core.pipeline.social_auth.associate_user',
120
'social_core.pipeline.social_auth.load_extra_data',
121
'social_core.pipeline.user.user_details'