You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/11/12 19:14:06 UTC

[2/4] git commit: [#6844] Fixed GC project icons not saving

[#6844] Fixed GC project icons not saving

Signed-off-by: Cory Johns <cj...@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/cj/6845
Commit: a4e46b7ab6ee430e9d96a8546b0e83bbd0289ae5
Parents: f1c9240
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Nov 8 20:29:04 2013 +0000
Committer: Dave Brondsema <db...@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')