29 def _choice_func(self, etype, attrname): |
29 def _choice_func(self, etype, attrname): |
30 try: |
30 try: |
31 return getattr(self, '_available_%s_%s' % (etype, attrname))(etype, attrname) |
31 return getattr(self, '_available_%s_%s' % (etype, attrname))(etype, attrname) |
32 except AttributeError: |
32 except AttributeError: |
33 return None |
33 return None |
34 |
34 |
35 def _available_Person_firstname(self, etype, attrname): |
35 def _available_Person_firstname(self, etype, attrname): |
36 return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))] |
36 return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))] |
37 |
37 |
38 |
38 |
39 def setUp(self): |
39 def setUp(self): |
49 def _check_date(self, date): |
49 def _check_date(self, date): |
50 """checks that 'date' is well-formed""" |
50 """checks that 'date' is well-formed""" |
51 year = date.year |
51 year = date.year |
52 month = date.month |
52 month = date.month |
53 day = date.day |
53 day = date.day |
54 self.failUnless(day in range(1, 29), '%s not in [0;28]' % day) |
54 self.failUnless(day in range(1, 29), '%s not in [0;28]' % day) |
55 self.failUnless(month in range(1, 13), '%s not in [1;12]' % month) |
55 self.failUnless(month in range(1, 13), '%s not in [1;12]' % month) |
56 self.failUnless(year in range(2000, 2005), |
56 self.failUnless(year in range(2000, 2005), |
57 '%s not in [2000;2004]' % year) |
57 '%s not in [2000;2004]' % year) |
58 |
58 |
59 |
59 |
60 def test_string(self): |
60 def test_string(self): |
61 """test string generation""" |
61 """test string generation""" |
62 surname = self.person_valgen._generate_value('surname', 12) |
62 surname = self.person_valgen._generate_value('surname', 12) |
63 self.assertEquals(surname, u'é&surname12') |
63 self.assertEquals(surname, u'é&surname12') |
87 """test date generation""" |
87 """test date generation""" |
88 # Test for random index |
88 # Test for random index |
89 for index in range(5): |
89 for index in range(5): |
90 date_value = self.person_valgen._generate_value('birthday', index) |
90 date_value = self.person_valgen._generate_value('birthday', index) |
91 self._check_date(date_value) |
91 self._check_date(date_value) |
92 |
92 |
93 def test_phone(self): |
93 def test_phone(self): |
94 """tests make_tel utility""" |
94 """tests make_tel utility""" |
95 self.assertEquals(make_tel(22030405), '22 03 04 05') |
95 self.assertEquals(make_tel(22030405), '22 03 04 05') |
96 |
96 |
97 |
97 |
100 u'dangerous') |
100 u'dangerous') |
101 self.assertEquals(self.bug_valgen._generate_value('description', 12), |
101 self.assertEquals(self.bug_valgen._generate_value('description', 12), |
102 u'yo') |
102 u'yo') |
103 self.assertEquals(self.person_valgen._generate_value('description', 12), |
103 self.assertEquals(self.person_valgen._generate_value('description', 12), |
104 u'yo') |
104 u'yo') |
105 |
105 |
106 |
106 |
107 |
107 |
108 class ConstraintInsertionTC(TestCase): |
108 class ConstraintInsertionTC(TestCase): |
109 |
109 |
110 def test_writeme(self): |
110 def test_writeme(self): |
111 self.skip('Test automatic insertion / Schema Constraints') |
111 self.skip('Test automatic insertion / Schema Constraints') |
112 |
112 |
113 |
113 |
114 if __name__ == '__main__': |
114 if __name__ == '__main__': |
115 unittest_main() |
115 unittest_main() |