end barmanship on ban

This commit is contained in:
imperosol committed 2026-11-10 20:21:50 +01:00
1 parent 079ec8a8e5
commit e45b4eb9e0
2 files changed
+30 -5

No files matched your search

+22 -5
View File
@@ -8,7 +8,10 @@ from django.utils.timezone import localtime
from model_bakery import baker
from pytest_django.asserts import assertRedirects
from core.baker_recipes import subscriber_user
from core.models import BanGroup, User, UserBan
from counter.models import Counter
from sith import settings
if TYPE_CHECKING:
from django.test import Client
@@ -33,11 +36,7 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
client.force_login(operator)
user = baker.make(User)
ban_group = BanGroup.objects.first()
data = {
"user": user.id,
"ban_group": ban_group.id,
"reason": "Being naughty",
}
data = {"user": user.id, "ban_group": ban_group.id, "reason": "Being naughty"}
if expires_at is not None:
data["expires_at"] = expires_at.strftime("%Y-%m-%d %H:%M")
response = client.post(reverse("rootplace:ban_create"), data)
@@ -49,6 +48,24 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
assert bans[0].ban_group == ban_group
@pytest.mark.django_db
def test_ban_counter_ends_barmanship():
user = subscriber_user.make()
counter = baker.make(Counter)
counter.sellers.add(user, through_defaults={"is_regular": True})
UserBan.objects.create(
user=user,
ban_group_id=settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
reason="ban comptoir",
)
# check that we did effectively delete the barmanship
# and not the bar itself (better safe than sorry)
assert Counter.objects.filter(id=counter.id).exists()
assert not user.counters.exists()
@pytest.mark.django_db
def test_remove_ban(client: Client, operator: User):
client.force_login(operator)