714903210c
- KFetConfig `set` method now takes model instance instead of their pk for this type of entries. - Add tests for KFetConfig class: tests against types currently used by kfet app (duration, modelinstance, decimal). - These tests are located in `kfet/tests/test_config.py`. We should separate tests suites by file like this, considering what they are about. - KFetConfig method `set_many` renamed to `set` (because it also updates only one).
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
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'))
|
|
|
|
def test_set_decimal(self):
|
|
"""Test field of decimal type."""
|
|
subvention_cof = Decimal('10')
|
|
# IUT
|
|
kfet_config.set(subvention_cof=subvention_cof)
|
|
# check
|
|
self.assertEqual(kfet_config.subvention_cof, subvention_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',
|
|
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)
|