Increase selling label size and add more counter click tests

This commit is contained in:
Antoine Bartuccio 2024-12-23 00:00:40 +01:00
parent f6693e12cf
commit b8d43a629b
3 changed files with 98 additions and 10 deletions

View File

@ -0,0 +1,17 @@
# Generated by Django 4.2.17 on 2024-12-22 22:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("counter", "0028_alter_producttype_comment_and_more"),
]
operations = [
migrations.AlterField(
model_name="selling",
name="label",
field=models.CharField(max_length=128, verbose_name="label"),
),
]

View File

@ -791,7 +791,8 @@ class SellingQuerySet(models.QuerySet):
class Selling(models.Model): class Selling(models.Model):
"""Handle the sellings.""" """Handle the sellings."""
label = models.CharField(_("label"), max_length=64) # We make sure that sellings have a way begger label than any product name is allowed to
label = models.CharField(_("label"), max_length=128)
product = models.ForeignKey( product = models.ForeignKey(
Product, Product,
related_name="sellings", related_name="sellings",

View File

@ -31,6 +31,7 @@ from model_bakery import baker
from club.models import Club, Membership from club.models import Club, Membership
from core.baker_recipes import board_user, old_subscriber_user, subscriber_user from core.baker_recipes import board_user, old_subscriber_user, subscriber_user
from core.models import User from core.models import User
from counter.baker_recipes import product_recipe
from counter.models import ( from counter.models import (
Counter, Counter,
Customer, Customer,
@ -216,26 +217,33 @@ class TestCounterClick(FullClickSetup, TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
super().setUpTestData() super().setUpTestData()
cls.beer = baker.make(
Product, limit_age=18, selling_price="1.5", special_selling_price="1" cls.underage_customer = subscriber_user.make()
cls.set_age(cls.customer, 20)
cls.set_age(cls.barmen, 20)
cls.set_age(cls.club_admin, 20)
cls.set_age(cls.underage_customer, 17)
cls.beer = product_recipe.make(
limit_age=18, selling_price="1.5", special_selling_price="1"
) )
cls.beer_tape = baker.make( cls.beer_tap = product_recipe.make(
Product,
limit_age=18, limit_age=18,
tray=True, tray=True,
selling_price="1.5", selling_price="1.5",
special_selling_price="1", special_selling_price="1",
) )
cls.snack = baker.make( cls.snack = product_recipe.make(
Product, limit_age=0, selling_price="1.5", special_selling_price="1" limit_age=0, selling_price="1.5", special_selling_price="1"
) )
cls.stamps = baker.make( cls.stamps = product_recipe.make(
Product, limit_age=0, selling_price="1.5", special_selling_price="1" limit_age=0, selling_price="1.5", special_selling_price="1"
) )
cls.counter.products.add(cls.beer) cls.counter.products.add(cls.beer)
cls.counter.products.add(cls.beer_tape) cls.counter.products.add(cls.beer_tap)
cls.counter.products.add(cls.snack) cls.counter.products.add(cls.snack)
cls.counter.save() cls.counter.save()
@ -252,6 +260,11 @@ class TestCounterClick(FullClickSetup, TestCase):
{"username": used_barman.username, "password": "plop"}, {"username": used_barman.username, "password": "plop"},
) )
@classmethod
def set_age(cls, user: User, age: int):
user.date_of_birth = localdate().replace(year=localdate().year - age)
user.save()
def submit_basket( def submit_basket(
self, self,
user: User, user: User,
@ -306,6 +319,63 @@ class TestCounterClick(FullClickSetup, TestCase):
assert self.updated_amount(self.club_admin) == Decimal("8.5") assert self.updated_amount(self.club_admin) == Decimal("8.5")
def test_click_bar_success(self):
self.refill_user(self.customer, 10)
self.login_in_bar(self.barmen)
assert (
self.submit_basket(
self.customer,
[
BasketItem(self.beer.id, 2),
BasketItem(self.snack.id, 1),
],
).status_code
== 302
)
assert self.updated_amount(self.customer) == Decimal("5.5")
# Test barmen special price
self.refill_user(self.barmen, 10)
assert (
self.submit_basket(self.barmen, [BasketItem(self.beer.id, 1)])
).status_code == 302
assert self.updated_amount(self.barmen) == Decimal("9")
def test_click_tray_price(self):
self.refill_user(self.customer, 20)
self.login_in_bar(self.barmen)
# Not applying tray price
assert (
self.submit_basket(
self.customer,
[
BasketItem(self.beer_tap.id, 2),
],
).status_code
== 302
)
assert self.updated_amount(self.customer) == Decimal("17")
# Applying tray price
assert (
self.submit_basket(
self.customer,
[
BasketItem(self.beer_tap.id, 7),
],
).status_code
== 302
)
assert self.updated_amount(self.customer) == Decimal("8")
def test_annotate_has_barman_queryset(self): def test_annotate_has_barman_queryset(self):
"""Test if the custom queryset method `annotate_has_barman` works as intended.""" """Test if the custom queryset method `annotate_has_barman` works as intended."""
counters = Counter.objects.annotate_has_barman(self.barmen) counters = Counter.objects.annotate_has_barman(self.barmen)