mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
feat: forbid self-refill on counters
This commit is contained in:
1 parent
ebb43658e1
commit
702524d77d
5 files changed
+70
-5
No files matched your search
@@ -18,7 +18,7 @@ from decimal import Decimal
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from bs4 import BeautifulSoup, SoupStrainer
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.hashers import make_password
|
||||
@@ -144,6 +144,24 @@ class TestRefilling(TestFullClickBase):
|
||||
),
|
||||
)
|
||||
|
||||
def refill_form_displayed(self, customer: User | Customer | None = None) -> bool:
|
||||
"""Assert the click interface is displayed,
|
||||
then return if it contains the refill form.
|
||||
"""
|
||||
if not customer:
|
||||
customer = self.customer
|
||||
click_res = self.client.get(
|
||||
reverse(
|
||||
"counter:click",
|
||||
kwargs={"counter_id": self.counter.id, "user_id": customer.pk},
|
||||
)
|
||||
)
|
||||
assert click_res.status_code == 200
|
||||
soup = BeautifulSoup(
|
||||
click_res.content, "lxml", parse_only=SoupStrainer(id="click-form")
|
||||
)
|
||||
return soup.find(id="counter-refill-fragment") is not None
|
||||
|
||||
def test_refilling_office_fail(self):
|
||||
self.client.force_login(self.club_admin)
|
||||
assert self.refill_user(self.customer, self.club_counter, 10).status_code == 403
|
||||
@@ -197,9 +215,22 @@ class TestRefilling(TestFullClickBase):
|
||||
|
||||
def test_refilling_counter_no_board_member(self):
|
||||
self.login_in_bar(barmen=self.barmen)
|
||||
assert not self.refill_form_displayed()
|
||||
assert self.refill_user(self.customer, self.counter, 10).status_code == 403
|
||||
assert self.updated_amount(self.customer) == 0
|
||||
|
||||
def test_self_refill_fails(self):
|
||||
"""Test that a barman cannot refill itself."""
|
||||
original_amount = self.barmen.customer.amount
|
||||
self.barmen.user_permissions.add(
|
||||
Permission.objects.get(codename="add_refilling")
|
||||
)
|
||||
self.login_in_bar(barmen=self.barmen)
|
||||
|
||||
assert not self.refill_form_displayed(customer=self.barmen)
|
||||
assert self.refill_user(self.barmen, self.counter, 10).status_code == 403
|
||||
assert self.updated_amount(self.customer) == original_amount
|
||||
|
||||
def test_refilling_user_can_not_buy(self):
|
||||
self.login_in_bar(barmen=self.barmen)
|
||||
|
||||
@@ -228,6 +259,7 @@ class TestRefilling(TestFullClickBase):
|
||||
def test_refilling_counter_success(self):
|
||||
self.login_in_bar()
|
||||
|
||||
assert self.refill_form_displayed()
|
||||
assert self.refill_user(self.customer, self.counter, 30).status_code == 302
|
||||
assert self.updated_amount(self.customer) == 30
|
||||
assert self.refill_user(self.customer, self.counter, 10.1).status_code == 302
|
||||
|
||||
Reference in new issue
Block a user