From aaec909b626f5cfc91496209638c876405a9b7cb Mon Sep 17 00:00:00 2001 From: nans Date: Sun, 11 Oct 2020 21:17:43 +0200 Subject: [PATCH] [TEST] base_partition: add coverage --- base_partition/__manifest__.py | 2 +- base_partition/tests/test_partition.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/base_partition/__manifest__.py b/base_partition/__manifest__.py index fcdebbaa0..a68fdf91b 100644 --- a/base_partition/__manifest__.py +++ b/base_partition/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Base Partition", "summary": "Base module that provide the partition method on all models", - "version": "12.0.0.0.0", + "version": "12.0.1.0.0", "category": "Uncategorized", "website": "https://github.com/OCA/server-tools", "author": "Acsone, Odoo Community Association (OCA)", diff --git a/base_partition/tests/test_partition.py b/base_partition/tests/test_partition.py index 031ed825c..1fcb720c8 100644 --- a/base_partition/tests/test_partition.py +++ b/base_partition/tests/test_partition.py @@ -3,7 +3,9 @@ import functools import math +from datetime import datetime +from odoo import fields from odoo.exceptions import UserError from odoo.tests.common import TransactionCase @@ -88,6 +90,11 @@ class TestPartition(TransactionCase): records = functools.reduce(sum, partition.values()) self.assertEqual(self.xyz, records) # we get the same recordset + def test_partition_lambda(self): + """Test an arbitrary predicate.""" + partition = (self.c1 | self.c2).partition(lambda c: "2" in c.name) + self.assertEqual(set(partition.keys()), {True, False}) + def test_batch(self): """The sum of all batches should be the original recordset; an empty recordset should return no batch; @@ -127,7 +134,7 @@ class TestPartition(TransactionCase): self.assertEqual(list(record_data.keys()), field_list) def test_filtered_domain(self): - """Initially yo satisfy the coverage tools, this test actually documents + """Initially to satisfy the coverage tools, this test actually documents a number of pitfalls of filtered_domain and the differences with a search. Commented examples would cause warnings, and even though these are edge-cases these behaviours should be known. @@ -182,3 +189,17 @@ class TestPartition(TransactionCase): # eq_domain = [(field, "=", r[field].ids)] # self.assertEqual(self.xyz.search(eq_domain), self.xyz) # self.assertEqual(self.xyz.filtered_domain(eq_domain), empty_recordset) + + # coverage + records.filtered_domain(["!", (1, "=", 1)]) + for operator in ["<", ">", "<=", ">="]: + date_now_str = fields.Datetime.to_string(datetime.now()) + records.filtered_domain([("create_date", operator, date_now_str)]) + for operator in ["!=", "like", "not like", "=?", "ilike", "=like", "not ilike"]: + records.filtered_domain([("name", operator, "c")]) + records.filtered_domain( + ["&", ("parent_id.id", "in", [self.parent1.id]), (1, "=", 1)] + ) + records.filtered_domain(["|", ("parent_id", "child_of", [42]), (0, "=", 1)]) + with self.assertRaises(ValueError): + records.filtered_domain([("name", "===", "test")])