def get_key_test(self): self.conn.sync() bucket = self.conn.get_bucket(self.name) key = Key(bucket) key.key = 'upload' assert key.key == 'upload'
def track_upload_init_test(self): self.conn.sync() bucket = self.conn.get_bucket(self.name) key = Key(bucket, 'track') key.set_contents_from_string('track') assert 'track' in mimicdb.backend.smembers(tpl.bucket % self.name)
def set_key_test(self): self.conn.sync() bucket = self.conn.get_bucket(self.name) key = Key(bucket) key.key = 'upload' assert key.size == len('upload') assert key.md5 == hashlib.md5('upload').hexdigest()
def track_upload_meta_init_test(self): self.conn.sync() bucket = self.conn.get_bucket(self.name) key = Key(bucket, 'track') key.set_contents_from_string('track') meta = mimicdb.backend.hgetall(tpl.key % (self.name, 'track')) assert int(meta['size']) == len('track') assert meta['md5'] == hashlib.md5('track').hexdigest()
def get_unassigned_key_test(self): self.conn.sync() bucket = self.conn.get_bucket(self.name) key = Key(bucket) assert key.key == None
def _get_key_internal(self, *args, **kwargs): """ Internal method for checking if a key exists in the bucket set. Returns None if not. If 'force' is in the headers, it checks S3 for the key. """ if 'force' in kwargs.get('headers', args[1] if len(args) > 1 else {}) or kwargs.pop('force', None): return super(Bucket, self)._get_key_internal(*args, **kwargs) key = None if mimicdb.redis.sismember(self.name, args[0]): key = Key(self) return key, None
def track_download_meta_test(self): self.conn.sync() bucket = self.conn.get_bucket(self.name) key = BotoKey(self.boto_bucket) key.key = 'download' key.set_contents_from_string('download') key = Key(bucket) key.key = 'download' key.get_contents_as_string() meta = mimicdb.backend.hgetall(tpl.key % (self.name, 'download')) assert int(meta['size']) == len('download') assert meta['md5'] == hashlib.md5('download').hexdigest()
def list(self, *args, **kwargs): """ Returns an iterable of keys in the bucket set. If 'force' is passed, it passes it to the internal function using the headers hack. """ if kwargs.pop('force', None): headers = kwargs.get('headers', {}) headers['force'] = 'True' kwargs['headers'] = headers for key in super(Bucket, self).list(*args, **kwargs): yield key else: prefix = kwargs.get('prefix', args[0] if args else '') for key in mimicdb.redis.smembers(self.name): if key.startswith(prefix): yield Key(self, key)