[Erp5-report] r44048 vincent - in /erp5/trunk/products/ZSQLCatalog: SearchKey/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Mar 8 15:14:33 CET 2011
Author: vincent
Date: Tue Mar 8 15:14:33 2011
New Revision: 44048
URL: http://svn.erp5.org?rev=44048&view=rev
Log:
Fix DateTimeKey behaviour toward bogus values.
DateTimeKey is capable of completing dates given with less than 3 parts (year,
month and day). This means less than 2 separators, not 3.
Also, be resilient to string which, when split by separators, generate an empty
list.
Add test cases.
Modified:
erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py
erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py?rev=44048&r1=44047&r2=44048&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py [utf8] Tue Mar 8 15:14:33 2011
@@ -72,7 +72,7 @@ def castDate(value):
value = _DateTime(value, **date_kw)
except DateTimeError:
delimiter_count = countDelimiters(value)
- if delimiter_count < 3:
+ if delimiter_count is not None and delimiter_count < 2:
split_value = value.split()
if split_value[-1].lower() in timezone_dict:
value = '%s %s' % (date_completion_format_dict[date_kw.get('datefmt')][delimiter_count] % (' '.join(split_value[:-1]), ), split_value[-1])
@@ -101,6 +101,8 @@ def countDelimiters(value):
assert isinstance(value, basestring)
# Detect if timezone was provided, to avoid counting it as in precision computation.
split_value = value.split()
+ if not split_value:
+ return None
if split_value[-1].lower() in timezone_dict:
value = ' '.join(split_value[:-1])
# Count delimiters
Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=44048&r1=44047&r2=44048&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Tue Mar 8 15:14:33 2011
@@ -363,6 +363,20 @@ class TestSQLCatalog(unittest.TestCase):
def test_DateTimeKey(self):
self._testDateTimeKey('date')
+ # XXX: It is unknown what these tests should produce when used with a
+ # related key: should the join happen or not ?
+ self.catalog(
+ ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
+ {'date': ' '})
+ self.catalog(
+ ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
+ {'date': '<>2008/01/01'})
+ self.catalog(
+ ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
+ {'date': '<'})
+ self.catalog(
+ ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
+ {'date': '00:00:00'})
def test_relatedDateTimeKey(self):
self._testDateTimeKey('related_date')
More information about the Erp5-report
mailing list