Ignore:
Timestamp:
13 Feb 2011, 14:40:24 (14 years ago)
Author:
uli
Message:

Add tests for ApplicantTraverser?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicants.py

    r5756 r5764  
    2525import unittest
    2626from StringIO import StringIO
     27from zope.app.file.interfaces import IImage
     28from zope.component import provideAdapter, adapts, getGlobalSiteManager
    2729from zope.component.interfaces import IFactory
    28 from zope.interface import verify
     30from zope.interface import verify, implements
     31from zope.location.interfaces import ILocation
     32from zope.publisher.base import TestRequest
     33from zope.publisher.interfaces import NotFound
    2934from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     35from waeup.sirp.widgets.passportwidget import PassportImage
    3036from waeup.sirp.applicants import (
    31     ResultEntry, Applicant, ApplicantFactory,
     37    ResultEntry, Applicant, ApplicantFactory, ApplicantTraverser,
    3238    )
    3339from waeup.sirp.applicants.interfaces import (
    3440    IResultEntry, IApplicant,
    3541    )
     42
     43class FakeImageLocation(object):
     44    implements(ILocation)
     45    adapts(IImage)
     46    def __init__(self, context):
     47        pass
    3648
    3749class ResultEntryTest(unittest.TestCase):
     
    8597        assert implemented_by.isOrExtends(IApplicant)
    8698
     99class 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
    87155def test_suite():
    88156    suite = unittest.TestSuite()
    89157    for testcase in [
    90158        ResultEntryTest, ApplicantTest, ApplicantFactoryTest,
     159        ApplicantTraverserTest,
    91160        ]:
    92161        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
Note: See TracChangeset for help on using the changeset viewer.