changeset 6651:986efdcfaf64

vcs: remove unused code and test of it Neither git nor mercurial nodes have a _mimetype attribute. Only test_nodes.test_mimetype monkey patches it and that to me seems just wrong. Thus, remove that part and fix the test with some usefull assertions. Found by pylint.
author domruf <dominikruf@gmail.com>
date Thu, 11 May 2017 00:19:14 +0200
parents e62b86858683
children b60fb9461b18
files kallithea/lib/vcs/nodes.py kallithea/tests/vcs/test_nodes.py
diffstat 2 files changed, 7 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/nodes.py	Wed May 10 23:14:12 2017 +0200
+++ b/kallithea/lib/vcs/nodes.py	Thu May 11 00:19:14 2017 +0200
@@ -315,18 +315,8 @@
 
     def get_mimetype(self):
         """
-        Mimetype is calculated based on the file's content. If ``_mimetype``
-        attribute is available, it will be returned (backends which store
-        mimetypes or can easily recognize them, should set this private
-        attribute to indicate that type should *NOT* be calculated).
+        Mimetype is calculated based on the file's content.
         """
-        if hasattr(self, '_mimetype'):
-            if (isinstance(self._mimetype, (tuple, list,)) and
-                len(self._mimetype) == 2):
-                return self._mimetype
-            else:
-                raise NodeError('given _mimetype attribute must be an 2 '
-                                'element list or tuple')
 
         mtype, encoding = mimetypes.guess_type(self.name)
 
--- a/kallithea/tests/vcs/test_nodes.py	Wed May 10 23:14:12 2017 +0200
+++ b/kallithea/tests/vcs/test_nodes.py	Thu May 11 00:19:14 2017 +0200
@@ -152,13 +152,11 @@
         py_node = FileNode('test.py')
         tar_node = FileNode('test.tar.gz')
 
-        ext = 'CustomExtension'
-
         my_node2 = FileNode('myfile2')
-        my_node2._mimetype = [ext]
+        my_node2._content = 'foobar'
 
         my_node3 = FileNode('myfile3')
-        my_node3._mimetype = [ext,ext]
+        my_node3._content = '\0foobar'
 
         self.assertEqual(py_node.mimetype, mimetypes.guess_type(py_node.name)[0])
         self.assertEqual(py_node.get_mimetype(), mimetypes.guess_type(py_node.name))
@@ -166,10 +164,11 @@
         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_node2.mimetype, 'text/plain')
+        self.assertEqual(my_node2.get_mimetype(), ('text/plain', None))
 
-        self.assertEqual(my_node3.mimetype,ext)
-        self.assertEqual(my_node3.get_mimetype(),[ext,ext])
+        self.assertEqual(my_node3.mimetype, 'application/octet-stream')
+        self.assertEqual(my_node3.get_mimetype(), ('application/octet-stream', None))
 
 class NodeContentTest(unittest.TestCase):