Browse Source

[ADD] tests

pull/480/head
Holger Brunn 9 years ago
parent
commit
f5f03e1b89
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 2
      field_rrule/README.rst
  2. 5
      field_rrule/field_rrule.py
  3. 55
      field_rrule/tests/test_field_rrule.py

2
field_rrule/README.rst

@ -25,7 +25,7 @@ If you want to pass a default, use the internal representation you'll find in th
In case you work with defaults and want to dumb down the UI a bit, use ``{'no_add_rule': true}``. In case you work with defaults and want to dumb down the UI a bit, use ``{'no_add_rule': true}``.
Further, as this is a serialized field, a value of `not set` will be represented in the database as ``'null'`` - this is then also what you have to search for when you need records with your field unset.
Further, as this is a serialized field, a value of `not set` will be represented in the database as ``'null'`` if the value was set and unset afterwards, or a database ``null`` if the value was never set - this is then also what you have to search for when you need records with your field unset.
Known issues / Roadmap Known issues / Roadmap
====================== ======================

5
field_rrule/field_rrule.py

@ -46,7 +46,7 @@ class SerializableRRuleSet(rruleset, list):
"""convert self to a proper rruleset for iteration. """convert self to a proper rruleset for iteration.
If we use defaults on our field, this will be called too with If we use defaults on our field, this will be called too with
and empty recordset as parameter. In this case, we need self""" and empty recordset as parameter. In this case, we need self"""
if isinstance(default_self, models.Model):
if isinstance(default_self, models.BaseModel):
return self return self
result = rruleset() result = rruleset()
result._rrule = self._rrule result._rrule = self._rrule
@ -55,9 +55,6 @@ class SerializableRRuleSet(rruleset, list):
result._exdate = self._exdate result._exdate = self._exdate
return result return result
def __exit__(self):
pass
def __nonzero__(self): def __nonzero__(self):
return bool(self._rrule) return bool(self._rrule)

55
field_rrule/tests/test_field_rrule.py

@ -1,9 +1,62 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl> # © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from dateutil.rrule import MONTHLY, rrule
from openerp import SUPERUSER_ID, fields, models
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
from openerp.addons.field_rrule import FieldRRule
from openerp.addons.field_rrule.field_rrule import SerializableRRuleSet
class RRuleTest(models.TransientModel):
_name = 'test.field.rrule'
# either use a default in object notation
rrule_with_default = FieldRRule(default=[{
"type": "rrule",
"dtstart": '2016-01-02 00:00:00',
"count": 1,
"freq": MONTHLY,
"interval": 1,
"bymonthday": [1],
}])
# or pass a SerializableRRuleSet.
# Rember that this class is callable, so passing it directly as default
# would actually pass an rruleset, because odoo uses the result of the
# callable. But in __call__, we check for this case, so nothing to do
rrule_with_default2 = FieldRRule(default=SerializableRRuleSet(
rrule(
dtstart=fields.Datetime.from_string('2016-01-02 00:00:00'),
interval=1,
freq=MONTHLY,
count=1,
bymonthday=[1],
)))
# also fiddle with an empty one
rrule = FieldRRule()
class TestFieldRrule(TransactionCase): class TestFieldRrule(TransactionCase):
def test_field_rrule(self): def test_field_rrule(self):
pass
model = RRuleTest._build_model(self.registry, self.cr)
model._prepare_setup(self.cr, SUPERUSER_ID, False)
model._setup_base(self.cr, SUPERUSER_ID, False)
model._setup_fields(self.cr, SUPERUSER_ID)
model._auto_init(self.cr)
record_id = model.create(self.cr, SUPERUSER_ID, {'rrule': None})
self.cr.execute(
'select rrule, rrule_with_default, rrule_with_default2 from '
'%s where id=%%s' % model._table, (record_id,))
data = self.cr.fetchall()[0]
self.assertEqual(data[0], 'null')
self.assertEqual(data[1], data[2])
record = model.browse(self.cr, SUPERUSER_ID, record_id)
self.assertFalse(record.rrule)
self.assertTrue(record.rrule_with_default)
self.assertTrue(record.rrule_with_default2)
self.assertEqual(record.rrule_with_default, record.rrule_with_default2)
self.assertEqual(record.rrule_with_default.count(), 1)
self.assertFalse(record.rrule_with_default.after(
fields.Datetime.from_string('2016-02-01 00:00:00')))
self.assertTrue(record.rrule_with_default.after(
fields.Datetime.from_string('2016-02-01 00:00:00'), inc=True))
Loading…
Cancel
Save