diff --git a/core/tests/test_auth_backend.py b/core/tests/test_auth_backend.py new file mode 100644 index 00000000..97eaac1b --- /dev/null +++ b/core/tests/test_auth_backend.py @@ -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 diff --git a/counter/tests/test_counter.py b/counter/tests/test_counter.py index 581b5b07..83b65021 100644 --- a/counter/tests/test_counter.py +++ b/counter/tests/test_counter.py @@ -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(