add tests

This commit is contained in:
imperosol
2026-09-17 12:51:16 +02:00
parent ee6b4d4b1e
commit 46318be572
2 changed files with 35 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
import pytest
from django.contrib.auth.models import Permission
from model_bakery import baker
from core.models import Group, User
@pytest.mark.django_db
def test_with_perm():
"""Test that `SithModelBackend.with_perm` works as intended."""
perms = baker.make(Permission, _quantity=4)
groups = baker.make(Group, _quantity=2)
groups[0].permissions.set(perms[0:2])
groups[1].permissions.set(perms[2:4])
users = [
baker.make(User),
baker.make(User, groups=[groups[0]]),
baker.make(User, groups=[groups[1]]),
baker.make(User, user_permissions=[perms[0]]),
baker.make(User, user_permissions=[perms[2]]),
baker.make(User, groups=[groups[1]], user_permissions=[perms[0]]),
]
expected = [users[1], users[3], users[5]]
assert list(User.objects.with_perm(perms[0])) == expected
str_repr = f"{perms[0].content_type.app_label}.{perms[0].codename}"
assert list(User.objects.with_perm(str_repr)) == expected
+8 -1
View File
@@ -108,6 +108,13 @@ class TestFullClickBase(TestCase):
class TestRefilling(TestFullClickBase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()
cls.board_admin.user_permissions.add(
Permission.objects.get(codename="add_refilling")
)
def login_in_bar(self, barmen: User | None = None):
used_barman = barmen if barmen is not None else self.board_admin
self.client.post(
@@ -147,7 +154,7 @@ class TestRefilling(TestFullClickBase):
assert self.updated_amount(self.customer) == 0
def test_refilling_no_refer_fail(self):
"""Check that the refill fails is the HTTP_REFERER header is missing"""
"""Check that the refill fails if the HTTP_REFERER header is missing"""
def refill():
return self.client.post(