You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/07/08 00:11:29 UTC

[12/16] allura git commit: [#7899] ticket:812 Add test for format=raw and fix unicode error

[#7899] ticket:812 Add test for format=raw and fix unicode error


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

Branch: refs/heads/db/6373
Commit: ffba7216b9a07bf5a1418180b771662f522e6c44
Parents: fdefe42
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Jul 6 16:13:50 2015 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon Jul 6 16:13:50 2015 +0300

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py         |  2 +-
 .../tests/functional/test_controllers.py        | 37 ++++++++++++++++++--
 2 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ffba7216/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index e9f051d..f8b0834 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -739,7 +739,7 @@ class FileBrowser(BaseController):
             response.content_encoding = content_encoding
         response.headers.add(
             'Content-Disposition',
-            'attachment;filename="%s"' % filename.encode('utf-8'))
+            'attachment;filename="%s"' % filename)
         return iter(self._blob)
 
     def diff(self, commit, fmt=None, **kw):

http://git-wip-us.apache.org/repos/asf/allura/blob/ffba7216/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 917f765..b84cd5a 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -1,3 +1,5 @@
+# coding: utf-8
+
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -78,6 +80,18 @@ class _TestCase(TestController):
 
 class TestRootController(_TestCase):
 
+
+    @with_tool('test', 'Git', 'weird-chars', 'WeirdChars', type='git')
+    def _setup_weird_chars_repo(self):
+        h.set_context('test', 'weird-chars', neighborhood='Projects')
+        repo_dir = pkg_resources.resource_filename(
+            'forgegit', 'tests/data')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.status = 'ready'
+        c.app.repo.name = 'weird-chars.git'
+        ThreadLocalORMSession.flush_all()
+        c.app.repo.refresh()
+
     def test_status(self):
         resp = self.app.get('/src-git/status')
         d = json.loads(resp.body)
@@ -164,11 +178,11 @@ class TestRootController(_TestCase):
     def test_tags(self):
         self.app.get('/src-git/ref/master~/tags/')
 
-    def _get_ci(self):
-        r = self.app.get('/src-git/ref/master/')
+    def _get_ci(self, repo='/p/test/src-git/'):
+        r = self.app.get(repo + 'ref/master/')
         resp = r.follow()
         for tag in resp.html.findAll('a'):
-            if tag['href'].startswith('/p/test/src-git/ci/'):
+            if tag['href'].startswith(repo + 'ci/'):
                 href = tag['href']
                 if href.endswith('tree/'):
                     href = href[:-5]
@@ -241,6 +255,23 @@ class TestRootController(_TestCase):
         assert '<span id="l1" class="code_block">' in resp
         assert 'var hash = window.location.hash.substring(1);' in resp
 
+    def test_file_raw(self):
+        self._setup_weird_chars_repo()
+        ci = self._get_ci(repo='/p/test/weird-chars/')
+        url = ci + 'tree/' + h.urlquote(u'привіт.txt') + '?format=raw'
+        resp = self.app.get(url)
+        assert_in(u'Привіт!\nWhich means Hello!', resp.body.decode('utf-8'))
+        assert_equal(
+            resp.headers.get('Content-Disposition').decode('utf-8'),
+            u'attachment;filename="привіт.txt"')
+
+        url = ci + 'tree/' + h.urlquote(u'with space.txt') + '?format=raw'
+        resp = self.app.get(url)
+        assert_in(u'with space', resp.body.decode('utf-8'))
+        assert_equal(
+            resp.headers.get('Content-Disposition').decode('utf-8'),
+            u'attachment;filename="with space.txt"')
+
     def test_invalid_file(self):
         ci = self._get_ci()
         self.app.get(ci + 'tree/READMEz', status=404)