mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-09 00:04:41 +00:00
add test case
This commit is contained in:
@@ -1402,5 +1402,9 @@ class InvoiceCall(models.Model):
|
||||
verbose_name = _("Invoice call")
|
||||
verbose_name_plural = _("Invoice calls")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.month = self._meta.get_field("month").to_python(self.month)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"invoice call of {self.month} made by {self.club}"
|
||||
|
33
counter/tests/test_invoices.py
Normal file
33
counter/tests/test_invoices.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
from model_bakery import baker
|
||||
|
||||
from club.models import Club
|
||||
from counter.models import InvoiceCall
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invoice_date_with_date():
|
||||
club = baker.make(Club)
|
||||
invoice = InvoiceCall.objects.create(club=club, month=date(2025, 10, 20))
|
||||
|
||||
assert not invoice.is_validated
|
||||
assert str(invoice) == f"invoice call of {invoice.month} made by {club}"
|
||||
assert invoice.month == date(2025, 10, 1)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invoice_date_with_string():
|
||||
club = baker.make(Club)
|
||||
invoice = InvoiceCall.objects.create(club=club, month="2025-10")
|
||||
|
||||
assert invoice.month == date(2025, 10, 1)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invoice_call_invalid_month_string():
|
||||
club = baker.make(Club)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
InvoiceCall.objects.create(club=club, month="2025-13")
|
Reference in New Issue
Block a user