Purpose: When running tests, all the tests for the installed/updated
files are done. This commit adds a 'tagged' decorator that can be used to
tag tests. Combined with a new 'test-tags' CLI option, it adds the ability
to filter which tests are executed. For example, @tagged('slow') will
add a tag 'slow' to the test. The CLI option 'test-tags="slow"' will
only run tests tagged 'slow'.
One can use prefixes to select cases with tags.
'+' or no prefix means that the tests tagged with this tag are selected
for execution. '-' prefix will exclude the tests tagged with this tag.
Exclusion takes precedence over inclusion.
Also, by default, all Odoo tests cases are tagged 'standard' and with
the technical name of the module.
This means that when selecting tests with the 'test-tags'
parameter, if '-standard' is not specified, all tests tags are
going to be executed.
When tagging tests, one can remove such automatic tag by prefixing the
tag name with '-'. E.g. @tagged('-standard') will remove the standard
tag from the test.
Another example, if one wants to test the 'sale' module alone,
even without adding any 'tagged' decorator thos tests can be selected
like that: --test-tags="sale"
Tests are selected or deselected using a TagsSelector. When instanciated,
a string is passed with comma separated tests selectors like
'+slow,-standard'. When the 'check' method is called with a test as argument,
it returns True or False if the test has to be executed or not.
73 lines
4.0 KiB
Python
73 lines
4.0 KiB
Python
from odoo.addons.account.tests.account_test_users import AccountTestUsers
|
|
from odoo.tests import tagged
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestSearch(AccountTestUsers):
|
|
|
|
"""Tests for search on name_search (account.account)
|
|
|
|
The name search on account.account is quite complex, make sure
|
|
we have all the correct results
|
|
"""
|
|
|
|
def test_name_search(self):
|
|
ac_ids = self.account_type_model.search([], limit=1)
|
|
self.atax = self.account_model.create(dict(
|
|
name="Tax Received",
|
|
code="X121",
|
|
user_type_id=ac_ids.id,
|
|
reconcile=True,
|
|
)).id, "X121 Tax Received"
|
|
|
|
self.apurchase = self.account_model.create(dict(
|
|
name="Purchased Stocks",
|
|
code="X1101",
|
|
user_type_id=ac_ids.id,
|
|
reconcile=True,
|
|
)).id, "X1101 Purchased Stocks"
|
|
|
|
self.asale = self.account_model.create(dict(
|
|
name="Product Sales",
|
|
code="XX200",
|
|
user_type_id=ac_ids.id,
|
|
reconcile=True,
|
|
)).id, "XX200 Product Sales"
|
|
|
|
self.all_ids = [self.atax[0], self.apurchase[0], self.asale[0]]
|
|
|
|
atax_ids = self.account_model.name_search(name="Tax", operator='ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.atax[0]]), set([a[0] for a in atax_ids]), "name_search 'ilike Tax' should have returned Tax Received account only")
|
|
|
|
atax_ids = self.account_model.name_search(name="Tax", operator='not ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.apurchase[0], self.asale[0]]), set([a[0] for a in atax_ids]), "name_search 'not ilike Tax' should have returned all but Tax Received account")
|
|
|
|
apur_ids = self.account_model.name_search(name='Purchased Stocks', operator='ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.apurchase[0]]), set([a[0] for a in apur_ids]), "name_search 'ilike Purchased Stocks' should have returned Purchased Stocks account only")
|
|
|
|
apur_ids = self.account_model.name_search(name='Purchased Stocks', operator='not ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.atax[0], self.asale[0]]), set([a[0] for a in apur_ids]), "name_search 'not ilike X1101' should have returned all but Purchased Stocks account")
|
|
|
|
asale_ids = self.account_model.name_search(name='Product Sales', operator='ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.asale[0]]), set([a[0] for a in asale_ids]), "name_search 'ilike 200 Sales' should have returned Product Sales account only")
|
|
|
|
asale_ids = self.account_model.name_search(name='Product Sales', operator='not ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.atax[0], self.apurchase[0]]), set([a[0] for a in asale_ids]), "name_search 'not ilike 200 Sales' should have returned all but Product Sales account")
|
|
|
|
asale_ids = self.account_model.name_search(name='XX200', operator='ilike', args=[('id', 'in', self.all_ids)])
|
|
self.assertEqual(set([self.asale[0]]), set([a[0] for a in asale_ids]), "name_search 'ilike XX200' should have returned Product Sales account only")
|
|
|
|
def test_property_unset_search(self):
|
|
res_partner_model = self.env['res.partner']
|
|
account_payment_term_model = self.env['account.payment.term']
|
|
|
|
a_partner = res_partner_model.create({'name': 'test partner'})
|
|
a_payment_term = account_payment_term_model.create({'name': 'test payment term'})
|
|
|
|
partners = res_partner_model.search([('property_payment_term_id', '=', False), ('id', '=', a_partner.id)])
|
|
self.assertTrue(partners, "unset property field 'propety_payment_term' should have been found")
|
|
|
|
a_partner.write({'property_payment_term_id': a_payment_term})
|
|
partners = res_partner_model.search([('property_payment_term_id', '=', False), ('id', '=', a_partner.id)])
|
|
self.assertFalse(partners, "set property field 'propety_payment_term' should not have been found")
|