You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/08/10 15:39:38 UTC

[14/18] allura git commit: [#7925] tests, fix, and docstring for has_html_view

[#7925] tests, fix, and docstring for has_html_view


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

Branch: refs/heads/master
Commit: 7133cb19b3b770f45159ceacc968e85464599af4
Parents: 9835504
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Jul 31 20:25:09 2015 +0000
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Mon Aug 10 09:38:37 2015 -0400

----------------------------------------------------------------------
 Allura/allura/model/repository.py     | 28 +++++++++++++++-----------
 Allura/allura/tests/unit/test_repo.py | 32 +++++++++++++++++++++++++-----
 2 files changed, 43 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/7133cb19/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 636d10c..3db43a8 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -78,18 +78,18 @@ SObjType = S.OneOf('blob', 'tree', 'submodule')
 # Used for when we're going to batch queries using $in
 QSIZE = 100
 BINARY_EXTENSIONS = [
-    "3ds", "3g2", "3gp", "7z", "a", "aac", "adp", "ai", "aif", "apk", "ar", "asf", "au", "avi",
-    "bak", "bin", "bk", "bmp", "btif", "bz2", "cab", "caf", "cgm", "cmx", "cpio", "cr2", "dat", "deb", "djvu", "dll",
-    "dmg", "dng", "doc", "docx", "dra", "DS_Store", "dsk", "dts", "dtshd", "dvb", "dwg", "dxf", "ecelp4800",
-    "ecelp7470", "ecelp9600", "egg", "eol", "eot", "epub", "exe", "f4v", "fbs", "fh", "fla", "flac", "fli", "flv",
-    "fpx", "fst", "fvt", "g3", "gif", "gz", "h261", "h263", "h264", "ico", "ief", "img", "ipa", "iso", "jar", "jpeg",
-    "jpg", "jpgv", "jpm", "jxr", "ktx", "lvp", "lz", "lzma", "lzo", "m3u", "m4a", "m4v", "mar", "mdi", "mid", "mj2",
-    "mka", "mkv", "mmr", "mng", "mov", "movie", "mp3", "mp4", "mp4a", "mpeg", "mpg", "mpga", "mxu", "nef", "npx", "o",
-    "oga", "ogg", "ogv", "otf", "pbm", "pcx", "pdf", "pea", "pgm", "pic", "png", "pnm", "ppm", "psd", "pya", "pyc",
-    "pyo", "pyv", "qt", "rar", "ras", "raw", "rgb", "rip", "rlc", "rz", "s3m", "s7z", "scpt", "sgi", "shar", "sil",
-    "smv", "so", "sub", "swf", "tar", "tbz2", "tga", "tgz", "tif", "tiff", "tlz", "ts", "ttf", "uvh", "uvi", "uvm",
-    "uvp", "uvs", "uvu", "viv", "vob", "war", "wav", "wax", "wbmp", "wdp", "weba", "webm", "webp", "whl", "wm", "wma",
-    "wmv", "wmx", "woff", "woff2", "wvx", "xbm", "xif", "xm", "xpi", "xpm", "xwd", "xz", "z", "zip", "zipx"
+    ".3ds", ".3g2", ".3gp", ".7z", ".a", ".aac", ".adp", ".ai", ".aif", ".apk", ".ar", ".asf", ".au", ".avi",
+    ".bak", ".bin", ".bk", ".bmp", ".btif", ".bz2", ".cab", ".caf", ".cgm", ".cmx", ".cpio", ".cr2", ".dat", ".deb", ".djvu", ".dll",
+    ".dmg", ".dng", ".doc", ".docx", ".dra", ".DS_Store", ".dsk", ".dts", ".dtshd", ".dvb", ".dwg", ".dxf", ".ecelp4800",
+    ".ecelp7470", ".ecelp9600", ".egg", ".eol", ".eot", ".epub", ".exe", ".f4v", ".fbs", ".fh", ".fla", ".flac", ".fli", ".flv",
+    ".fpx", ".fst", ".fvt", ".g3", ".gif", ".gz", ".h261", ".h263", ".h264", ".ico", ".ief", ".img", ".ipa", ".iso", ".jar", ".jpeg",
+    ".jpg", ".jpgv", ".jpm", ".jxr", ".ktx", ".lvp", ".lz", ".lzma", ".lzo", ".m3u", ".m4a", ".m4v", ".mar", ".mdi", ".mid", ".mj2",
+    ".mka", ".mkv", ".mmr", ".mng", ".mov", ".movie", ".mp3", ".mp4", ".mp4a", ".mpeg", ".mpg", ".mpga", ".mxu", ".nef", ".npx", ".o",
+    ".oga", ".ogg", ".ogv", ".otf", ".pbm", ".pcx", ".pdf", ".pea", ".pgm", ".pic", ".png", ".pnm", ".ppm", ".psd", ".pya", ".pyc",
+    ".pyo", ".pyv", ".qt", ".rar", ".ras", ".raw", ".rgb", ".rip", ".rlc", ".rz", ".s3m", ".s7z", ".scpt", ".sgi", ".shar", ".sil",
+    ".smv", ".so", ".sub", ".swf", ".tar", ".tbz2", ".tga", ".tgz", ".tif", ".tiff", ".tlz", ".ts", ".ttf", ".uvh", ".uvi", ".uvm",
+    ".uvp", ".uvs", ".uvu", ".viv", ".vob", ".war", ".wav", ".wax", ".wbmp", ".wdp", ".weba", ".webm", ".webp", ".whl", ".wm", ".wma",
+    ".wmv", ".wmx", ".woff", ".woff2", ".wvx", ".xbm", ".xif", ".xm", ".xpi", ".xpm", ".xwd", ".xz", ".z", ".zip", ".zipx"
 ]
 
 PYPELINE_EXTENSIONS = utils.MARKDOWN_EXTENSIONS + ['.rst']
@@ -1478,6 +1478,10 @@ class Blob(object):
 
     @LazyProperty
     def has_html_view(self):
+        '''
+        Return true if file is a text file that can be displayed.
+        :return: boolean
+        '''
         if self.extension in BINARY_EXTENSIONS:
             return False
         if (self.content_type.startswith('text/') or

http://git-wip-us.apache.org/repos/asf/allura/blob/7133cb19/Allura/allura/tests/unit/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_repo.py b/Allura/allura/tests/unit/test_repo.py
index 9008571..2e52ebe 100644
--- a/Allura/allura/tests/unit/test_repo.py
+++ b/Allura/allura/tests/unit/test_repo.py
@@ -153,13 +153,35 @@ class TestTree(unittest.TestCase):
 class TestBlob(unittest.TestCase):
 
     def test_pypeline_view(self):
-        blob = M.repository.Blob(Mock(), Mock(), Mock())
-        blob._id = 'blob1'
-        blob.path = Mock(return_value='path')
-        blob.name = 'INSTALL.mdown'
-        blob.extension = '.mdown'
+        blob = M.repository.Blob(Mock(), 'INSTALL.mdown', 'blob1')
         assert_equal(blob.has_pypeline_view, True)
 
+    def test_has_html_view_text_mime(self):
+        blob = M.repository.Blob(Mock(), 'INSTALL', 'blob1')
+        blob.content_type = 'text/plain'
+        assert_equal(blob.has_html_view, True)
+
+    def test_has_html_view_text_ext(self):
+        blob = M.repository.Blob(Mock(), 'INSTALL.txt', 'blob1')
+        blob.content_type = 'foo/bar'
+        assert_equal(blob.has_html_view, True)
+
+    def test_has_html_view_text_contents(self):
+        blob = M.repository.Blob(MagicMock(), 'INSTALL', 'blob1')
+        blob.content_type = 'foo/bar'
+        blob.text = 'hello world, this is text here'
+        assert_equal(blob.has_html_view, True)
+
+    def test_has_html_view_bin_ext(self):
+        blob = M.repository.Blob(Mock(), 'INSTALL.zip', 'blob1')
+        assert_equal(blob.has_html_view, False)
+
+    def test_has_html_view_bin_content(self):
+        blob = M.repository.Blob(MagicMock(), 'myfile', 'blob1')
+        blob.content_type = 'whatever'
+        blob.text = '\0\0\0\0'
+        assert_equal(blob.has_html_view, False)
+
 
 class TestCommit(unittest.TestCase):