cashbook/tests/test_config.py
2022-08-09 15:08:41 +02:00

96 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
# This file is part of the cashbook-module from m-ds for Tryton.
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.exceptions import UserError
from datetime import date
class ConfigTestCase(ModuleTestCase):
'Test config type module'
module = 'cashbook'
@with_transaction()
def test_config_create(self):
""" create config
"""
Configuration = Pool().get('cashbook.configuration')
cfg1 = Configuration()
cfg1.save()
cfg2 = Configuration.get_singleton()
self.assertEqual(cfg2.date_from, None)
self.assertEqual(cfg2.date_to, None)
self.assertEqual(cfg2.checked, True)
self.assertEqual(cfg2.done, False)
@with_transaction()
def test_config_create_multi_user(self):
""" create config, multi-user
"""
pool = Pool()
Configuration = pool.get('cashbook.configuration')
ResUser = pool.get('res.user')
usr_lst = ResUser.create([{
'login': 'frida',
'name': 'Frida',
}, {
'login': 'diego',
'name': 'Diego',
}])
self.assertEqual(len(usr_lst), 2)
self.assertEqual(usr_lst[0].name, 'Frida')
self.assertEqual(usr_lst[1].name, 'Diego')
with Transaction().set_context({
'_check_access': True,
}):
# change to user 'frida'
with Transaction().set_user(usr_lst[0].id):
cfg1 = Configuration()
cfg1.save()
cfg2 = Configuration.get_singleton()
self.assertEqual(cfg2.date_from, None)
self.assertEqual(cfg2.date_to, None)
self.assertEqual(cfg2.checked, True)
self.assertEqual(cfg2.done, False)
cfg2.date_from = date(2022, 4, 1)
cfg2.date_to = date(2022, 5, 30)
cfg2.checked = False
cfg2.save()
# change to user 'diego'
with Transaction().set_user(usr_lst[1].id):
cfg1 = Configuration()
cfg1.save()
cfg2 = Configuration.get_singleton()
self.assertEqual(cfg2.date_from, None)
self.assertEqual(cfg2.date_to, None)
self.assertEqual(cfg2.checked, True)
self.assertEqual(cfg2.done, False)
cfg2.date_from = date(2022, 4, 15)
cfg2.date_to = date(2022, 5, 15)
cfg2.save()
# change to user 'frida' - check
with Transaction().set_user(usr_lst[0].id):
cfg1 = Configuration()
cfg1.save()
cfg2 = Configuration.get_singleton()
self.assertEqual(cfg2.date_from, date(2022, 4, 1))
self.assertEqual(cfg2.date_to, date(2022, 5, 30))
self.assertEqual(cfg2.checked, False)
self.assertEqual(cfg2.done, False)
# end ConfigTestCase