Skip to content

Commit

Permalink
closes #12 - set modified time for new files
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneier committed Dec 27, 2014
1 parent f691f2f commit 8bd2728
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion storages/backends/s3boto.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from boto.s3.connection import S3Connection, SubdomainCallingFormat
from boto.exception import S3ResponseError
from boto.s3.key import Key as S3Key
from boto.utils import parse_ts
from boto.utils import parse_ts, ISO8601
except ImportError:
raise ImproperlyConfigured("Could not load Boto's S3 bindings.\n"
"See https://github.com/boto/boto")
Expand Down Expand Up @@ -411,6 +411,7 @@ def _save(self, name, content):
key = self.bucket.new_key(encoded_name)
if self.preload_metadata:
self._entries[encoded_name] = key
key.last_modified = datetime.utcnow().strftime(ISO8601)

key.set_metadata('Content-Type', content_type)
self._save_content(key, content, headers=headers)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_s3boto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.files.base import ContentFile

from boto.s3.key import Key
from boto.utils import ISO8601
from boto.utils import parse_ts, ISO8601

from storages.compat import urlparse
from storages.backends import s3boto
Expand Down Expand Up @@ -290,7 +290,6 @@ def test_new_file_modified_time(self):
with mock.patch('storages.backends.s3boto.datetime') as mock_datetime:
mock_datetime.utcnow.return_value = utcnow
self.storage.save(name, content)
self.assertEqual(self.storage.entries[name].last_modified,
utcnow.strftime(ISO8601))
self.storage.modified_time(name) # should not raise an exception
self.assertEqual(self.storage.modified_time(name),
parse_ts(utcnow.strftime(ISO8601)))

0 comments on commit 8bd2728

Please sign in to comment.