mirror of
https://github.com/ae-utbm/sith.git
synced 2026-06-13 11:39:25 +00:00
add tests
This commit is contained in:
@@ -144,6 +144,8 @@ 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"""
|
||||
|
||||
def refill():
|
||||
return self.client.post(
|
||||
reverse(
|
||||
@@ -157,13 +159,13 @@ class TestRefilling(TestFullClickBase):
|
||||
)
|
||||
|
||||
self.client.force_login(self.club_admin)
|
||||
assert refill()
|
||||
assert refill().status_code == 403
|
||||
|
||||
self.client.force_login(self.root)
|
||||
assert refill()
|
||||
assert refill().status_code == 403
|
||||
|
||||
self.client.force_login(self.subscriber)
|
||||
assert refill()
|
||||
assert refill().status_code == 403
|
||||
|
||||
assert self.updated_amount(self.customer) == 0
|
||||
|
||||
@@ -199,6 +201,17 @@ class TestRefilling(TestFullClickBase):
|
||||
== 404
|
||||
)
|
||||
|
||||
def test_refilling_above_limit_fails(self):
|
||||
"""Test that it's forbidden to refill a customer above the limit."""
|
||||
self.login_in_bar()
|
||||
limit = settings.SITH_ACCOUNT_MAX_MONEY
|
||||
# create a refilling to check that current balance is taken into account
|
||||
baker.make(Refilling, customer=self.customer.customer, amount=limit // 2)
|
||||
response = self.refill_user(self.customer, self.counter, (limit // 2) + 1)
|
||||
assert response.status_code == 200 # no redirect = failure
|
||||
self.customer.customer.refresh_from_db()
|
||||
assert self.updated_amount(self.customer) == limit // 2
|
||||
|
||||
def test_refilling_counter_success(self):
|
||||
self.login_in_bar()
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from core.models import User
|
||||
from counter.baker_recipes import product_recipe, refill_recipe, sale_recipe
|
||||
from counter.models import (
|
||||
Counter,
|
||||
CounterSellers,
|
||||
Customer,
|
||||
Refilling,
|
||||
ReturnableProduct,
|
||||
@@ -38,7 +39,7 @@ class TestStudentCard(TestCase):
|
||||
cls.subscriber = subscriber_user.make()
|
||||
|
||||
cls.counter = baker.make(Counter, type="BAR")
|
||||
cls.counter.sellers.add(cls.barmen)
|
||||
CounterSellers.objects.create(counter=cls.counter, user=cls.barmen)
|
||||
|
||||
cls.club_counter = baker.make(Counter)
|
||||
role = baker.make(ClubRole, club=cls.club_counter.club, is_board=True)
|
||||
|
||||
Reference in New Issue
Block a user