Changeset 7121
- Timestamp:
- 16 Nov 2011, 18:07:03 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/applicants
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicant.py
r7105 r7121 201 201 """ 202 202 marker, filename, basename, ext = store.extractMarker(file_id) 203 return os.path.join(root, 'applicants', filename) 203 sub_root = os.path.join(root, 'applicants') 204 return super(ApplicantImageStoreHandler, self).pathFromFileID( 205 store, sub_root, basename) 204 206 205 207 def createFile(self, store, root, filename, file_id, file): 206 208 """Create a browsable file-like object. 207 209 """ 208 # possible other actions: check for jpeg format 209 path = self.pathFromFileID(store, root, file_id) 210 return file, path, WAeUPImageFile(filename, file_id) 210 ext = os.path.splitext(filename)[1].lower() 211 if ext not in ['.jpg', '.png']: 212 raise ValueError('Only .jpg and .png allowed') 213 # call super method to ensure that any old files with 214 # different filename extension are deleted. 215 file, path, file_obj = super( 216 ApplicantImageStoreHandler, self).createFile( 217 store, root, filename, file_id, file) 218 return file, path, WAeUPImageFile( 219 file_obj.filename, file_obj.data) -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicant.py
r7063 r7121 23 23 """ 24 24 import grok 25 import os 26 import shutil 27 import tempfile 25 28 import unittest 29 from StringIO import StringIO 26 30 from zope.component import adapts, queryUtility 27 31 from zope.component.interfaces import IFactory … … 48 52 layer = FunctionalLayer 49 53 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 50 64 def test_get_regno_or_ac(self): 51 65 # we can get reg_no or access_code of an applicants if it is set … … 85 99 store, '/fake-root', '__img-applicant__dir1/dir2/sample.jpg') 86 100 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')) 92 128 return 93 129
Note: See TracChangeset for help on using the changeset viewer.