source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicants.py @ 6412

Last change on this file since 6412 was 6297, checked in by uli, 14 years ago

Fix testing problems simply by turning basic unittests into functional
ones.

File size: 5.1 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 unittest
25from zope.app.testing.functional import FunctionalTestCase
26from zope.component import (
27    provideAdapter, adapts, getGlobalSiteManager, provideUtility)
28from zope.component.interfaces import IFactory
29from zope.interface import verify, implements
30from zope.location.interfaces import ILocation
31from zope.publisher.base import TestRequest
32from zope.publisher.interfaces import NotFound
33from waeup.sirp.image.image import WAeUPImageFile
34from waeup.sirp.image.interfaces import IWAeUPImageFile
35from waeup.sirp.applicants import (
36    ResultEntry, Applicant, ApplicantFactory, ApplicantTraverser,
37    )
38from waeup.sirp.applicants.interfaces import (
39    IResultEntry, IApplicant,
40    )
41from waeup.sirp.testing import FunctionalLayer
42
43class FakeImageLocation(object):
44    implements(ILocation)
45    adapts(IWAeUPImageFile)
46    def __init__(self, context):
47        pass
48
49class ResultEntryTest(unittest.TestCase):
50
51    def setUp(self):
52        self.result_entry = ResultEntry()
53        return
54
55    def tearDown(self):
56        pass
57
58    def test_interfaces(self):
59        verify.verifyClass(IResultEntry, ResultEntry)
60        verify.verifyObject(IResultEntry, self.result_entry)
61
62    def test_resultentry(self):
63        entry = ResultEntry('Some subject', 3.7)
64        assert entry.subject == 'Some subject'
65        assert entry.score == 3.7
66
67class ApplicantTest(FunctionalTestCase):
68
69    layer = FunctionalLayer
70
71    def setUp(self):
72        self.applicant = Applicant()
73
74    def tearDown(self):
75        pass
76
77    def test_interfaces(self):
78        verify.verifyClass(IApplicant, Applicant)
79        verify.verifyObject(IApplicant, self.applicant)
80
81class ApplicantFactoryTest(FunctionalTestCase):
82
83    layer = FunctionalLayer
84
85    def setUp(self):
86        self.factory = ApplicantFactory()
87
88    def tearDown(self):
89        pass
90
91    def test_interfaces(self):
92        verify.verifyClass(IFactory, ApplicantFactory)
93        verify.verifyObject(IFactory, self.factory)
94
95    def test_factory(self):
96        obj = self.factory()
97        assert isinstance(obj, Applicant)
98
99    def test_getInterfaces(self):
100        implemented_by = self.factory.getInterfaces()
101        assert implemented_by.isOrExtends(IApplicant)
102
103
104class ApplicantTraverserTest(FunctionalTestCase):
105
106    layer = FunctionalLayer
107
108    def setUp(self):
109        super(ApplicantTraverserTest, self).setUp()
110        provideAdapter(FakeImageLocation)
111        self.applicant = Applicant()
112
113        self.request = TestRequest('')
114        return
115
116    def tearDown(self):
117        gsm = getGlobalSiteManager()
118        gsm.unregisterAdapter(FakeImageLocation)
119        super(ApplicantTraverserTest, self).tearDown()
120        return
121
122    def test_traverse_wo_passport(self):
123        # Ask for some attribute not provided
124        traverser = ApplicantTraverser(
125            self.applicant, self.request
126            )
127        self.assertRaises(
128            NotFound,
129            traverser.publishTraverse, self.request, 'passport'
130            )
131        return
132
133    def test_traverse_wo_image_passport_jpg(self):
134        # Ask for applicant pic if we didn't provided one
135        # We get a placeholder.
136        traverser = ApplicantTraverser(
137            self.applicant, self.request
138            )
139        result = traverser.publishTraverse(self.request, 'passport.jpg')
140        self.assertTrue(isinstance(result, FakeImageLocation))
141        return
142
143    def test_traverse_w_image_passport_jpg(self):
144        # Ask for applicant pic that's named 'passport.jpg'
145        traverser = ApplicantTraverser(
146            self.applicant, self.request
147            )
148        self.applicant.passport = WAeUPImageFile('nofile.jpg', '')
149        self.applicant.passport.filename = 'mypic.jpg'
150        result = traverser.publishTraverse(self.request, 'passport.jpg')
151        self.assertTrue(isinstance(result, FakeImageLocation))
152        return
153
154    def test_traverse_w_image_some_jpg(self):
155        # Ask for applicant pic by correct name
156        traverser = ApplicantTraverser(
157            self.applicant, self.request
158            )
159        self.applicant.passport = WAeUPImageFile('nofile.jpg', '')
160        self.applicant.passport.filename = 'mypic.jpg'
161        result = traverser.publishTraverse(self.request, 'mypic.jpg')
162        self.assertTrue(isinstance(result, FakeImageLocation))
163        return
Note: See TracBrowser for help on using the repository browser.