Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7468B109AF for ; Fri, 8 Nov 2013 20:29:45 +0000 (UTC) Received: (qmail 10664 invoked by uid 500); 8 Nov 2013 20:29:45 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 10640 invoked by uid 500); 8 Nov 2013 20:29:45 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 10632 invoked by uid 99); 8 Nov 2013 20:29:45 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Nov 2013 20:29:45 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 1D86081F1B2; Fri, 8 Nov 2013 20:29:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: [#6844] Fixed GC project icons not saving Date: Fri, 8 Nov 2013 20:29:45 +0000 (UTC) Updated Branches: refs/heads/cj/6844 [created] 4f951eb05 [#6844] Fixed GC project icons not saving Signed-off-by: Cory Johns 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 Authored: Fri Nov 8 20:29:04 2013 +0000 Committer: Cory Johns 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')