Changeset 6539


Ignore:
Timestamp:
23 Jul 2011, 02:49:20 (13 years ago)
Author:
uli
Message:

Extend tests and use new IFileRetrieval when checking passport images.

File:
1 edited

Legend:

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

    r6297 r6539  
    2323"""
    2424import unittest
     25from StringIO import StringIO
     26from hurry.file.interfaces import IFileRetrieval
    2527from zope.app.testing.functional import FunctionalTestCase
    2628from zope.component import (
    2729    provideAdapter, adapts, getGlobalSiteManager, provideUtility)
     30from zope.component.hooks import setSite
    2831from zope.component.interfaces import IFactory
    2932from zope.interface import verify, implements
     
    3134from zope.publisher.base import TestRequest
    3235from zope.publisher.interfaces import NotFound
    33 from waeup.sirp.image.image import WAeUPImageFile
     36from waeup.sirp.app import University
     37from waeup.sirp.image import WAeUPImageFile, createWAeUPImageFile
    3438from waeup.sirp.image.interfaces import IWAeUPImageFile
    3539from waeup.sirp.applicants import (
     
    3943    IResultEntry, IApplicant,
    4044    )
     45from waeup.sirp.imagestorage import ImageStorageFileRetrieval
    4146from waeup.sirp.testing import FunctionalLayer
    4247
     
    7075
    7176    def setUp(self):
     77        super(ApplicantTest, self).setUp()
    7278        self.applicant = Applicant()
     79        return
    7380
    7481    def tearDown(self):
    75         pass
     82        super(ApplicantTest, self).tearDown()
     83        return
    7684
    7785    def test_interfaces(self):
    7886        verify.verifyClass(IApplicant, Applicant)
    7987        verify.verifyObject(IApplicant, self.applicant)
     88        return
     89
     90    def test_passport_no_site(self):
     91        # make sure we get a real image stored in passport attr
     92        image = self.applicant.passport.file.read()
     93        self.assertEqual(len(image), 2059)
     94        return
     95
     96    def test_passport_insite(self):
     97        # make sure we get a real image in passport attr when inside a site.
     98        # When an applicant is created 'inside a site', its passport
     99        # photograph should be put inside the images folder of the
     100        # site, even if it is only a placeholder.
     101        self.getRootFolder()['app'] = University()
     102        app = self.getRootFolder()['app']
     103        setSite(app)
     104        applicant = Applicant()
     105        image = self.applicant.passport.file.read()
     106        self.assertEqual(len(image), 2059)
     107        # The image contains a file_id instead of real image-data
     108        self.assertEqual(self.applicant.passport.data,
     109                         u'b48a1d39bbcb32e955d9ff2dea4ed0e6-1')
     110        assert u'b48a1d39bbcb32e955d9ff2dea4ed0e6' in app['images'].keys()
     111        return
    80112
    81113class ApplicantFactoryTest(FunctionalTestCase):
     
    84116
    85117    def setUp(self):
     118        # Install a IFileRetrieval utility that returns WAeUPImageFiles.
     119        storage = ImageStorageFileRetrieval()
     120        provideUtility(storage, IFileRetrieval)
    86121        self.factory = ApplicantFactory()
    87122
     
    146181            self.applicant, self.request
    147182            )
    148         self.applicant.passport = WAeUPImageFile('nofile.jpg', '')
     183        self.applicant.passport = createWAeUPImageFile(
     184            'nofile.jpg', StringIO('no-content'))
    149185        self.applicant.passport.filename = 'mypic.jpg'
    150186        result = traverser.publishTraverse(self.request, 'passport.jpg')
Note: See TracChangeset for help on using the changeset viewer.