mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX+IMP] contract: improve test coverage with new sections + fix search method
This commit is contained in:
committed by
Christopher Rogos
parent
b782d9d602
commit
6b0f5086b6
@@ -42,9 +42,16 @@ class TestContractBase(common.SavepointCase):
|
||||
'recurring_rule_type': 'yearly',
|
||||
'recurring_interval': 1,
|
||||
}
|
||||
cls.section_template_vals = {
|
||||
'display_type': 'line_section',
|
||||
'name': 'Test section',
|
||||
}
|
||||
cls.template_vals = {
|
||||
'name': 'Test Contract Template',
|
||||
'contract_line_ids': [(0, 0, cls.line_template_vals)],
|
||||
'contract_line_ids': [
|
||||
(0, 0, cls.section_template_vals),
|
||||
(0, 0, cls.line_template_vals),
|
||||
],
|
||||
}
|
||||
cls.template = cls.env['contract.template'].create(
|
||||
cls.template_vals
|
||||
@@ -403,6 +410,14 @@ class TestContract(TestContractBase):
|
||||
self.contract._onchange_contract_template_id()
|
||||
res = {
|
||||
'contract_line_ids': [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
'display_type': 'line_section',
|
||||
'name': 'Test section',
|
||||
}
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
@@ -434,15 +449,19 @@ class TestContract(TestContractBase):
|
||||
)
|
||||
self.contract.contract_template_id = self.template
|
||||
self.contract._onchange_contract_template_id()
|
||||
self.assertEqual(len(self.contract.contract_line_ids), 1)
|
||||
|
||||
for key, value in self.line_template_vals.items():
|
||||
test_value = self.contract.contract_line_ids[0][key]
|
||||
try:
|
||||
test_value = test_value.id
|
||||
except AttributeError:
|
||||
pass
|
||||
self.assertEqual(test_value, value)
|
||||
self.assertEqual(len(self.contract.contract_line_ids), 2)
|
||||
for index, vals in [
|
||||
(0, self.section_template_vals),
|
||||
(1, self.line_template_vals)
|
||||
]:
|
||||
contract_line = self.contract.contract_line_ids[index]
|
||||
for key, value in vals.items():
|
||||
test_value = contract_line[key]
|
||||
try:
|
||||
test_value = test_value.id
|
||||
except AttributeError:
|
||||
pass
|
||||
self.assertEqual(test_value, value)
|
||||
|
||||
def test_send_mail_contract(self):
|
||||
result = self.contract.action_contract_send()
|
||||
@@ -2098,6 +2117,12 @@ class TestContract(TestContractBase):
|
||||
'is_canceled': True,
|
||||
}
|
||||
)
|
||||
# section
|
||||
lines |= self.env['contract.line'].create({
|
||||
"contract_id": self.contract.id,
|
||||
"display_type": "line_section",
|
||||
"name": "Test section",
|
||||
})
|
||||
states = [
|
||||
'upcoming',
|
||||
'in-progress',
|
||||
@@ -2105,48 +2130,29 @@ class TestContract(TestContractBase):
|
||||
'upcoming-close',
|
||||
'closed',
|
||||
'canceled',
|
||||
False,
|
||||
]
|
||||
self.assertEqual(set(lines.mapped('state')), set(states))
|
||||
# Test search method
|
||||
for state in states:
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', '=', state)]
|
||||
)
|
||||
self.assertEqual(len(set(lines.mapped('state'))), 1, state)
|
||||
self.assertEqual(lines.mapped('state')[0], state, state)
|
||||
|
||||
for state in states:
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', '!=', state)]
|
||||
)
|
||||
self.assertFalse(state in lines.mapped('state'))
|
||||
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', 'in', states)]
|
||||
)
|
||||
lines = self.env['contract.line'].search([('state', '=', state)])
|
||||
self.assertTrue(lines, state)
|
||||
self.assertTrue(state in lines.mapped('state'), state)
|
||||
lines = self.env['contract.line'].search([('state', '!=', state)])
|
||||
self.assertFalse(state in lines.mapped('state'), state)
|
||||
lines = self.env['contract.line'].search([('state', 'in', states)])
|
||||
self.assertEqual(set(lines.mapped('state')), set(states))
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', 'in', [])]
|
||||
)
|
||||
lines = self.env['contract.line'].search([('state', 'in', [])])
|
||||
self.assertFalse(lines.mapped('state'))
|
||||
with self.assertRaises(TypeError):
|
||||
self.env['contract.line'].search(
|
||||
[('state', 'in', 'upcoming')]
|
||||
)
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', 'not in', [])]
|
||||
)
|
||||
self.env['contract.line'].search([('state', 'in', 'upcoming')])
|
||||
lines = self.env['contract.line'].search([('state', 'not in', [])])
|
||||
self.assertEqual(set(lines.mapped('state')), set(states))
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', 'not in', states)]
|
||||
)
|
||||
lines = self.env['contract.line'].search([('state', 'not in', states)])
|
||||
self.assertFalse(lines.mapped('state'))
|
||||
lines = self.env['contract.line'].search(
|
||||
[('state', 'not in', ['upcoming', 'in-progress'])]
|
||||
)
|
||||
self.assertEqual(
|
||||
set(lines.mapped('state')),
|
||||
set(['to-renew', 'upcoming-close', 'closed', 'canceled']),
|
||||
)
|
||||
state2 = ['upcoming', 'in-progress']
|
||||
lines = self.env['contract.line'].search([('state', 'not in', state2)])
|
||||
self.assertEqual(set(lines.mapped('state')), set(states) - set(state2))
|
||||
|
||||
def test_check_auto_renew_contract_line_with_successor(self):
|
||||
"""
|
||||
@@ -2331,6 +2337,12 @@ class TestContract(TestContractBase):
|
||||
)
|
||||
self.assertFalse(self.acct_line.create_invoice_visibility)
|
||||
self.assertFalse(self.contract.create_invoice_visibility)
|
||||
section = self.env['contract.line'].create({
|
||||
"contract_id": self.contract.id,
|
||||
"display_type": "line_section",
|
||||
"name": "Test section",
|
||||
})
|
||||
self.assertFalse(section.create_invoice_visibility)
|
||||
|
||||
def test_invoice_contract_without_lines(self):
|
||||
self.contract.contract_line_ids.cancel()
|
||||
|
||||
Reference in New Issue
Block a user