neu: kategorie, config + test
This commit is contained in:
parent
b9bb433c39
commit
d6a8b254a3
28 changed files with 1255 additions and 35 deletions
|
@ -7,11 +7,15 @@ import unittest
|
|||
from trytond.modules.cashbook.tests.test_type import TypeTestCase
|
||||
from trytond.modules.cashbook.tests.test_book import BookTestCase
|
||||
from trytond.modules.cashbook.tests.test_line import LineTestCase
|
||||
from trytond.modules.cashbook.tests.test_config import ConfigTestCase
|
||||
from trytond.modules.cashbook.tests.test_category import CategoryTestCase
|
||||
|
||||
__all__ = ['suite']
|
||||
|
||||
|
||||
class CashbookTestCase(\
|
||||
CategoryTestCase,\
|
||||
ConfigTestCase,\
|
||||
LineTestCase,
|
||||
BookTestCase,
|
||||
TypeTestCase,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
# -*- 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.
|
||||
|
||||
import os, requests
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
|
@ -54,7 +55,7 @@ class BookTestCase(ModuleTestCase):
|
|||
self.assertEqual(book.state, 'open')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
|
||||
"The cashbook 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
|
||||
Book.delete,
|
||||
[book])
|
||||
|
||||
|
@ -82,7 +83,7 @@ class BookTestCase(ModuleTestCase):
|
|||
self.assertEqual(book.state, 'closed')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
|
||||
"The cashbook 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
|
||||
Book.delete,
|
||||
[book])
|
||||
|
||||
|
|
137
tests/test_category.py
Normal file
137
tests/test_category.py
Normal file
|
@ -0,0 +1,137 @@
|
|||
# -*- 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 trytond.modules.company.tests import create_company
|
||||
|
||||
|
||||
class CategoryTestCase(ModuleTestCase):
|
||||
'Test cashbook categoy module'
|
||||
module = 'cashbook'
|
||||
|
||||
@with_transaction()
|
||||
def test_category_create_nodupl_at_root(self):
|
||||
""" create category, duplicates are allowed at root-level
|
||||
"""
|
||||
pool = Pool()
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
cat1, = Category.create([{
|
||||
'name': 'Test 1',
|
||||
'description': 'Info',
|
||||
}])
|
||||
self.assertEqual(cat1.name, 'Test 1')
|
||||
self.assertEqual(cat1.rec_name, 'Test 1')
|
||||
self.assertEqual(cat1.description, 'Info')
|
||||
self.assertEqual(cat1.company.rec_name, 'm-ds')
|
||||
self.assertEqual(cat1.parent, None)
|
||||
|
||||
# duplicate, allowed
|
||||
cat2, = Category.create([{
|
||||
'name': 'Test 1',
|
||||
'description': 'Info',
|
||||
}])
|
||||
self.assertEqual(cat2.name, 'Test 1')
|
||||
self.assertEqual(cat2.rec_name, 'Test 1')
|
||||
self.assertEqual(cat2.description, 'Info')
|
||||
self.assertEqual(cat2.company.rec_name, 'm-ds')
|
||||
self.assertEqual(cat2.parent, None)
|
||||
|
||||
@with_transaction()
|
||||
def test_category_create_nodupl_diff_level(self):
|
||||
""" create category
|
||||
"""
|
||||
pool = Pool()
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
cat1, = Category.create([{
|
||||
'name': 'Test 1',
|
||||
'description': 'Info',
|
||||
'childs': [('create', [{
|
||||
'name': 'Test 1',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(cat1.name, 'Test 1')
|
||||
self.assertEqual(cat1.rec_name, 'Test 1')
|
||||
self.assertEqual(cat1.description, 'Info')
|
||||
self.assertEqual(cat1.company.rec_name, 'm-ds')
|
||||
|
||||
self.assertEqual(len(cat1.childs), 1)
|
||||
self.assertEqual(cat1.childs[0].rec_name, 'Test 1/Test 1')
|
||||
|
||||
@with_transaction()
|
||||
def test_category_create_deny_dupl_at_sublevel(self):
|
||||
""" create category
|
||||
"""
|
||||
pool = Pool()
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
self.assertRaisesRegex(UserError,
|
||||
'The category name already exists at this level.',
|
||||
Category.create,
|
||||
[{
|
||||
'name': 'Test 1',
|
||||
'description': 'Info',
|
||||
'childs': [('create', [{
|
||||
'name': 'Test 1',
|
||||
}, {
|
||||
'name': 'Test 1',
|
||||
}])],
|
||||
}])
|
||||
|
||||
@with_transaction()
|
||||
def test_category_create_with_account(self):
|
||||
""" create category + account
|
||||
"""
|
||||
pool = Pool()
|
||||
Account = pool.get('account.account')
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
account, = Account.create([{
|
||||
'name': 'Account No 1',
|
||||
'code': '0123',
|
||||
}])
|
||||
|
||||
cat1, = Category.create([{
|
||||
'name': 'Test 1',
|
||||
'description': 'Info',
|
||||
'account': account.id,
|
||||
}])
|
||||
self.assertEqual(cat1.name, 'Test 1')
|
||||
self.assertEqual(cat1.rec_name, '0123 Test 1')
|
||||
self.assertEqual(cat1.description, 'Info')
|
||||
self.assertEqual(cat1.company.rec_name, 'm-ds')
|
||||
|
||||
self.assertEqual(Category.search_count([
|
||||
('account_code', '=', '0123'),
|
||||
]), 1)
|
||||
self.assertEqual(Category.search_count([
|
||||
('account_code', '=', '123'),
|
||||
]), 0)
|
||||
|
||||
# end CategoryTestCase
|
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
|
|
@ -1,7 +1,8 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
# -*- 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.
|
||||
|
||||
import os, requests
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
# -*- 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.
|
||||
|
||||
import os, requests
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue