allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#6844] Fixed GC project icons not saving
Date Mon, 11 Nov 2013 20:46:02 GMT
Updated Branches:
  refs/heads/master f1c92401c -> a4e46b7ab


[#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/a4e46b7a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a4e46b7a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a4e46b7a

Branch: refs/heads/master
Commit: a4e46b7ab6ee430e9d96a8546b0e83bbd0289ae5
Parents: f1c9240
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Nov 8 20:29:04 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Nov 11 20:45:05 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/a4e46b7a/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/a4e46b7a/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