1
1

add whole new app for balance prediction, replace uwsgi, update everything

This commit is contained in:
2021-01-04 14:45:43 +01:00
parent 5e2881af2a
commit 37f698d82b
20 changed files with 448 additions and 191 deletions

View File

@@ -0,0 +1,47 @@
from decimal import Decimal, InvalidOperation
from django.test import TestCase
from django.utils import timezone
from core.models import Balance
def _create_and_reload_balance(amount):
bal = Balance.objects.create(amount=amount, date=timezone.now().date())
bal.refresh_from_db()
return bal
class PriceFieldTestCase(TestCase):
def test_normal_decimal(self):
bal = _create_and_reload_balance(Decimal("13.37"))
self.assertEqual(bal.amount, Decimal("13.37"))
def test_too_big_decimal(self):
with self.assertRaises(InvalidOperation):
_create_and_reload_balance(Decimal("13371337.00"))
def test_rounding_decimal(self):
bal = _create_and_reload_balance(Decimal("1.337"))
self.assertEqual(bal.amount, Decimal("1.34"))
def test_normal_int(self):
bal = _create_and_reload_balance(1337)
self.assertEqual(bal.amount, Decimal("1337.00"))
def test_too_big_int(self):
with self.assertRaises(InvalidOperation):
_create_and_reload_balance(13371337)
def test_normal_float(self):
bal = _create_and_reload_balance(13.37)
self.assertEqual(bal.amount, Decimal("13.37"))
def test_too_big_float(self):
with self.assertRaises(InvalidOperation):
_create_and_reload_balance(13371337.00)
def test_rounding_float(self):
bal = _create_and_reload_balance(1.337)
self.assertEqual(bal.amount, Decimal("1.34"))