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:
@@ -200,7 +200,11 @@ class TestFilterInactive(TestCase):
|
|||||||
]
|
]
|
||||||
sale_recipe.make(customer=cls.users[3].customer, date=time_active)
|
sale_recipe.make(customer=cls.users[3].customer, date=time_active)
|
||||||
baker.make(
|
baker.make(
|
||||||
Refilling, customer=cls.users[4].customer, date=time_active, counter=counter
|
Refilling,
|
||||||
|
customer=cls.users[4].customer,
|
||||||
|
date=time_active,
|
||||||
|
counter=counter,
|
||||||
|
amount=1,
|
||||||
)
|
)
|
||||||
sale_recipe.make(customer=cls.users[5].customer, date=time_inactive)
|
sale_recipe.make(customer=cls.users[5].customer, date=time_inactive)
|
||||||
|
|
||||||
@@ -455,7 +459,9 @@ def test_user_preferences(client: Client):
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_user_stats(client: Client):
|
def test_user_stats(client: Client):
|
||||||
user = subscriber_user.make()
|
user = subscriber_user.make()
|
||||||
baker.make(Refilling, customer=user.customer, amount=99999)
|
baker.make(
|
||||||
|
Refilling, customer=user.customer, amount=settings.SITH_ACCOUNT_MAX_MONEY
|
||||||
|
)
|
||||||
bars = [b[0] for b in settings.SITH_COUNTER_BARS]
|
bars = [b[0] for b in settings.SITH_COUNTER_BARS]
|
||||||
baker.make(
|
baker.make(
|
||||||
Permanency,
|
Permanency,
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ class TestRefilling(TestFullClickBase):
|
|||||||
assert self.updated_amount(self.customer) == 0
|
assert self.updated_amount(self.customer) == 0
|
||||||
|
|
||||||
def test_refilling_no_refer_fail(self):
|
def test_refilling_no_refer_fail(self):
|
||||||
|
"""Check that the refill fails is the HTTP_REFERER header is missing"""
|
||||||
|
|
||||||
def refill():
|
def refill():
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
reverse(
|
reverse(
|
||||||
@@ -157,13 +159,13 @@ class TestRefilling(TestFullClickBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.client.force_login(self.club_admin)
|
self.client.force_login(self.club_admin)
|
||||||
assert refill()
|
assert refill().status_code == 403
|
||||||
|
|
||||||
self.client.force_login(self.root)
|
self.client.force_login(self.root)
|
||||||
assert refill()
|
assert refill().status_code == 403
|
||||||
|
|
||||||
self.client.force_login(self.subscriber)
|
self.client.force_login(self.subscriber)
|
||||||
assert refill()
|
assert refill().status_code == 403
|
||||||
|
|
||||||
assert self.updated_amount(self.customer) == 0
|
assert self.updated_amount(self.customer) == 0
|
||||||
|
|
||||||
@@ -199,6 +201,17 @@ class TestRefilling(TestFullClickBase):
|
|||||||
== 404
|
== 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):
|
def test_refilling_counter_success(self):
|
||||||
self.login_in_bar()
|
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.baker_recipes import product_recipe, refill_recipe, sale_recipe
|
||||||
from counter.models import (
|
from counter.models import (
|
||||||
Counter,
|
Counter,
|
||||||
|
CounterSellers,
|
||||||
Customer,
|
Customer,
|
||||||
Refilling,
|
Refilling,
|
||||||
ReturnableProduct,
|
ReturnableProduct,
|
||||||
@@ -38,7 +39,7 @@ class TestStudentCard(TestCase):
|
|||||||
cls.subscriber = subscriber_user.make()
|
cls.subscriber = subscriber_user.make()
|
||||||
|
|
||||||
cls.counter = baker.make(Counter, type="BAR")
|
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)
|
cls.club_counter = baker.make(Counter)
|
||||||
role = baker.make(ClubRole, club=cls.club_counter.club, is_board=True)
|
role = baker.make(ClubRole, club=cls.club_counter.club, is_board=True)
|
||||||
|
|||||||
@@ -278,6 +278,27 @@ class TestEboutic(TestCase):
|
|||||||
)
|
)
|
||||||
assert Basket.objects.count() == 2
|
assert Basket.objects.count() == 2
|
||||||
|
|
||||||
|
def test_refill_limit(self):
|
||||||
|
"""Test that an eboutic basket cannot refill an account above the limit."""
|
||||||
|
self.client.force_login(self.subscriber)
|
||||||
|
product = product_recipe.make(
|
||||||
|
product_type_id=settings.SITH_COUNTER_PRODUCTTYPE_REFILLING,
|
||||||
|
counters=[self.eboutic],
|
||||||
|
)
|
||||||
|
price = price_recipe.make(
|
||||||
|
product=product,
|
||||||
|
groups=[self.group_cotiz],
|
||||||
|
amount=settings.SITH_ACCOUNT_MAX_MONEY // 10,
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self.submit_basket([BasketItem(price.id, 10)])
|
||||||
|
assert Basket.objects.count() == 1
|
||||||
|
assertRedirects(response, reverse("eboutic:checkout", kwargs={"basket_id": 1}))
|
||||||
|
|
||||||
|
response = self.submit_basket([BasketItem(price.id, 11)])
|
||||||
|
assert Basket.objects.count() == 1
|
||||||
|
assert response.status_code == 200 # no redirect = form validation failed
|
||||||
|
|
||||||
def test_create_basket(self):
|
def test_create_basket(self):
|
||||||
self.client.force_login(self.new_customer)
|
self.client.force_login(self.new_customer)
|
||||||
assertRedirects(
|
assertRedirects(
|
||||||
|
|||||||
Reference in New Issue
Block a user