def test_content_encoding_gzip(self): kwargs = {'message': 'hello'} message = json.dumps(kwargs) fp = StringIO() try: f = GzipFile(fileobj=fp, mode='w') f.write(message) finally: f.close() key = self.projectkey.public_key secret = self.projectkey.secret_key resp = self.client.post( self.path, fp.getvalue(), content_type='application/octet-stream', HTTP_CONTENT_ENCODING='gzip', HTTP_X_SENTRY_AUTH=get_auth_header('_postWithHeader', key, secret), ) assert resp.status_code == 200, resp.content event_id = json.loads(resp.content)['id'] instance = Event.objects.get(event_id=event_id) assert instance.message == 'hello'
def test_content_encoding_gzip(self): kwargs = {"message": "hello"} message = json.dumps(kwargs) fp = StringIO() try: f = GzipFile(fileobj=fp, mode="w") f.write(message) finally: f.close() key = self.projectkey.public_key secret = self.projectkey.secret_key with self.tasks(): resp = self.client.post( self.path, fp.getvalue(), content_type="application/octet-stream", HTTP_CONTENT_ENCODING="gzip", HTTP_X_SENTRY_AUTH=get_auth_header("_postWithHeader", key, secret), ) assert resp.status_code == 200, resp.content event_id = json.loads(resp.content)["id"] instance = Event.objects.get(event_id=event_id) assert instance.message == "hello"
def get_cached_photo(self, size): if not self.file: return if size not in self.ALLOWED_SIZES: size = min(self.ALLOWED_SIZES, key=lambda x: abs(x - size)) cache_key = self.get_cache_key(size) photo = cache.get(cache_key) if photo is None: photo_file = self.file.getfile() with Image.open(photo_file) as image: image = image.resize((size, size)) image_file = StringIO() image.save(image_file, "PNG") photo = image_file.getvalue() cache.set(cache_key, photo) return photo
def get_cached_photo(self, size): if not self.file: return if size not in self.ALLOWED_SIZES: size = min(self.ALLOWED_SIZES, key=lambda x: abs(x - size)) cache_key = self.get_cache_key(size) photo = cache.get(cache_key) if photo is None: photo_file = self.file.getfile() with Image.open(photo_file) as image: image = image.resize((size, size)) image_file = StringIO() image.save(image_file, 'PNG') photo = image_file.getvalue() cache.set(cache_key, photo) return photo