author | Julien Cristau <julien.cristau@logilab.fr> |
Wed, 02 Apr 2014 17:03:46 +0200 | |
changeset 9644 | 2683c9f9a6b7 |
parent 5424 | 8ecbcbff9777 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""cubicweb.web.controller unit tests |
19 |
||
20 |
""" |
|
21 |
||
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
22 |
from datetime import datetime, date, time |
0 | 23 |
|
24 |
from logilab.common.testlib import unittest_main |
|
25 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
26 |
from cubicweb.devtools import testlib |
0 | 27 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
28 |
class BaseControllerTC(testlib.CubicWebTC): |
1654 | 29 |
|
30 |
def test_parse_datetime_ok(self): |
|
9644
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
31 |
with self.admin_access.web_request() as req: |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
32 |
ctrl = self.vreg['controllers'].select('view', req) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
33 |
pd = ctrl._cw.parse_datetime |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
34 |
self.assertIsInstance(pd('2006/06/24 12:18'), datetime) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
35 |
self.assertIsInstance(pd('2006/06/24'), date) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
36 |
self.assertIsInstance(pd('2006/06/24 12:18', 'Datetime'), datetime) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
37 |
self.assertIsInstance(pd('2006/06/24', 'Datetime'), datetime) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
38 |
self.assertIsInstance(pd('2006/06/24', 'Date'), date) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
39 |
self.assertIsInstance(pd('12:18', 'Time'), time) |
1654 | 40 |
|
41 |
def test_parse_datetime_ko(self): |
|
9644
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
42 |
with self.admin_access.web_request() as req: |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
43 |
ctrl = self.vreg['controllers'].select('view', req) |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
44 |
pd = ctrl._cw.parse_datetime |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
45 |
self.assertRaises(ValueError, |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
46 |
pd, '2006/06/24 12:188', 'Datetime') |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
47 |
self.assertRaises(ValueError, |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
48 |
pd, '2006/06/240', 'Datetime') |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
49 |
self.assertRaises(ValueError, |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
50 |
pd, '2006/06/24 12:18', 'Date') |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
51 |
self.assertRaises(ValueError, |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
52 |
pd, '2006/24/06', 'Date') |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
53 |
self.assertRaises(ValueError, |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
54 |
pd, '2006/06/240', 'Date') |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
55 |
self.assertRaises(ValueError, |
2683c9f9a6b7
[web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents:
5424
diff
changeset
|
56 |
pd, '12:188', 'Time') |
1654 | 57 |
|
0 | 58 |
if __name__ == '__main__': |
59 |
unittest_main() |