From 94dcf620f27e8e3820389e47fb4a86af85a358f4 Mon Sep 17 00:00:00 2001 From: Andrzej Winnicki Date: Mon, 31 Jul 2017 16:40:32 +0200 Subject: [PATCH] Add failing test which tries to save the same content twice (#371) See: https://github.com/jschneier/django-storages/issues/367 --- tests/test_s3boto3.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_s3boto3.py b/tests/test_s3boto3.py index d0f0b0593..ef1a263e3 100644 --- a/tests/test_s3boto3.py +++ b/tests/test_s3boto3.py @@ -128,6 +128,34 @@ def test_storage_save_gzip(self): zfile = gzip.GzipFile(mode='rb', fileobj=content) self.assertEqual(zfile.read(), b"I should be gzip'd") + def test_storage_save_gzip_twice(self): + """ + Test saving the same file content twice with gzip enabled. + """ + # Given + self.storage.gzip = True + name = 'test_storage_save.css' + content = ContentFile("I should be gzip'd") + + # When + self.storage.save(name, content) + self.storage.save('test_storage_save_2.css', content) + + # Then + obj = self.storage.bucket.Object.return_value + obj.upload_fileobj.assert_called_with( + mock.ANY, + ExtraArgs={ + 'ContentType': 'text/css', + 'ContentEncoding': 'gzip', + 'ACL': self.storage.default_acl, + } + ) + args, kwargs = obj.upload_fileobj.call_args + content = args[0] + zfile = gzip.GzipFile(mode='rb', fileobj=content) + self.assertEqual(zfile.read(), b"I should be gzip'd") + def test_compress_content_len(self): """ Test that file returned by _compress_content() is readable.