neu: kategorie, config + test
This commit is contained in:
parent
b9bb433c39
commit
d6a8b254a3
28 changed files with 1255 additions and 35 deletions
96
tests/test_config.py
Normal file
96
tests/test_config.py
Normal file
|
@ -0,0 +1,96 @@
|
|||
# -*- 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
|
Loading…
Add table
Add a link
Reference in a new issue