Changeset 5764 for main/waeup.sirp/trunk/src
- Timestamp:
- 13 Feb 2011, 14:40:24 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicants.py
r5756 r5764 25 25 import unittest 26 26 from StringIO import StringIO 27 from zope.app.file.interfaces import IImage 28 from zope.component import provideAdapter, adapts, getGlobalSiteManager 27 29 from zope.component.interfaces import IFactory 28 from zope.interface import verify 30 from zope.interface import verify, implements 31 from zope.location.interfaces import ILocation 32 from zope.publisher.base import TestRequest 33 from zope.publisher.interfaces import NotFound 29 34 from waeup.sirp.interfaces import IWAeUPSIRPPluggable 35 from waeup.sirp.widgets.passportwidget import PassportImage 30 36 from waeup.sirp.applicants import ( 31 ResultEntry, Applicant, ApplicantFactory, 37 ResultEntry, Applicant, ApplicantFactory, ApplicantTraverser, 32 38 ) 33 39 from waeup.sirp.applicants.interfaces import ( 34 40 IResultEntry, IApplicant, 35 41 ) 42 43 class FakeImageLocation(object): 44 implements(ILocation) 45 adapts(IImage) 46 def __init__(self, context): 47 pass 36 48 37 49 class ResultEntryTest(unittest.TestCase): … … 85 97 assert implemented_by.isOrExtends(IApplicant) 86 98 99 class ApplicantTraverserTest(unittest.TestCase): 100 101 def setUp(self): 102 self.applicant = Applicant() 103 self.request = TestRequest('') 104 self.gsm = getGlobalSiteManager() 105 self.gsm.registerAdapter(FakeImageLocation) 106 return 107 108 def tearDown(self): 109 self.gsm.unregisterAdapter(FakeImageLocation) 110 return 111 112 def test_traverse_wo_passport(self): 113 # Ask for some attribute not provided 114 traverser = ApplicantTraverser( 115 self.applicant, self.request 116 ) 117 self.assertRaises( 118 NotFound, 119 traverser.publishTraverse, self.request, 'passport' 120 ) 121 return 122 123 def test_traverse_wo_image_passport_jpg(self): 124 # Ask for applicant pic if we didn't provided one 125 # We get a placeholder. 126 traverser = ApplicantTraverser( 127 self.applicant, self.request 128 ) 129 result = traverser.publishTraverse(self.request, 'passport.jpg') 130 self.assertTrue(isinstance(result, FakeImageLocation)) 131 return 132 133 def test_traverse_w_image_passport_jpg(self): 134 # Ask for applicant pic that's named 'passport.jpg' 135 traverser = ApplicantTraverser( 136 self.applicant, self.request 137 ) 138 self.applicant.passport = PassportImage(None) 139 self.applicant.passport.filename = 'mypic.jpg' 140 result = traverser.publishTraverse(self.request, 'passport.jpg') 141 self.assertTrue(isinstance(result, FakeImageLocation)) 142 return 143 144 def test_traverse_w_image_some_jpg(self): 145 # Ask for applicant pic by correct name 146 traverser = ApplicantTraverser( 147 self.applicant, self.request 148 ) 149 self.applicant.passport = PassportImage(None) 150 self.applicant.passport.filename = 'mypic.jpg' 151 result = traverser.publishTraverse(self.request, 'mypic.jpg') 152 self.assertTrue(isinstance(result, FakeImageLocation)) 153 return 154 87 155 def test_suite(): 88 156 suite = unittest.TestSuite() 89 157 for testcase in [ 90 158 ResultEntryTest, ApplicantTest, ApplicantFactoryTest, 159 ApplicantTraverserTest, 91 160 ]: 92 161 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
Note: See TracChangeset for help on using the changeset viewer.