2017-04-04 17:05:55 +02:00
|
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
import djconfig
|
|
|
|
|
|
|
|
from gestioncof.models import User
|
|
|
|
from kfet.config import kfet_config
|
|
|
|
from kfet.models import Account
|
|
|
|
|
|
|
|
|
|
|
|
class ConfigTest(TestCase):
|
|
|
|
"""Tests suite for kfet configuration."""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# load configuration as in djconfig middleware
|
|
|
|
djconfig.reload_maybe()
|
|
|
|
|
|
|
|
def test_get(self):
|
|
|
|
self.assertTrue(hasattr(kfet_config, 'subvention_cof'))
|
|
|
|
|
2017-04-10 11:52:57 +02:00
|
|
|
def test_subvention_cof(self):
|
|
|
|
reduction_cof = Decimal('20')
|
|
|
|
subvention_cof = Decimal('25')
|
|
|
|
kfet_config.set(reduction_cof=reduction_cof)
|
|
|
|
|
|
|
|
self.assertEqual(kfet_config.subvention_cof, subvention_cof)
|
|
|
|
|
2017-04-04 17:05:55 +02:00
|
|
|
def test_set_decimal(self):
|
|
|
|
"""Test field of decimal type."""
|
2017-04-10 11:52:57 +02:00
|
|
|
reduction_cof = Decimal('10')
|
2017-04-04 17:05:55 +02:00
|
|
|
# IUT
|
2017-04-10 11:52:57 +02:00
|
|
|
kfet_config.set(reduction_cof=reduction_cof)
|
2017-04-04 17:05:55 +02:00
|
|
|
# check
|
2017-04-10 11:52:57 +02:00
|
|
|
self.assertEqual(kfet_config.reduction_cof, reduction_cof)
|
2017-04-04 17:05:55 +02:00
|
|
|
|
|
|
|
def test_set_modelinstance(self):
|
|
|
|
"""Test field of model instance type."""
|
|
|
|
user = User.objects.create(username='foo_user')
|
|
|
|
account = Account.objects.create(trigramme='FOO',
|
|
|
|
cofprofile=user.profile)
|
|
|
|
# IUT
|
|
|
|
kfet_config.set(addcost_for=account)
|
|
|
|
# check
|
|
|
|
self.assertEqual(kfet_config.addcost_for, account)
|
|
|
|
|
|
|
|
def test_set_duration(self):
|
|
|
|
"""Test field of duration type."""
|
|
|
|
cancel_duration = timezone.timedelta(days=2, hours=4)
|
|
|
|
# IUT
|
|
|
|
kfet_config.set(cancel_duration=cancel_duration)
|
|
|
|
# check
|
|
|
|
self.assertEqual(kfet_config.cancel_duration, cancel_duration)
|