source: main/waeup.sirp/branches/ulif-images/src/waeup/sirp/jambtables/tests/test_applicants.py @ 10385

Last change on this file since 10385 was 5478, checked in by uli, 14 years ago

Add unit tests for applicant components.

File size: 4.6 KB
Line 
1##
2## test_applicants.py
3## Login : <uli@pu.smp.net>
4## Started on  Tue Aug 24 04:36:11 2010 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2010 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"""Tests for applicants and related.
23"""
24import logging
25import unittest
26from StringIO import StringIO
27from zope.component.interfaces import IFactory
28from zope.interface import verify
29from waeup.sirp.interfaces import IWAeUPSIRPPluggable
30from waeup.sirp.jambtables import (
31    ResultEntry, Applicant, ApplicantFactory, ApplicantContainer,
32    ApplicantsPlugin,
33    )
34from waeup.sirp.jambtables.interfaces import (
35    IResultEntry, IApplicant, IApplicantContainer,
36    )
37
38class ResultEntryTest(unittest.TestCase):
39
40    def setUp(self):
41        self.result_entry = ResultEntry()
42        return
43
44    def tearDown(self):
45        pass
46
47    def test_interfaces(self):
48        verify.verifyClass(IResultEntry, ResultEntry)
49        verify.verifyObject(IResultEntry, self.result_entry)
50
51    def test_resultentry(self):
52        entry = ResultEntry('Some subject', 3.7)
53        assert entry.subject == 'Some subject'
54        assert entry.score == 3.7
55
56class ApplicantTest(unittest.TestCase):
57
58    def setUp(self):
59        self.applicant = Applicant()
60
61    def tearDown(self):
62        pass
63
64    def test_interfaces(self):
65        verify.verifyClass(IApplicant, Applicant)
66        verify.verifyObject(IApplicant, self.applicant)
67
68class ApplicantFactoryTest(unittest.TestCase):
69
70    def setUp(self):
71        self.factory = ApplicantFactory()
72
73    def tearDown(self):
74        pass
75
76    def test_interfaces(self):
77        verify.verifyClass(IFactory, ApplicantFactory)
78        verify.verifyObject(IFactory, self.factory)
79
80    def test_factory(self):
81        obj = self.factory()
82        assert isinstance(obj, Applicant)
83
84    def test_getInterfaces(self):
85        implemented_by = self.factory.getInterfaces()
86        assert implemented_by.isOrExtends(IApplicant)
87
88class ApplicantContainerTest(unittest.TestCase):
89
90    def setUp(self):
91        self.container = ApplicantContainer()
92        return
93
94    def tearDown(self):
95        pass
96
97    def test_interfaces(self):
98        verify.verifyClass(IApplicantContainer, ApplicantContainer)
99        verify.verifyObject(IApplicantContainer, self.container)
100
101class ApplicantsPluginTest(unittest.TestCase):
102
103    def setUp(self):
104        self.plugin = ApplicantsPlugin()
105        self.site1 = dict()
106        self.site2 = dict(applications = True)
107        self.log_stream = StringIO()#.open('w')
108        handler = logging.StreamHandler(self.log_stream)
109        self.logger = logging.getLogger('waeup.sirp.testing')
110        self.logger.addHandler(handler)
111        self.logger.propagate = False
112        self.logger.setLevel(logging.DEBUG)
113       
114    def tearDown(self):
115        handlers = self.logger.handlers
116        for handler in handlers:
117            del handler
118        pass
119
120    def notest_interfaces(self):
121        verify.verifyClass(IWAeUPSIRPPluggable, ApplicantsPlugin)
122        verify.verifyObject(IWAeUPSIRPPluggable, self.plugin)
123
124    def test_setup(self):
125        self.plugin.setup(self.site1, 'some.site', self.logger)
126        assert 'Installed application container' in self.log_stream.getvalue()
127        assert 'applications' in self.site1.keys()
128
129    def test_update_empty_site(self):
130        self.plugin.update(self.site1, 'some.site', self.logger)
131        assert 'Updating site' in self.log_stream.getvalue()
132        assert 'Installing' in self.log_stream.getvalue()
133
134    def test_update_filled_site(self):
135        self.plugin.update(self.site2, 'some.site', self.logger)
136        assert 'Nothing to do' in self.log_stream.getvalue()
137       
138
139def test_suite():
140    suite = unittest.TestSuite()
141    for testcase in [
142        ResultEntryTest, ApplicantTest, ApplicantFactoryTest,
143        ApplicantContainerTest, ApplicantsPluginTest,
144        ]:
145        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
146                testcase
147                )
148        )
149    return suite
Note: See TracBrowser for help on using the repository browser.