author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 25 Jul 2014 16:11:46 +0200 | |
changeset 10407 | 18d1ef2d2a3e |
parent 9674 | 96549de9dd70 |
child 10609 | e2d8e81bfe68 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4651
diff
changeset
|
2 |
# 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:
4651
diff
changeset
|
3 |
# 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:
4651
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4651
diff
changeset
|
5 |
# 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:
4651
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4651
diff
changeset
|
7 |
# 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:
4651
diff
changeset
|
8 |
# 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:
4651
diff
changeset
|
9 |
# 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:
4651
diff
changeset
|
10 |
# 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:
4651
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# 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:
4651
diff
changeset
|
13 |
# 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:
4651
diff
changeset
|
14 |
# 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:
4651
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4651
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4651
diff
changeset
|
17 |
# 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:
4651
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
19 |
"""unit tests for database value generator""" |
0 | 20 |
|
21 |
import os.path as osp |
|
22 |
import re |
|
4651
f9cd35dece09
[devtools/fill] fix date generation and its test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4471
diff
changeset
|
23 |
import datetime |
0 | 24 |
|
25 |
from logilab.common.testlib import TestCase, unittest_main |
|
26 |
||
27 |
from cubicweb.devtools.fill import ValueGenerator, make_tel |
|
28 |
from cubicweb.devtools import ApptestConfiguration |
|
29 |
||
30 |
DATADIR = osp.join(osp.abspath(osp.dirname(__file__)), 'data') |
|
31 |
ISODATE_SRE = re.compile('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$') |
|
32 |
||
33 |
||
34 |
class MyValueGenerator(ValueGenerator): |
|
35 |
||
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
36 |
def generate_Bug_severity(self, entity, index): |
0 | 37 |
return u'dangerous' |
38 |
||
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
39 |
def generate_Any_description(self, entity, index, format=None): |
0 | 40 |
return u'yo' |
41 |
||
42 |
||
43 |
class ValueGeneratorTC(TestCase): |
|
44 |
"""test case for ValueGenerator""" |
|
45 |
||
46 |
def _choice_func(self, etype, attrname): |
|
47 |
try: |
|
48 |
return getattr(self, '_available_%s_%s' % (etype, attrname))(etype, attrname) |
|
49 |
except AttributeError: |
|
50 |
return None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
51 |
|
0 | 52 |
def _available_Person_firstname(self, etype, attrname): |
53 |
return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))] |
|
54 |
||
55 |
def setUp(self): |
|
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
56 |
config = ApptestConfiguration('data', apphome=DATADIR) |
0 | 57 |
config.bootstrap_cubes() |
58 |
schema = config.load_schema() |
|
3755
9b973e8eabb3
deprecated api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
59 |
e_schema = schema.eschema('Person') |
0 | 60 |
self.person_valgen = ValueGenerator(e_schema, self._choice_func) |
3755
9b973e8eabb3
deprecated api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
61 |
e_schema = schema.eschema('Bug') |
0 | 62 |
self.bug_valgen = MyValueGenerator(e_schema) |
63 |
self.config = config |
|
64 |
||
65 |
def test_string(self): |
|
66 |
"""test string generation""" |
|
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
67 |
surname = self.person_valgen.generate_attribute_value({}, 'surname', 12) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
68 |
self.assertEqual(surname, u'�&surname12') |
0 | 69 |
|
70 |
def test_domain_value(self): |
|
71 |
"""test value generation from a given domain value""" |
|
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
72 |
firstname = self.person_valgen.generate_attribute_value({}, 'firstname', 12) |
0 | 73 |
possible_choices = self._choice_func('Person', 'firstname') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
74 |
self.assertTrue(firstname in possible_choices, |
0 | 75 |
'%s not in %s' % (firstname, possible_choices)) |
76 |
||
77 |
def test_choice(self): |
|
78 |
"""test choice generation""" |
|
79 |
# Test for random index |
|
80 |
for index in range(5): |
|
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
81 |
sx_value = self.person_valgen.generate_attribute_value({}, 'civility', index) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
82 |
self.assertTrue(sx_value in ('Mr', 'Mrs', 'Ms')) |
0 | 83 |
|
84 |
def test_integer(self): |
|
85 |
"""test integer generation""" |
|
86 |
# Test for random index |
|
87 |
for index in range(5): |
|
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
88 |
cost_value = self.bug_valgen.generate_attribute_value({}, 'cost', index) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
8930
diff
changeset
|
89 |
self.assertIn(cost_value, range(index+1)) |
0 | 90 |
|
91 |
def test_date(self): |
|
92 |
"""test date generation""" |
|
93 |
# Test for random index |
|
4651
f9cd35dece09
[devtools/fill] fix date generation and its test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4471
diff
changeset
|
94 |
for index in range(10): |
4471
71fbc449e814
db fill api has changed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
95 |
date_value = self.person_valgen.generate_attribute_value({}, 'birthday', index) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
96 |
self.assertTrue(isinstance(date_value, datetime.date)) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
97 |
|
0 | 98 |
def test_phone(self): |
99 |
"""tests make_tel utility""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
100 |
self.assertEqual(make_tel(22030405), '22 03 04 05') |
0 | 101 |
|
102 |
def test_customized_generation(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
103 |
self.assertEqual(self.bug_valgen.generate_attribute_value({}, 'severity', 12), |
0 | 104 |
u'dangerous') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
105 |
self.assertEqual(self.bug_valgen.generate_attribute_value({}, 'description', 12), |
0 | 106 |
u'yo') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
107 |
self.assertEqual(self.person_valgen.generate_attribute_value({}, 'description', 12), |
0 | 108 |
u'yo') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
109 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
110 |
|
0 | 111 |
class ConstraintInsertionTC(TestCase): |
112 |
||
113 |
def test_writeme(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
114 |
self.skipTest('Test automatic insertion / Schema Constraints') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
115 |
|
0 | 116 |
|
117 |
if __name__ == '__main__': |
|
118 |
unittest_main() |