incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#6844] Fixed GC project icons not saving
Date Fri, 08 Nov 2013 20:29:45 GMT
Updated Branches:
  refs/heads/cj/6844 [created] 4f951eb05


[#6844] Fixed GC project icons not saving

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/4f951eb0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4f951eb0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4f951eb0

Branch: refs/heads/cj/6844
Commit: 4f951eb05f86dc1d92ab53277b8c7fe48ec0ee07
Parents: f09d0b6
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Nov 8 20:29:04 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Nov 8 20:29:04 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/base.py            |  9 +++++++++
 ForgeImporters/forgeimporters/tests/test_base.py | 10 +++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4f951eb0/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 97f7c92..4f05156 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -513,6 +513,7 @@ class ImportAdminExtension(AdminExtension):
 
 def stringio_parser(page):
     return {
+            'content-type': page.info()['content-type'],
             'data': StringIO(page.read()),
         }
 
@@ -521,7 +522,15 @@ class File(object):
         extractor = ProjectExtractor(None, url, parser=stringio_parser)
         self.url = url
         self.filename = filename or os.path.basename(urlparse(url).path)
+        # try to get the mime-type from the filename first, because
+        # some files (e.g., attachements) may have the Content-Type header
+        # forced to encourage the UA to download / save the file
         self.type = guess_mime_type(self.filename)
+        if self.type == 'application/octet-stream':
+            # however, if that fails, fall back to the given mime-type,
+            # as some files (e.g., project icons) might have no file
+            # extension but return a valid Content-Type header
+            self.type = extractor.page['content-type']
         self.file = extractor.page['data']
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4f951eb0/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index b1b2e63..ade7b7a 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -347,10 +347,14 @@ def test_save_importer_upload(giup, os):
 
 class TestFile(object):
 
-    @mock.patch.object(base, 'ProjectExtractor', mock.MagicMock)
-    def test_type(self):
+    @mock.patch.object(base, 'ProjectExtractor')
+    def test_type(self, PE):
+        PE().page = {
+                'content-type': 'image/png',
+                'data': 'data',
+            }
         f = base.File('http://example.com/barbaz.jpg')
         assert_equal(f.type, 'image/jpeg')
 
         f = base.File('http://example.com/barbaz')
-        assert_equal(f.type, 'application/octet-stream')
+        assert_equal(f.type, 'image/png')


Mime
View raw message