Commits

Mike Lin committed 544e36f

Rolled back changes to the deprecated S3 backend. Used string.endswith() to be more concise. Added test cases.

  • Participants
  • Parent commits eba248d

Comments (0)

Files changed (3)

File storages/backends/s3.py

         return content_length and int(content_length) or 0
 
     def url(self, name):
-        # Preserve the trailing slash after normalizing the path.
-        trailing_slash = '/' if name and name[-1] == '/' else ''
-        name = self._clean_name(name) + trailing_slash
+        name = self._clean_name(name)
         if QUERYSTRING_ACTIVE:
             return self.generator.generate_url('GET', self.bucket, name)
         else:

File storages/backends/s3boto.py

 
     def url(self, name, headers=None, response_headers=None):
         # Preserve the trailing slash after normalizing the path.
-        trailing_slash = '/' if name and name[-1] == '/' else ''
+        trailing_slash = '/' if name.endswith('/') else ''
         name = self._normalize_name(self._clean_name(name)) + trailing_slash
         if self.custom_domain:
             return "%s//%s/%s" % (self.url_protocol,

File storages/tests/s3boto.py

 
 class S3BotoStorageTests(S3BotoTestCase):
 
+    def test_storage_url(self):
+        """
+        Test URL generation.
+        """
+        self.storage.custom_domain = 'example.com'
+
+        # We expect no leading slashes in the path,
+        # and trailing slashes should be preserved.
+        self.assertEqual(self.storage.url(''), 'https://example.com/')
+        self.assertEqual(self.storage.url('path'), 'https://example.com/path')
+        self.assertEqual(self.storage.url('path/'), 'https://example.com/path/')
+        self.assertEqual(self.storage.url('path/1'), 'https://example.com/path/1')
+        self.assertEqual(self.storage.url('path/1/'), 'https://example.com/path/1/')
+
     def test_storage_save(self):
         """
         Test saving a file