Ignore:
Timestamp:
16 Nov 2011, 18:07:03 (13 years ago)
Author:
uli
Message:

Let applicants cooperate with new imagestorage and accept at least jpg and png.

File:
1 edited

Legend:

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

    r7063 r7121  
    2323"""
    2424import grok
     25import os
     26import shutil
     27import tempfile
    2528import unittest
     29from StringIO import StringIO
    2630from zope.component import adapts, queryUtility
    2731from zope.component.interfaces import IFactory
     
    4852    layer = FunctionalLayer
    4953
     54    def setUp(self):
     55        super(HelperTests, self).setUp()
     56        self.workdir = tempfile.mkdtemp()
     57        return
     58
     59    def tearDown(self):
     60        super(HelperTests, self).tearDown()
     61        shutil.rmtree(self.workdir)
     62        return
     63
    5064    def test_get_regno_or_ac(self):
    5165        # we can get reg_no or access_code of an applicants if it is set
     
    8599            store, '/fake-root', '__img-applicant__dir1/dir2/sample.jpg')
    86100        self.assertEqual(
    87             result1, '/fake-root/applicants/sample.jpg')
    88         self.assertEqual(
    89             result2, '/fake-root/applicants/dir1/sample.jpg')
    90         self.assertEqual(
    91             result3, '/fake-root/applicants/dir1/dir2/sample.jpg')
     101            result1, '/fake-root/applicants/sample')
     102        self.assertEqual(
     103            result2, '/fake-root/applicants/dir1/sample')
     104        self.assertEqual(
     105            result3, '/fake-root/applicants/dir1/dir2/sample')
     106        return
     107
     108    def test_image_store_handler_create(self):
     109        # we can create files in image store with the applicant image
     110        # store handler
     111        store = DefaultStorage(self.workdir)
     112        handler = queryUtility(IFileStoreHandler, name='img-applicant')
     113        file_obj, path, waeup_file = handler.createFile(
     114            store, store.root, 'sample.jpg', '__img_applicant__sample',
     115            StringIO('I am a JPG file'))
     116        self.assertEqual(path[-21:], 'applicants/sample.jpg')
     117        return
     118
     119    def test_image_store_handler_invalid_filename_ext(self):
     120        # we only accept '.jpg' and '.png' as filename extensions.
     121        store = DefaultStorage()
     122        handler = queryUtility(IFileStoreHandler, name='img-applicant')
     123        self.assertRaises(
     124            ValueError,
     125            handler.createFile,
     126            store, store.root, 'sample.txt', '__img_applicant__sample',
     127            StringIO('I am a txt file'))
    92128        return
    93129
Note: See TracChangeset for help on using the changeset viewer.