1 | ## |
---|
2 | ## test_interfaces.py |
---|
3 | ## Login : <uli@pu.smp.net> |
---|
4 | ## Started on Tue Jan 25 17:09:46 2011 Uli Fouquet |
---|
5 | ## $Id$ |
---|
6 | ## |
---|
7 | ## Copyright (C) 2011 Uli Fouquet |
---|
8 | ## This program is free software; you can redistribute it and/or modify |
---|
9 | ## it under the terms of the GNU General Public License as published by |
---|
10 | ## the Free Software Foundation; either version 2 of the License, or |
---|
11 | ## (at your option) any later version. |
---|
12 | ## |
---|
13 | ## This program is distributed in the hope that it will be useful, |
---|
14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | ## GNU General Public License for more details. |
---|
17 | ## |
---|
18 | ## You should have received a copy of the GNU General Public License |
---|
19 | ## along with this program; if not, write to the Free Software |
---|
20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
21 | ## |
---|
22 | """ |
---|
23 | Test components defined in interface module. |
---|
24 | """ |
---|
25 | import unittest |
---|
26 | from zc.sourcefactory.browser.source import FactoredTerms |
---|
27 | from zope.browser.interfaces import ITerms |
---|
28 | from zope.component import getMultiAdapter |
---|
29 | from zope.interface.verify import verifyClass, verifyObject |
---|
30 | from zope.publisher.browser import TestRequest |
---|
31 | from waeup.sirp.applicants import interfaces |
---|
32 | from waeup.sirp.applicants.vocabularies import ( |
---|
33 | APPLICATION_TYPES, application_types_vocab, GenderSource, |
---|
34 | ) |
---|
35 | |
---|
36 | class ApplicationCategoriesTestCase(unittest.TestCase): |
---|
37 | |
---|
38 | def setUp(self): |
---|
39 | self.vocab = application_types_vocab |
---|
40 | return |
---|
41 | |
---|
42 | def test_vocabulary_len(self): |
---|
43 | self.assertEqual(len(self.vocab), 10) |
---|
44 | return |
---|
45 | |
---|
46 | def test_vocabulary_items(self): |
---|
47 | self.assertTrue('pude' in self.vocab) |
---|
48 | return |
---|
49 | |
---|
50 | def test_term_attributes(self): |
---|
51 | # Check that each vocab entry provided value, token, and title. |
---|
52 | term = self.vocab.getTermByToken('pude') |
---|
53 | self.assertEqual(term.token, 'pude') |
---|
54 | self.assertEqual(term.value, 'pude') |
---|
55 | self.assertEqual(term.title, 'Post UDE Screening') |
---|
56 | return |
---|
57 | |
---|
58 | class InterfacesTest(unittest.TestCase): |
---|
59 | |
---|
60 | def setUp(self): |
---|
61 | self.source = GenderSource() |
---|
62 | self.request = TestRequest() |
---|
63 | self.terms = FactoredTerms(self.source, self.request) |
---|
64 | return |
---|
65 | |
---|
66 | def tearDown(self): |
---|
67 | pass |
---|
68 | |
---|
69 | def test_GenderSource_list(self): |
---|
70 | result = list(self.source) |
---|
71 | self.assertEqual(result, ['m', 'f']) |
---|
72 | |
---|
73 | def test_GenderSource_term_male(self): |
---|
74 | term = self.terms.getTerm('m') |
---|
75 | assert term.title == 'male' |
---|
76 | assert term.token == 'm' |
---|
77 | assert term.value == 'm' |
---|
78 | |
---|
79 | def test_GenderSource_term_female(self): |
---|
80 | term = self.terms.getTerm('f') |
---|
81 | assert term.title == 'female' |
---|
82 | assert term.token == 'f' |
---|
83 | assert term.value == 'f' |
---|
84 | |
---|
85 | def test_GernderSource_term_invalid(self): |
---|
86 | term_inv = self.terms.getTerm('Invalid') |
---|
87 | assert term_inv.title is None |
---|
88 | assert term_inv.token == 'i' |
---|
89 | |
---|
90 | def suite(): |
---|
91 | suite = unittest.TestSuite() |
---|
92 | for testcase in [ |
---|
93 | ApplicationCategoriesTestCase, |
---|
94 | InterfacesTest, |
---|
95 | ]: |
---|
96 | suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase)) |
---|
97 | return suite |
---|
98 | |
---|
99 | test_suite = suite |
---|
100 | |
---|
101 | |
---|