From 76a63f40eebd52491048dde614cf36cea4f3726f Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 17 Jan 2019 09:25:43 +0100 Subject: [PATCH] Better tests --- .../tests/test_account_invoice_spread.py | 33 +++++++++++-------- .../tests/test_account_spread_cost_revenue.py | 24 +++++++++----- .../tests/test_compute_spread_board.py | 30 ++++++++++------- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/account_spread_cost_revenue/tests/test_account_invoice_spread.py b/account_spread_cost_revenue/tests/test_account_invoice_spread.py index e0648987..01e0d559 100644 --- a/account_spread_cost_revenue/tests/test_account_invoice_spread.py +++ b/account_spread_cost_revenue/tests/test_account_invoice_spread.py @@ -25,24 +25,31 @@ class TestAccountInvoiceSpread(common.TransactionCase): type_receivable = self.env.ref('account.data_account_type_receivable') type_payable = self.env.ref('account.data_account_type_payable') - def get_account(obj): - return self.env['account.account'].search([ - ('user_type_id', '=', obj.id), - ('reconcile', '=', True), - ], limit=1) + self.invoice_account = self.env['account.account'].create({ + 'name': 'test_account_receivable', + 'code': '123', + 'user_type_id': type_receivable.id, + 'reconcile': True + }) - self.invoice_account = get_account(type_receivable) - self.invoice_line_account = get_account(type_payable) + self.invoice_line_account = self.env['account.account'].create({ + 'name': 'test_account_payable', + 'code': '321', + 'user_type_id': type_payable.id, + 'reconcile': True + }) - self.spread_account = self.env['account.account'].search([ - ('user_type_id', '=', type_payable.id), - ('id', '!=', self.invoice_line_account.id) - ], limit=1) + self.spread_account = self.env['account.account'].create({ + 'name': 'test spread account_payable', + 'code': '765', + 'user_type_id': type_payable.id, + 'reconcile': True + }) - partner = self.env['res.partner'].create({ + partner = self.env['res.partner'].create([{ 'name': 'Partner Name', 'supplier': True, - }) + }]) self.invoice = self.env['account.invoice'].create({ 'partner_id': partner.id, 'account_id': self.invoice_account.id, diff --git a/account_spread_cost_revenue/tests/test_account_spread_cost_revenue.py b/account_spread_cost_revenue/tests/test_account_spread_cost_revenue.py index 5573df68..b0e1def1 100644 --- a/account_spread_cost_revenue/tests/test_account_spread_cost_revenue.py +++ b/account_spread_cost_revenue/tests/test_account_spread_cost_revenue.py @@ -24,19 +24,25 @@ class TestAccountSpreadCostRevenue(common.TransactionCase): super().setUp() self._load('account', 'test', 'account_minimal_test.xml') - def get_account(obj): - return self.env['account.account'].search([ - ('user_type_id', '=', obj.id) - ], limit=1) - type_receivable = self.env.ref('account.data_account_type_receivable') type_expenses = self.env.ref('account.data_account_type_expenses') - self.credit_account = get_account(type_receivable) - self.debit_account = get_account(type_expenses) + self.credit_account = self.env['account.account'].create({ + 'name': 'test_account_receivable', + 'code': '123', + 'user_type_id': type_receivable.id, + 'reconcile': True + }) + + self.debit_account = self.env['account.account'].create({ + 'name': 'test account_expenses', + 'code': '765', + 'user_type_id': type_expenses.id, + 'reconcile': True + }) def test_01_account_spread_defaults(self): - + this_year = datetime.date.today().year spread = self.env['account.spread'].create({ 'name': 'test', 'invoice_type': 'out_invoice', @@ -65,7 +71,7 @@ class TestAccountSpreadCostRevenue(common.TransactionCase): self.assertEqual(spread.unposted_amount, 0.) self.assertEqual(spread.total_amount, 0.) self.assertEqual(spread.estimated_amount, 0.) - self.assertEqual(spread.spread_date, datetime.date(2018, 1, 1)) + self.assertEqual(spread.spread_date, datetime.date(this_year, 1, 1)) self.assertTrue(spread.journal_id) self.assertEqual(spread.journal_id.type, 'general') diff --git a/account_spread_cost_revenue/tests/test_compute_spread_board.py b/account_spread_cost_revenue/tests/test_compute_spread_board.py index e205ca3a..c16cdfdd 100644 --- a/account_spread_cost_revenue/tests/test_compute_spread_board.py +++ b/account_spread_cost_revenue/tests/test_compute_spread_board.py @@ -14,22 +14,30 @@ class TestComputeSpreadBoard(common.TransactionCase): type_receivable = self.env.ref('account.data_account_type_receivable') type_expenses = self.env.ref('account.data_account_type_expenses') - def get_account(obj): - return self.env['account.account'].search([ - ('user_type_id', '=', obj.id) - ], limit=1) - journal = self.env['account.journal'].search([ ('type', '=', 'general')], limit=1) - self.receivable_account = get_account(type_receivable) - self.expense_account = get_account(type_expenses) + self.receivable_account = self.env['account.account'].create({ + 'name': 'test_account_receivable', + 'code': '123', + 'user_type_id': type_receivable.id, + 'reconcile': True + }) - self.spread_account = self.env['account.account'].search([ - ('user_type_id', '=', type_expenses.id), - ('id', '!=', self.expense_account.id) - ], limit=1) + self.expense_account = self.env['account.account'].create({ + 'name': 'test account_expenses', + 'code': '765', + 'user_type_id': type_expenses.id, + 'reconcile': True + }) + + self.spread_account = self.env['account.account'].create({ + 'name': 'test spread account_expenses', + 'code': '321', + 'user_type_id': type_expenses.id, + 'reconcile': True + }) self.spread = self.env['account.spread'].create({ 'name': 'test',