forked from DGNum/gestioCOF
Tests du nouveau comportement
This commit is contained in:
parent
348881d207
commit
1939a54fef
1 changed files with 55 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
import datetime
|
||||
from datetime import datetime, timedelta, timezone as tz
|
||||
from decimal import Decimal
|
||||
from unittest import mock
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from kfet.models import Account, Checkout
|
||||
from kfet.models import Account, AccountNegative, Checkout
|
||||
|
||||
from .utils import create_user
|
||||
|
||||
|
@ -28,6 +30,56 @@ class AccountTests(TestCase):
|
|||
with self.assertRaises(Account.DoesNotExist):
|
||||
Account.objects.get_by_password("bernard")
|
||||
|
||||
@mock.patch("django.utils.timezone.now")
|
||||
def test_negative_creation(self, mock_now):
|
||||
now = datetime(2005, 7, 15, tzinfo=tz.utc)
|
||||
mock_now.return_value = now
|
||||
self.account.balance = Decimal(-10)
|
||||
self.account.update_negative()
|
||||
|
||||
self.assertTrue(hasattr(self.account, "negative"))
|
||||
self.assertEqual(self.account.negative.start, now)
|
||||
|
||||
@mock.patch("django.utils.timezone.now")
|
||||
def test_negative_no_reset(self, mock_now):
|
||||
now = datetime(2005, 7, 15, tzinfo=tz.utc)
|
||||
mock_now.return_value = now
|
||||
|
||||
self.account.balance = Decimal(-10)
|
||||
AccountNegative.objects.create(
|
||||
account=self.account, start=now - timedelta(minutes=3)
|
||||
)
|
||||
self.account.refresh_from_db()
|
||||
|
||||
self.account.balance = Decimal(5)
|
||||
self.account.update_negative()
|
||||
self.assertTrue(hasattr(self.account, "negative"))
|
||||
|
||||
self.account.balance = Decimal(-10)
|
||||
self.account.update_negative()
|
||||
self.assertEqual(self.account.negative.start, now - timedelta(minutes=3))
|
||||
|
||||
@mock.patch("django.utils.timezone.now")
|
||||
def test_negative_eventually_resets(self, mock_now):
|
||||
now = datetime(2005, 7, 15, tzinfo=tz.utc)
|
||||
mock_now.return_value = now
|
||||
|
||||
self.account.balance = Decimal(-10)
|
||||
AccountNegative.objects.create(
|
||||
account=self.account, start=now - timedelta(minutes=20)
|
||||
)
|
||||
self.account.refresh_from_db()
|
||||
self.account.balance = Decimal(5)
|
||||
|
||||
mock_now.return_value = now - timedelta(minutes=10)
|
||||
self.account.update_negative()
|
||||
|
||||
mock_now.return_value = now
|
||||
self.account.update_negative()
|
||||
self.account.refresh_from_db()
|
||||
|
||||
self.assertFalse(hasattr(self.account, "negative"))
|
||||
|
||||
|
||||
class CheckoutTests(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -39,7 +91,7 @@ class CheckoutTests(TestCase):
|
|||
self.c = Checkout(
|
||||
created_by=self.u_acc,
|
||||
valid_from=self.now,
|
||||
valid_to=self.now + datetime.timedelta(days=1),
|
||||
valid_to=self.now + timedelta(days=1),
|
||||
)
|
||||
|
||||
def test_initial_statement(self):
|
||||
|
|
Loading…
Reference in a new issue