web/test/unittest_controller.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 19 Feb 2010 09:34:14 +0100
branchstable
changeset 4643 921737d2e3a8
parent 3460 e4843535db25
child 5421 8167de96c523
permissions -rw-r--r--
fix optimisation with super session that may lead to integrity loss at some point I've decided to stop ensuring ?1 cardinality was respected when adding a new relation using a super session, to avoid the cost of the delete query. That was yet discussable because it introduced unexpected difference between execute and unsafe_execute, which is imo not worth it. Also, now that rql() in migration script default to unsafe_execute, we definitly don't want that implicit behaviour change (which already cause bug when for instance adding another default workflow for an entity type: without that fix we end up with *two* default workflows while the schema tells we can have only one. IMO we should go to the direction that super session skip all security check, but nothing else, unless explicitly asked.

"""cubicweb.web.controller unit tests

:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""

from datetime import datetime, date, time

from logilab.common.testlib import unittest_main

from cubicweb.devtools import testlib

class BaseControllerTC(testlib.CubicWebTC):

    def test_parse_datetime_ok(self):
        ctrl = self.vreg['controllers'].select('view', self.request())
        pd = ctrl._cw.parse_datetime
        self.assertIsInstance(pd('2006/06/24 12:18'), datetime)
        self.assertIsInstance(pd('2006/06/24'), date)
        self.assertIsInstance(pd('2006/06/24 12:18', 'Datetime'), datetime)
        self.assertIsInstance(pd('2006/06/24', 'Datetime'), datetime)
        self.assertIsInstance(pd('2006/06/24', 'Date'), date)
        self.assertIsInstance(pd('12:18', 'Time'), time)

    def test_parse_datetime_ko(self):
        ctrl = self.vreg['controllers'].select('view', self.request())
        pd = ctrl._cw.parse_datetime
        self.assertRaises(ValueError,
                          pd, '2006/06/24 12:188', 'Datetime')
        self.assertRaises(ValueError,
                          pd, '2006/06/240', 'Datetime')
        self.assertRaises(ValueError,
                          pd, '2006/06/24 12:18', 'Date')
        self.assertRaises(ValueError,
                          pd, '2006/24/06', 'Date')
        self.assertRaises(ValueError,
                          pd, '2006/06/240', 'Date')
        self.assertRaises(ValueError,
                          pd, '12:188', 'Time')

if __name__ == '__main__':
    unittest_main()