kpsul/kfet/tests/test_config.py
2017-10-26 14:07:45 +02:00

55 lines
1.7 KiB
Python

import djconfig
from decimal import Decimal
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.utils import timezone
from kfet.config import kfet_config
from kfet.models import Account
User = get_user_model()
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'))
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)
def test_set_decimal(self):
"""Test field of decimal type."""
reduction_cof = Decimal('10')
# IUT
kfet_config.set(reduction_cof=reduction_cof)
# check
self.assertEqual(kfet_config.reduction_cof, reduction_cof)
def test_set_modelinstance(self):
"""Test field of model instance type."""
user = User.objects.create(username='foo_user')
account = Account.objects.create(trigramme='FOO',
profile=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)