Improve users management on kfet TestCase, and Py34 compat

This commit is contained in:
Aurélien Delobelle 2017-09-01 16:37:14 +02:00
parent 997b63d6b6
commit af97c0cda6
2 changed files with 64 additions and 62 deletions

View file

@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse
from django.http import QueryDict
from django.test import Client
from django.utils import timezone
from django.utils.functional import cached_property
from .utils import create_root, create_team, create_user
@ -180,9 +181,9 @@ class ViewTestCaseMixin(TestCaseMixin):
- 'root': a superuser, account trigramme: 200.
Their password is their username.
One can create additionnal users with 'users_extra' attribute, or prevent
these 3 users to be created with 'users_base' attribute. See these two
properties for further informations.
One can create additionnal users with 'get_users_extra' method, or prevent
these 3 users to be created with 'get_users_base' method. See these two
methods for further informations.
By using 'register_user' method, these users can then be accessed at
'users' attribute by their label. Similarly, their kfet account is
@ -240,7 +241,7 @@ class ViewTestCaseMixin(TestCaseMixin):
self.users = {}
self.accounts = {}
for label, user in {**self.users_base, **self.users_extra}.items():
for label, user in dict(self.users_base, **self.users_extra).items():
self.register_user(label, user)
if self.auth_user:
@ -252,8 +253,20 @@ class ViewTestCaseMixin(TestCaseMixin):
)
)
@property
def users_base(self):
def tearDown(self):
del self.users_base
del self.users_extra
def get_users_base(self):
"""
Dict of <label: user instance>.
Note: Don't access yourself this property. Use 'users_base' attribute
which cache the returned value from here.
It allows to give functions calls, which creates users instances, as
values here.
"""
# Format desc: username, password, trigramme
return {
# user, user, 000
@ -264,10 +277,26 @@ class ViewTestCaseMixin(TestCaseMixin):
'root': create_root(),
}
@property
def users_extra(self):
@cached_property
def users_base(self):
return self.get_users_base()
def get_users_extra(self):
"""
Dict of <label: user instance>.
Note: Don't access yourself this property. Use 'users_base' attribute
which cache the returned value from here.
It allows to give functions calls, which create users instances, as
values here.
"""
return {}
@cached_property
def users_extra(self):
return self.get_users_extra()
def register_user(self, label, user):
self.users[label] = user
if hasattr(user.profile, 'account_kfet'):