Move group-related views tests to kfetauth tests
This commit is contained in:
parent
94f21c062a
commit
94ab754f82
|
@ -10,6 +10,8 @@ from django.core.urlresolvers import reverse
|
|||
from django.test import RequestFactory, TestCase
|
||||
|
||||
from kfet.models import Account
|
||||
from kfet.tests.testcases import ViewTestCaseMixin
|
||||
from kfet.tests.utils import create_team, get_perms
|
||||
|
||||
from . import KFET_GENERIC_TRIGRAMME, KFET_GENERIC_USERNAME
|
||||
from .backends import AccountBackend, GenericBackend
|
||||
|
@ -389,6 +391,154 @@ class GenericLoginViewTests(TestCase):
|
|||
self.assertEqual(r.wsgi_request.path, '/k-fet/')
|
||||
|
||||
|
||||
class GroupListViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.group'
|
||||
url_expected = '/k-fet/groupes/'
|
||||
|
||||
auth_user = 'team1'
|
||||
auth_forbidden = [None, 'user', 'team']
|
||||
|
||||
def get_users_extra(self):
|
||||
return {
|
||||
'team1': create_team('team1', '101', perms=[
|
||||
'kfetauth.view_group']),
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.group1 = Group.objects.create(name='K-Fêt - Group1')
|
||||
self.group2 = Group.objects.create(name='K-Fêt - Group2')
|
||||
|
||||
def test_ok(self):
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
r.context['groups'],
|
||||
map(repr, [self.group1, self.group2]),
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
class GroupCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.group.create'
|
||||
url_expected = '/k-fet/groupes/nouveau/'
|
||||
|
||||
http_methods = ['GET', 'POST']
|
||||
|
||||
auth_user = 'team1'
|
||||
auth_forbidden = [None, 'user', 'team']
|
||||
|
||||
def get_users_extra(self):
|
||||
return {
|
||||
'team1': create_team('team1', '101', perms=['kfetauth.add_group']),
|
||||
}
|
||||
|
||||
@property
|
||||
def post_data(self):
|
||||
return {
|
||||
'name': 'The Group',
|
||||
'permissions': [
|
||||
str(self.perms['kfet.is_team'].pk),
|
||||
str(self.perms['kfetauth.add_group'].pk),
|
||||
],
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.perms = get_perms(
|
||||
'kfet.is_team',
|
||||
'kfetauth.add_group',
|
||||
)
|
||||
|
||||
def test_get_ok(self):
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_post_ok(self):
|
||||
r = self.client.post(self.url, self.post_data)
|
||||
self.assertRedirects(
|
||||
r, reverse('kfet.group'),
|
||||
fetch_redirect_response=False, # Requires `kfetauth.view_group`.
|
||||
)
|
||||
|
||||
group = Group.objects.get(name='The Group')
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
group.permissions.all(),
|
||||
map(repr, [
|
||||
self.perms['kfet.is_team'],
|
||||
self.perms['kfetauth.add_group'],
|
||||
]),
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
class GroupUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.group.update'
|
||||
|
||||
http_methods = ['GET', 'POST']
|
||||
|
||||
auth_user = 'team1'
|
||||
auth_forbidden = [None, 'user', 'team']
|
||||
|
||||
@property
|
||||
def url_kwargs(self):
|
||||
return {'pk': self.group.pk}
|
||||
|
||||
@property
|
||||
def url_expected(self):
|
||||
return '/k-fet/groupes/{}/edition/'.format(self.group.pk)
|
||||
|
||||
def get_users_extra(self):
|
||||
return {
|
||||
'team1': create_team('team1', '101', perms=[
|
||||
'kfetauth.change_group']),
|
||||
}
|
||||
|
||||
@property
|
||||
def post_data(self):
|
||||
return {
|
||||
'name': 'The Group',
|
||||
'permissions': [
|
||||
str(self.perms['kfet.is_team'].pk),
|
||||
str(self.perms['kfetauth.change_group'].pk),
|
||||
],
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.perms = get_perms(
|
||||
'kfet.is_team',
|
||||
'kfetauth.change_group',
|
||||
)
|
||||
self.group = Group.objects.create(name='K-Fêt - Group')
|
||||
self.group.permissions = self.perms.values()
|
||||
|
||||
def test_get_ok(self):
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_post_ok(self):
|
||||
r = self.client.post(self.url, self.post_data)
|
||||
self.assertRedirects(
|
||||
r, reverse('kfet.group'),
|
||||
fetch_redirect_response=False, # Requires `kfetauth.view_group`.
|
||||
)
|
||||
|
||||
self.group.refresh_from_db()
|
||||
|
||||
self.assertEqual(self.group.name, 'The Group')
|
||||
self.assertQuerysetEqual(
|
||||
self.group.permissions.all(),
|
||||
map(repr, [
|
||||
self.perms['kfet.is_team'],
|
||||
self.perms['kfetauth.change_group'],
|
||||
]),
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
##
|
||||
# Temporary authentication
|
||||
#
|
||||
|
|
|
@ -7,8 +7,6 @@ from django.core.urlresolvers import reverse
|
|||
from django.test import Client, TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from kfet.auth.models import Group
|
||||
|
||||
from ..config import kfet_config
|
||||
from ..models import (
|
||||
Account, Article, ArticleCategory, Checkout, CheckoutStatement, Inventory,
|
||||
|
@ -16,7 +14,7 @@ from ..models import (
|
|||
SupplierArticle, Transfer, TransferGroup,
|
||||
)
|
||||
from .testcases import ViewTestCaseMixin
|
||||
from .utils import create_team, create_user, get_perms
|
||||
from .utils import create_team, create_user
|
||||
|
||||
|
||||
class AccountListViewTests(ViewTestCaseMixin, TestCase):
|
||||
|
@ -336,148 +334,6 @@ class AccountUpdateViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertForbiddenKfet(r)
|
||||
|
||||
|
||||
class AccountGroupListViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.group'
|
||||
url_expected = '/k-fet/groupes/'
|
||||
|
||||
auth_user = 'team1'
|
||||
auth_forbidden = [None, 'user', 'team']
|
||||
|
||||
def get_users_extra(self):
|
||||
return {
|
||||
'team1': create_team('team1', '101', perms=[
|
||||
'kfetauth.view_group']),
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.group1 = Group.objects.create(name='K-Fêt - Group1')
|
||||
self.group2 = Group.objects.create(name='K-Fêt - Group2')
|
||||
|
||||
def test_ok(self):
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
r.context['groups'],
|
||||
map(repr, [self.group1, self.group2]),
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
class AccountGroupCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.group.create'
|
||||
url_expected = '/k-fet/groupes/nouveau/'
|
||||
|
||||
http_methods = ['GET', 'POST']
|
||||
|
||||
auth_user = 'team1'
|
||||
auth_forbidden = [None, 'user', 'team']
|
||||
|
||||
def get_users_extra(self):
|
||||
return {
|
||||
'team1': create_team('team1', '101', perms=['kfetauth.add_group']),
|
||||
}
|
||||
|
||||
@property
|
||||
def post_data(self):
|
||||
return {
|
||||
'name': 'The Group',
|
||||
'permissions': [
|
||||
str(self.perms['kfet.is_team'].pk),
|
||||
str(self.perms['kfetauth.add_group'].pk),
|
||||
],
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.perms = get_perms(
|
||||
'kfet.is_team',
|
||||
'kfetauth.add_group',
|
||||
)
|
||||
|
||||
def test_get_ok(self):
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_post_ok(self):
|
||||
r = self.client.post(self.url, self.post_data)
|
||||
self.assertRedirects(r, reverse('kfet.group'))
|
||||
|
||||
group = Group.objects.get(name='The Group')
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
group.permissions.all(),
|
||||
map(repr, [
|
||||
self.perms['kfet.is_team'],
|
||||
self.perms['kfetauth.add_group'],
|
||||
]),
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
class AccountGroupUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.group.update'
|
||||
|
||||
http_methods = ['GET', 'POST']
|
||||
|
||||
auth_user = 'team1'
|
||||
auth_forbidden = [None, 'user', 'team']
|
||||
|
||||
@property
|
||||
def url_kwargs(self):
|
||||
return {'pk': self.group.pk}
|
||||
|
||||
@property
|
||||
def url_expected(self):
|
||||
return '/k-fet/groupes/{}/edition/'.format(self.group.pk)
|
||||
|
||||
def get_users_extra(self):
|
||||
return {
|
||||
'team1': create_team('team1', '101', perms=[
|
||||
'kfetauth.change_group']),
|
||||
}
|
||||
|
||||
@property
|
||||
def post_data(self):
|
||||
return {
|
||||
'name': 'The Group',
|
||||
'permissions': [
|
||||
str(self.perms['kfet.is_team'].pk),
|
||||
str(self.perms['kfetauth.change_group'].pk),
|
||||
],
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.perms = get_perms(
|
||||
'kfet.is_team',
|
||||
'kfetauth.change_group',
|
||||
)
|
||||
self.group = Group.objects.create(name='K-Fêt - Group')
|
||||
self.group.permissions = self.perms.values()
|
||||
|
||||
def test_get_ok(self):
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_post_ok(self):
|
||||
r = self.client.post(self.url, self.post_data)
|
||||
self.assertRedirects(r, reverse('kfet.group'))
|
||||
|
||||
self.group.refresh_from_db()
|
||||
|
||||
self.assertEqual(self.group.name, 'The Group')
|
||||
self.assertQuerysetEqual(
|
||||
self.group.permissions.all(),
|
||||
map(repr, [
|
||||
self.perms['kfet.is_team'],
|
||||
self.perms['kfetauth.change_group'],
|
||||
]),
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
||||
class AccountNegativeListViewTests(ViewTestCaseMixin, TestCase):
|
||||
url_name = 'kfet.account.negative'
|
||||
url_expected = '/k-fet/accounts/negatives'
|
||||
|
|
Loading…
Reference in a new issue