def test_location_leading_slash(self): msg = ( "S3BotoStorage.location cannot begin with a leading slash. " "Found '/'. Use '' instead." ) with self.assertRaises(ImproperlyConfigured, msg=msg): s3boto.S3BotoStorage(location='/')
def __init__(self, _location, params): """ location is not used but otherwise Django crashes. """ BaseCache.__init__(self, params) # Amazon and boto have a maximum limit of 1000 for get_all_keys(). See: # http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html # This implementation of the GET operation returns some or all (up to 1000) # of the objects in a bucket.... if self._max_entries > 1000: self._max_entries = 1000 self._options = params.get('OPTIONS', {}) # backward compatible syntax for s3cache users before v1.2 for easy upgrades # in v1.2 we update to latest django-storages 1.1.8 which changes variable names # in non-backward compatible fashion if 'ACCESS_KEY' not in self._options.keys(): self._options['ACCESS_KEY'] = self._options.get( 'ACCESS_KEY_ID', None) if 'SECRET_KEY' not in self._options.keys(): self._options['SECRET_KEY'] = self._options.get( 'SECRET_ACCESS_KEY', None) if 'BUCKET_NAME' not in self._options.keys(): self._options['BUCKET_NAME'] = self._options.get( 'STORAGE_BUCKET_NAME', None) # we use S3 compatible varibale names while django-storages doesn't _bucket_name = self._options.get('BUCKET_NAME', None) _default_acl = self._options.get('DEFAULT_ACL', 'private') _bucket_acl = self._options.get('BUCKET_ACL', _default_acl) # in case it was not specified in OPTIONS default to 'private' self._options['BUCKET_ACL'] = _bucket_acl self._location = self._options.get('LOCATION', self._options.get('location', '')) # sanitize location by removing leading and traling slashes self._options['LOCATION'] = self._location.strip('/') # S3BotoStorage wants lower case names lowercase_options = [] for name, value in self._options.items(): if value: # skip None values lowercase_options.append((name.lower(), value)) # this avoids RuntimeError: dictionary changed size during iteration # with Python 3 if we assign to the dictionary directly for _n, _v in lowercase_options: self._options[_n] = _v self._storage = s3boto.S3BotoStorage(acl=_default_acl, bucket=_bucket_name, **self._options)
def setUp(self, S3Connection): self.storage = s3boto.S3BotoStorage() self.storage._connection = mock.MagicMock()
password = models.CharField(max_length=130) num_apps_left_today = models.IntegerField(default=daily_allowed_apps) profile = models.ForeignKey('Profile', null=True, default=None) def upload_resume_to(instance, filename): import os from django.utils.timezone import now filename_base, filename_ext = os.path.splitext(filename) return 'profiles/%s%s' % ( now().strftime("%Y%m%d%H%M%S"), filename_ext.lower(), ) public_storage = s3boto.S3BotoStorage(querystring_expire=600000000, ) class Profile(models.Model): github_url = models.CharField(max_length=250, default="") linkedin_url = models.CharField(max_length=250, default="") personal_site_url = models.CharField(max_length=250, default="") phone = models.CharField(max_length=50, default="") college = models.CharField(max_length=150, default="") gpa = models.CharField(max_length=10, default="") address = models.CharField(max_length=230, default="") city = models.CharField(max_length=130, default="") state = models.CharField(max_length=130, default="") zipcode = models.CharField(max_length=130, default="")
def setUp(self, S3Connection): self.storage = s3boto.S3BotoStorage()
def get_bucket(self): storage = s3boto.S3BotoStorage() return storage.bucket