Changeset - 9d645f4ede35
[Not reviewed]
default
0 2 0
domruf - 10 years ago 2016-04-09 15:47:19
dominikruf@gmail.com
tests: fix test_nodes.py and test_files.py which fail on windows due to mimetype differences

The mimetype of files may differ on different platforms (e.g. the mimetype of
.py files on windows is not text/x-python but text/plain). Therefore, compare
the mimetype to the value the platform uses.
2 files changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_files.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
import os
 
import posixpath
 
import mimetypes
 
from kallithea.tests import *
 
from kallithea.model.db import Repository
 
from kallithea.model.meta import Session
 
from kallithea.tests.fixture import Fixture
 

	
 
fixture = Fixture()
 
@@ -239,13 +240,13 @@ removed extra unicode conversion in diff
 
        response = self.app.get(url(controller='files', action='rawfile',
 
                                    repo_name=HG_REPO,
 
                                    revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
 
                                    f_path='vcs/nodes.py'))
 

	
 
        self.assertEqual(response.content_disposition, "attachment; filename=nodes.py")
 
        self.assertEqual(response.content_type, "text/x-python")
 
        self.assertEqual(response.content_type, mimetypes.guess_type("nodes.py")[0])
 

	
 
    def test_raw_file_wrong_cs(self):
 
        self.log_user()
 
        rev = u'ERRORce30c96924232dffcd24178a07ffeb5dfc'
 
        f_path = 'vcs/nodes.py'
 

	
kallithea/tests/vcs/test_nodes.py
Show inline comments
 

	
 
import stat
 
import mimetypes
 
from kallithea.lib.vcs.nodes import DirNode
 
from kallithea.lib.vcs.nodes import FileNode
 
from kallithea.lib.vcs.nodes import Node
 
from kallithea.lib.vcs.nodes import NodeError
 
from kallithea.lib.vcs.nodes import NodeKind
 
from kallithea.lib.vcs.utils.compat import unittest
 
@@ -156,17 +157,17 @@ class NodeBasicTest(unittest.TestCase):
 
        my_node2 = FileNode('myfile2')
 
        my_node2._mimetype = [ext]
 

	
 
        my_node3 = FileNode('myfile3')
 
        my_node3._mimetype = [ext,ext]
 

	
 
        self.assertEqual(py_node.mimetype,'text/x-python')
 
        self.assertEqual(py_node.get_mimetype(),('text/x-python',None))
 
        self.assertEqual(py_node.mimetype, mimetypes.guess_type(py_node.name)[0])
 
        self.assertEqual(py_node.get_mimetype(), mimetypes.guess_type(py_node.name))
 

	
 
        self.assertEqual(tar_node.mimetype,'application/x-tar')
 
        self.assertEqual(tar_node.get_mimetype(),('application/x-tar','gzip'))
 
        self.assertEqual(tar_node.mimetype, mimetypes.guess_type(tar_node.name)[0])
 
        self.assertEqual(tar_node.get_mimetype(), mimetypes.guess_type(tar_node.name))
 

	
 
        self.assertRaises(NodeError,my_node2.get_mimetype)
 

	
 
        self.assertEqual(my_node3.mimetype,ext)
 
        self.assertEqual(my_node3.get_mimetype(),[ext,ext])
 

	
0 comments (0 inline, 0 general)