Changeset 7241


Ignore:
Timestamp:
1 Dec 2011, 07:55:32 (13 years ago)
Author:
Henrik Bettermann
Message:

Add fixed ApplicantImageNameChooserTests?.

File:
1 edited

Legend:

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

    r7240 r7241  
    104104        return
    105105
     106class ApplicantImageNameChooserTests(FunctionalTestCase):
     107
     108    layer = FunctionalLayer
     109
     110    def test_iface(self):
     111        # make sure we implement promised interfaces
     112        obj = ApplicantImageNameChooser(None) # needs a context normally
     113        verify.verifyClass(IFileStoreNameChooser, ApplicantImageNameChooser)
     114        verify.verifyObject(IFileStoreNameChooser, obj)
     115        return
     116
     117    def test_name_chooser_available(self):
     118        # we can get a name chooser for applicant objects as adapter
     119        appl = Applicant()
     120        chooser = IFileStoreNameChooser(appl)
     121        self.assertTrue(chooser is not None)
     122        return
     123
     124    def test_name_chooser_applicant_wo_container(self):
     125        # we can get an image filename for applicants not in a container
     126        appl = Applicant()
     127        chooser = IFileStoreNameChooser(appl)
     128        result = chooser.chooseName()
     129        # the file would be stored in a ``_default`` directory.
     130        self.assertEqual(
     131            result, '__img-applicant___default/xxx_1234.jpg')
     132        return
     133
     134    def test_name_chooser_applicant_w_container(self):
     135        fake_container = grok.Container()
     136        fake_container.__name__ = 'folder'
     137        fake_container.code = 'folder'
     138        appl = Applicant(container=fake_container)
     139        appl.__parent__ = fake_container
     140        chooser = IFileStoreNameChooser(appl)
     141        result = chooser.chooseName()
     142        self.assertEqual(
     143            result, '__img-applicant__folder/%s.jpg' % appl.applicant_id)
     144        return
     145
     146    def test_name_chooser_check_name(self):
     147        # we can check file ids for applicants
     148        fake_container = grok.Container()
     149        fake_container.__name__ = 'folder'
     150        fake_container.code = 'folder'
     151        appl = Applicant(container=fake_container)
     152        appl.__parent__ = fake_container
     153        chooser = IFileStoreNameChooser(appl)
     154        result1 = chooser.checkName('foo')
     155        result2 = chooser.checkName(
     156            '__img-applicant__folder/%s.jpg' % appl.applicant_id)
     157        self.assertEqual(result1, False)
     158        self.assertEqual(result2, True)
     159        return
     160
    106161class ApplicantTest(FunctionalTestCase):
    107162
Note: See TracChangeset for help on using the changeset viewer.