Changeset 7032 for main/waeup.sirp/branches/ulif-extimgstore/src/waeup
- Timestamp:
- 8 Nov 2011, 14:13:30 (13 years ago)
- Location:
- main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/imagestorage.py
r7031 r7032 210 210 211 211 class FileStoreNameChooser(grok.Adapter): 212 """Default file store name chooser. 213 214 File store name choosers pick a file id, a string, for a certain 215 context object. They are normally registered as adapters for a 216 certain content type and know how to build the file id for this 217 special type of context. 218 219 Provides the :class:`waeup.sirp.interfaces.IFileStoreNameChooser` 220 interface. 221 222 This default file name chosser accepts almost every name as long 223 as it is a string or unicode object. 224 """ 212 225 grok.context(Interface) 213 226 grok.implements(IFileStoreNameChooser) … … 217 230 218 231 Raises a user error if the name is not valid. 219 """ 220 pass 232 233 For the default file store name chooser any name is valid. 234 """ 235 if isinstance(name, basestring): 236 return True 237 return False 221 238 222 239 def chooseName(self, name): … … 228 245 chooseName is expected to always choose a valid name (that 229 246 would pass the checkName test) and never raise an error. 230 """ 247 248 For this default name chooser we return the given name if it 249 is valid or ``unknown_file`` else. 250 """ 251 if self.checkName(name): 252 return name 231 253 return u'unknown_file' 232 254 -
main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/tests/test_imagestorage.py
r7002 r7032 310 310 self.assertEqual(contents, 'Hi there!') 311 311 312 class NameChooserTests(unittest.TestCase): 312 class FileStoreNameChooserTests(FunctionalTestCase): 313 314 layer = FunctionalLayer 313 315 314 316 def test_iface(self): 317 # we provide the interfaces we promise to do 315 318 obj = FileStoreNameChooser(None) 316 319 verifyClass(IFileStoreNameChooser, FileStoreNameChooser) 317 320 verifyObject(IFileStoreNameChooser, obj) 321 return 322 323 def test_accessible_as_adapter(self): 324 # we can get a file name chooser via adapter 325 chooser = IFileStoreNameChooser(object()) 326 self.assertTrue( 327 isinstance(chooser, FileStoreNameChooser)) 328 return 329 330 def test_check_name(self): 331 # default file name choosers accept any string 332 chooser = FileStoreNameChooser(object()) 333 self.assertEqual(chooser.checkName('Hi there!'), True) 334 self.assertEqual(chooser.checkName(None), False) 335 return 336 337 def test_choose_name(self): 338 # we get a simple string if we do not pass in a valid string 339 chooser = FileStoreNameChooser(object()) 340 self.assertEqual(chooser.chooseName('myname'), 'myname') 341 self.assertEqual(chooser.chooseName(None), u'unknown_file') 318 342 return 319 343
Note: See TracChangeset for help on using the changeset viewer.