forked from DGNum/gestioCOF
Tests (!!)
This commit is contained in:
parent
52521e89a6
commit
f12370a6cd
1 changed files with 57 additions and 0 deletions
|
@ -8,6 +8,8 @@ from django.test import Client, TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from .. import KFET_DELETED_TRIGRAMME
|
||||||
|
from ..auth import KFET_GENERIC_TRIGRAMME
|
||||||
from ..config import kfet_config
|
from ..config import kfet_config
|
||||||
from ..models import (
|
from ..models import (
|
||||||
Account,
|
Account,
|
||||||
|
@ -340,6 +342,61 @@ class AccountUpdateViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.assertForbiddenKfet(r)
|
self.assertForbiddenKfet(r)
|
||||||
|
|
||||||
|
|
||||||
|
class AccountDeleteViewTests(ViewTestCaseMixin, TestCase):
|
||||||
|
url_name = "kfet.account.delete"
|
||||||
|
url_kwargs = {"trigramme": "001"}
|
||||||
|
url_expected = "/k-fet/accounts/001/delete"
|
||||||
|
|
||||||
|
auth_user = "team1"
|
||||||
|
auth_forbidden = [None, "user", "team"]
|
||||||
|
http_methods = ["GET", "POST"]
|
||||||
|
with_liq = True
|
||||||
|
|
||||||
|
def get_users_extra(self):
|
||||||
|
return {
|
||||||
|
"user1": create_user("user1", "001"),
|
||||||
|
"team1": create_team("team1", "101", perms=["kfet.delete_account"]),
|
||||||
|
"trez": create_user("trez", "#13"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_get_redirects(self):
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertRedirects(r, reverse("kfet.account.read", kwargs=self.url_kwargs))
|
||||||
|
|
||||||
|
def test_post_ok(self):
|
||||||
|
r = self.client.post(self.url, {})
|
||||||
|
self.assertRedirects(r, reverse("kfet.account"))
|
||||||
|
|
||||||
|
with self.assertRaises(Account.DoesNotExist):
|
||||||
|
self.accounts["user1"].refresh_from_db()
|
||||||
|
|
||||||
|
def test_protected_accounts(self):
|
||||||
|
for trigramme in ["LIQ", "#13", KFET_GENERIC_TRIGRAMME, KFET_DELETED_TRIGRAMME]:
|
||||||
|
if Account.objects.get(trigramme=trigramme).readable:
|
||||||
|
expected_code = 200
|
||||||
|
else:
|
||||||
|
expected_code = 403
|
||||||
|
r = self.client.post(
|
||||||
|
reverse(self.url_name, kwargs={"trigramme": trigramme}), {}
|
||||||
|
)
|
||||||
|
self.assertRedirects(
|
||||||
|
r,
|
||||||
|
reverse("kfet.account.read", kwargs={"trigramme": trigramme}),
|
||||||
|
target_status_code=expected_code,
|
||||||
|
)
|
||||||
|
# Devrait être redondant avec le précédent, mais on sait jamais
|
||||||
|
self.assertTrue(Account.objects.filter(trigramme=trigramme).exists())
|
||||||
|
|
||||||
|
def test_nonempty_accounts(self):
|
||||||
|
self.accounts["user1"].balance = 1
|
||||||
|
self.accounts["user1"].save()
|
||||||
|
|
||||||
|
r = self.client.post(self.url, {})
|
||||||
|
self.assertRedirects(r, reverse("kfet.account.read", kwargs=self.url_kwargs))
|
||||||
|
# Shouldn't throw an error
|
||||||
|
self.accounts["user1"].refresh_from_db()
|
||||||
|
|
||||||
|
|
||||||
class AccountGroupListViewTests(ViewTestCaseMixin, TestCase):
|
class AccountGroupListViewTests(ViewTestCaseMixin, TestCase):
|
||||||
url_name = "kfet.account.group"
|
url_name = "kfet.account.group"
|
||||||
url_expected = "/k-fet/accounts/groups"
|
url_expected = "/k-fet/accounts/groups"
|
||||||
|
|
Loading…
Reference in a new issue