Revision 1808f7bc snf-astakos-app/astakos/im/tests/common.py
b/snf-astakos-app/astakos/im/tests/common.py | ||
---|---|---|
1 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
1 |
# Copyright 2011, 2012, 2013 GRNET S.A. All rights reserved.
|
|
2 | 2 |
# |
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
... | ... | |
54 | 54 |
from astakos.im import settings as astakos_settings |
55 | 55 |
from astakos.im import forms |
56 | 56 |
from astakos.im import activation_backends |
57 |
from astakos.im import auth as auth_functions |
|
57 | 58 |
|
58 | 59 |
from urllib import quote |
59 | 60 |
from datetime import timedelta |
... | ... | |
145 | 146 |
|
146 | 147 |
|
147 | 148 |
def get_local_user(username, **kwargs): |
148 |
try: |
|
149 |
return AstakosUser.objects.get(email=username) |
|
150 |
except: |
|
151 |
user_params = { |
|
152 |
'username': username, |
|
153 |
'email': username, |
|
154 |
'is_active': True, |
|
155 |
'activation_sent': datetime.now(), |
|
156 |
'has_signed_terms': True, |
|
157 |
'date_signed_terms': datetime.now(), |
|
158 |
'email_verified': True |
|
159 |
} |
|
160 |
user_params.update(kwargs) |
|
161 |
user = AstakosUser(**user_params) |
|
162 |
user.set_password(kwargs.get('password', 'password')) |
|
163 |
user.renew_verification_code() |
|
164 |
user.save() |
|
165 |
user.add_auth_provider('local', auth_backend='astakos') |
|
166 |
if kwargs.get('is_active', True): |
|
167 |
user.is_active = True |
|
168 |
else: |
|
169 |
user.is_active = False |
|
170 |
user.save() |
|
171 |
return user |
|
149 |
try: |
|
150 |
return AstakosUser.objects.get(email=username) |
|
151 |
except: |
|
152 |
user = auth_functions.make_local_user(email=username, |
|
153 |
has_signed_terms=True) |
|
154 |
user.set_password(kwargs.pop('password', 'password')) |
|
155 |
|
|
156 |
for key, value in kwargs.iteritems(): |
|
157 |
setattr(user, key, value) |
|
158 |
user.save() |
|
159 |
|
|
160 |
if kwargs.get("is_active", True): |
|
161 |
backend = activation_backends.get_backend() |
|
162 |
backend.verify_user(user, user.verification_code) |
|
163 |
backend.accept_user(user) |
|
164 |
|
|
165 |
return user |
|
172 | 166 |
|
173 | 167 |
|
174 | 168 |
def get_mailbox(email): |
Also available in: Unified diff