forked from DGNum/gestioCOF
Improve users management on kfet TestCase, and Py34 compat
This commit is contained in:
parent
997b63d6b6
commit
af97c0cda6
2 changed files with 64 additions and 62 deletions
|
@ -93,8 +93,7 @@ class AccountCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
'email': 'email@domain.net',
|
'email': 'email@domain.net',
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.add_account']),
|
'team1': create_team('team1', '101', perms=['kfet.add_account']),
|
||||||
}
|
}
|
||||||
|
@ -212,8 +211,7 @@ class AccountReadViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team'
|
auth_user = 'team'
|
||||||
auth_forbidden = [None, 'user']
|
auth_forbidden = [None, 'user']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'user1': create_user('user1', '001'),
|
'user1': create_user('user1', '001'),
|
||||||
}
|
}
|
||||||
|
@ -292,8 +290,7 @@ class AccountUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
'pwd2': '',
|
'pwd2': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'user1': create_user('user1', '001'),
|
'user1': create_user('user1', '001'),
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
|
@ -359,8 +356,7 @@ class AccountGroupListViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team1'
|
auth_user = 'team1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.manage_perms']),
|
'team1': create_team('team1', '101', perms=['kfet.manage_perms']),
|
||||||
}
|
}
|
||||||
|
@ -390,8 +386,7 @@ class AccountGroupCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team1'
|
auth_user = 'team1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.manage_perms']),
|
'team1': create_team('team1', '101', perms=['kfet.manage_perms']),
|
||||||
}
|
}
|
||||||
|
@ -449,8 +444,7 @@ class AccountGroupUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/accounts/groups/{}/edit'.format(self.group.pk)
|
return '/k-fet/accounts/groups/{}/edit'.format(self.group.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.manage_perms']),
|
'team1': create_team('team1', '101', perms=['kfet.manage_perms']),
|
||||||
}
|
}
|
||||||
|
@ -502,8 +496,7 @@ class AccountNegativeListViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team1'
|
auth_user = 'team1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.view_negs']),
|
'team1': create_team('team1', '101', perms=['kfet.view_negs']),
|
||||||
}
|
}
|
||||||
|
@ -533,8 +526,7 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'user1'
|
auth_user = 'user1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {'user1': create_user('user1', '001')}
|
return {'user1': create_user('user1', '001')}
|
||||||
|
|
||||||
def test_ok(self):
|
def test_ok(self):
|
||||||
|
@ -594,8 +586,7 @@ class AccountStatOperationViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'user1'
|
auth_user = 'user1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {'user1': create_user('user1', '001')}
|
return {'user1': create_user('user1', '001')}
|
||||||
|
|
||||||
def test_ok(self):
|
def test_ok(self):
|
||||||
|
@ -611,8 +602,7 @@ class AccountStatBalanceListViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'user1'
|
auth_user = 'user1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {'user1': create_user('user1', '001')}
|
return {'user1': create_user('user1', '001')}
|
||||||
|
|
||||||
def test_ok(self):
|
def test_ok(self):
|
||||||
|
@ -666,8 +656,7 @@ class AccountStatBalanceViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'user1'
|
auth_user = 'user1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {'user1': create_user('user1', '001')}
|
return {'user1': create_user('user1', '001')}
|
||||||
|
|
||||||
def test_ok(self):
|
def test_ok(self):
|
||||||
|
@ -724,8 +713,7 @@ class CheckoutCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
# 'is_protected': not checked
|
# 'is_protected': not checked
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.add_checkout']),
|
'team1': create_team('team1', '101', perms=['kfet.add_checkout']),
|
||||||
}
|
}
|
||||||
|
@ -807,8 +795,7 @@ class CheckoutUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/checkouts/{}/edit'.format(self.checkout.pk)
|
return '/k-fet/checkouts/{}/edit'.format(self.checkout.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.change_checkout',
|
'kfet.change_checkout',
|
||||||
|
@ -927,8 +914,7 @@ class CheckoutStatementCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/checkouts/{}/statements/add'.format(self.checkout.pk)
|
return '/k-fet/checkouts/{}/statements/add'.format(self.checkout.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '001', perms=[
|
'team1': create_team('team1', '001', perms=[
|
||||||
'kfet.add_checkoutstatement',
|
'kfet.add_checkoutstatement',
|
||||||
|
@ -1014,8 +1000,7 @@ class CheckoutStatementUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
pk=self.statement.pk,
|
pk=self.statement.pk,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.change_checkoutstatement',
|
'kfet.change_checkoutstatement',
|
||||||
|
@ -1109,8 +1094,7 @@ class ArticleCategoryUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/categories/{}/edit'.format(self.category.pk)
|
return '/k-fet/categories/{}/edit'.format(self.category.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.change_articlecategory',
|
'kfet.change_articlecategory',
|
||||||
|
@ -1188,8 +1172,7 @@ class ArticleCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team'
|
auth_user = 'team'
|
||||||
auth_forbidden = [None, 'user']
|
auth_forbidden = [None, 'user']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.add_article']),
|
'team1': create_team('team1', '101', perms=['kfet.add_article']),
|
||||||
}
|
}
|
||||||
|
@ -1276,8 +1259,7 @@ class ArticleUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/articles/{}/edit'.format(self.article.pk)
|
return '/k-fet/articles/{}/edit'.format(self.article.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.change_article',
|
'kfet.change_article',
|
||||||
|
@ -1564,8 +1546,7 @@ class KPsulUpdateAddcost(ViewTestCaseMixin, TestCase):
|
||||||
'amount': '0.5',
|
'amount': '0.5',
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.manage_addcosts',
|
'kfet.manage_addcosts',
|
||||||
|
@ -1649,8 +1630,7 @@ class SettingsListViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team1'
|
auth_user = 'team1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.see_config',
|
'kfet.see_config',
|
||||||
|
@ -1682,8 +1662,7 @@ class SettingsUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
'kfet_cancel_duration': '00:20:00',
|
'kfet_cancel_duration': '00:20:00',
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.change_config',
|
'kfet.change_config',
|
||||||
|
@ -1749,8 +1728,7 @@ class TransferPerformViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team1'
|
auth_user = 'team1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
# Required
|
# Required
|
||||||
|
@ -1806,8 +1784,7 @@ class TransferCancelViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team1'
|
auth_user = 'team1'
|
||||||
auth_forbidden = [None, 'user', 'team']
|
auth_forbidden = [None, 'user', 'team']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
# Convenience
|
# Convenience
|
||||||
|
@ -1898,8 +1875,7 @@ class InventoryCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
auth_user = 'team'
|
auth_user = 'team'
|
||||||
auth_forbidden = [None, 'user']
|
auth_forbidden = [None, 'user']
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.add_inventory',
|
'kfet.add_inventory',
|
||||||
|
@ -2069,8 +2045,7 @@ class SupplierUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/orders/suppliers/{}/edit'.format(self.supplier.pk)
|
return '/k-fet/orders/suppliers/{}/edit'.format(self.supplier.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.change_supplier',
|
'kfet.change_supplier',
|
||||||
|
@ -2124,8 +2099,7 @@ class OrderCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/orders/suppliers/{}/new-order'.format(self.supplier.pk)
|
return '/k-fet/orders/suppliers/{}/new-order'.format(self.supplier.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=['kfet.add_order']),
|
'team1': create_team('team1', '101', perms=['kfet.add_order']),
|
||||||
}
|
}
|
||||||
|
@ -2195,8 +2169,7 @@ class OrderToInventoryViewTests(ViewTestCaseMixin, TestCase):
|
||||||
def url_expected(self):
|
def url_expected(self):
|
||||||
return '/k-fet/orders/{}/to_inventory'.format(self.order.pk)
|
return '/k-fet/orders/{}/to_inventory'.format(self.order.pk)
|
||||||
|
|
||||||
@property
|
def get_users_extra(self):
|
||||||
def users_extra(self):
|
|
||||||
return {
|
return {
|
||||||
'team1': create_team('team1', '101', perms=[
|
'team1': create_team('team1', '101', perms=[
|
||||||
'kfet.order_to_inventory',
|
'kfet.order_to_inventory',
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
from django.test import Client
|
from django.test import Client
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
from .utils import create_root, create_team, create_user
|
from .utils import create_root, create_team, create_user
|
||||||
|
|
||||||
|
@ -180,9 +181,9 @@ class ViewTestCaseMixin(TestCaseMixin):
|
||||||
- 'root': a superuser, account trigramme: 200.
|
- 'root': a superuser, account trigramme: 200.
|
||||||
Their password is their username.
|
Their password is their username.
|
||||||
|
|
||||||
One can create additionnal users with 'users_extra' attribute, or prevent
|
One can create additionnal users with 'get_users_extra' method, or prevent
|
||||||
these 3 users to be created with 'users_base' attribute. See these two
|
these 3 users to be created with 'get_users_base' method. See these two
|
||||||
properties for further informations.
|
methods for further informations.
|
||||||
|
|
||||||
By using 'register_user' method, these users can then be accessed at
|
By using 'register_user' method, these users can then be accessed at
|
||||||
'users' attribute by their label. Similarly, their kfet account is
|
'users' attribute by their label. Similarly, their kfet account is
|
||||||
|
@ -240,7 +241,7 @@ class ViewTestCaseMixin(TestCaseMixin):
|
||||||
self.users = {}
|
self.users = {}
|
||||||
self.accounts = {}
|
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)
|
self.register_user(label, user)
|
||||||
|
|
||||||
if self.auth_user:
|
if self.auth_user:
|
||||||
|
@ -252,8 +253,20 @@ class ViewTestCaseMixin(TestCaseMixin):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
def tearDown(self):
|
||||||
def users_base(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
|
# Format desc: username, password, trigramme
|
||||||
return {
|
return {
|
||||||
# user, user, 000
|
# user, user, 000
|
||||||
|
@ -264,10 +277,26 @@ class ViewTestCaseMixin(TestCaseMixin):
|
||||||
'root': create_root(),
|
'root': create_root(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def users_extra(self):
|
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 {}
|
return {}
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def users_extra(self):
|
||||||
|
return self.get_users_extra()
|
||||||
|
|
||||||
def register_user(self, label, user):
|
def register_user(self, label, user):
|
||||||
self.users[label] = user
|
self.users[label] = user
|
||||||
if hasattr(user.profile, 'account_kfet'):
|
if hasattr(user.profile, 'account_kfet'):
|
||||||
|
|
Loading…
Reference in a new issue