def testConvertSize(self): self.assertEquals(None, convert_size.ConvertSize(None)) self.assertEquals(None, convert_size.ConvertSize('4')) self.assertEquals(None, convert_size.ConvertSize('4C')) self.assertEquals(4, convert_size.ConvertSize('4B')) self.assertEquals(4 * 2**10, convert_size.ConvertSize('4KB')) self.assertEquals(12 * 2**20, convert_size.ConvertSize('12MB')) self.assertEquals(10 * 2**30, convert_size.ConvertSize('10GB'))
def _InitMediaUpload(self, parent): media_upload = self.values.get('mediaUpload') if media_upload: if parent: parent.SetTemplateValue('isMedia', True) # Get which MIME Media Ranges are accepted for media uploads to this # method. accepted_mime_ranges = media_upload.get('accept') self.SetTemplateValue('accepted_mime_ranges', accepted_mime_ranges) max_size = media_upload.get('maxSize') self.SetTemplateValue('max_size', max_size) self.SetTemplateValue('max_size_bytes', convert_size.ConvertSize(max_size)) # Find which upload protocols are supported. upload_protocols = media_upload['protocols'] for upload_protocol in upload_protocols: self._SetUploadTemplateValues( upload_protocol, upload_protocols[upload_protocol])