##// END OF EJS Templates
fixed VCS tests after executable big issue was fixed
marcink -
r3854:d7a5da0d default
parent child Browse files
Show More
@@ -1,183 +1,183
1 1 from __future__ import with_statement
2 2
3 3 import stat
4 4 from rhodecode.lib.vcs.nodes import DirNode
5 5 from rhodecode.lib.vcs.nodes import FileNode
6 6 from rhodecode.lib.vcs.nodes import Node
7 7 from rhodecode.lib.vcs.nodes import NodeError
8 8 from rhodecode.lib.vcs.nodes import NodeKind
9 9 from rhodecode.lib.vcs.utils.compat import unittest
10 10
11 11
12 12 class NodeBasicTest(unittest.TestCase):
13 13
14 14 def test_init(self):
15 15 """
16 16 Cannot innitialize Node objects with path with slash at the beginning.
17 17 """
18 18 wrong_paths = (
19 19 '/foo',
20 20 '/foo/bar'
21 21 )
22 22 for path in wrong_paths:
23 23 self.assertRaises(NodeError, Node, path, NodeKind.FILE)
24 24
25 25 wrong_paths = (
26 26 '/foo/',
27 27 '/foo/bar/'
28 28 )
29 29 for path in wrong_paths:
30 30 self.assertRaises(NodeError, Node, path, NodeKind.DIR)
31 31
32 32 def test_name(self):
33 33 node = Node('', NodeKind.DIR)
34 34 self.assertEqual(node.name, '')
35 35
36 36 node = Node('path', NodeKind.FILE)
37 37 self.assertEqual(node.name, 'path')
38 38
39 39 node = Node('path/', NodeKind.DIR)
40 40 self.assertEqual(node.name, 'path')
41 41
42 42 node = Node('some/path', NodeKind.FILE)
43 43 self.assertEqual(node.name, 'path')
44 44
45 45 node = Node('some/path/', NodeKind.DIR)
46 46 self.assertEqual(node.name, 'path')
47 47
48 48 def test_root_node(self):
49 49 self.assertRaises(NodeError, Node, '', NodeKind.FILE)
50 50
51 51 def test_kind_setter(self):
52 52 node = Node('', NodeKind.DIR)
53 53 self.assertRaises(NodeError, setattr, node, 'kind', NodeKind.FILE)
54 54
55 55 def _test_parent_path(self, node_path, expected_parent_path):
56 56 """
57 57 Tests if node's parent path are properly computed.
58 58 """
59 59 node = Node(node_path, NodeKind.DIR)
60 60 parent_path = node.get_parent_path()
61 61 self.assertTrue(parent_path.endswith('/') or \
62 62 node.is_root() and parent_path == '')
63 63 self.assertEqual(parent_path, expected_parent_path,
64 64 "Node's path is %r and parent path is %r but should be %r"
65 65 % (node.path, parent_path, expected_parent_path))
66 66
67 67 def test_parent_path(self):
68 68 test_paths = (
69 69 # (node_path, expected_parent_path)
70 70 ('', ''),
71 71 ('some/path/', 'some/'),
72 72 ('some/longer/path/', 'some/longer/'),
73 73 )
74 74 for node_path, expected_parent_path in test_paths:
75 75 self._test_parent_path(node_path, expected_parent_path)
76 76
77 77 '''
78 78 def _test_trailing_slash(self, path):
79 79 if not path.endswith('/'):
80 80 self.fail("Trailing slash tests needs paths to end with slash")
81 81 for kind in NodeKind.FILE, NodeKind.DIR:
82 82 self.assertRaises(NodeError, Node, path=path, kind=kind)
83 83
84 84 def test_trailing_slash(self):
85 85 for path in ('/', 'foo/', 'foo/bar/', 'foo/bar/biz/'):
86 86 self._test_trailing_slash(path)
87 87 '''
88 88
89 89 def test_is_file(self):
90 90 node = Node('any', NodeKind.FILE)
91 91 self.assertTrue(node.is_file())
92 92
93 93 node = FileNode('any')
94 94 self.assertTrue(node.is_file())
95 95 self.assertRaises(AttributeError, getattr, node, 'nodes')
96 96
97 97 def test_is_dir(self):
98 98 node = Node('any_dir', NodeKind.DIR)
99 99 self.assertTrue(node.is_dir())
100 100
101 101 node = DirNode('any_dir')
102 102
103 103 self.assertTrue(node.is_dir())
104 104 self.assertRaises(NodeError, getattr, node, 'content')
105 105
106 106 def test_dir_node_iter(self):
107 107 nodes = [
108 108 DirNode('docs'),
109 109 DirNode('tests'),
110 110 FileNode('bar'),
111 111 FileNode('foo'),
112 112 FileNode('readme.txt'),
113 113 FileNode('setup.py'),
114 114 ]
115 115 dirnode = DirNode('', nodes=nodes)
116 116 for node in dirnode:
117 117 node == dirnode.get_node(node.path)
118 118
119 119 def test_node_state(self):
120 120 """
121 121 Without link to changeset nodes should raise NodeError.
122 122 """
123 123 node = FileNode('anything')
124 124 self.assertRaises(NodeError, getattr, node, 'state')
125 125 node = DirNode('anything')
126 126 self.assertRaises(NodeError, getattr, node, 'state')
127 127
128 128 def test_file_node_stat(self):
129 129 node = FileNode('foobar', 'empty... almost')
130 130 mode = node.mode # default should be 0100644
131 131 self.assertTrue(mode & stat.S_IRUSR)
132 132 self.assertTrue(mode & stat.S_IWUSR)
133 133 self.assertTrue(mode & stat.S_IRGRP)
134 134 self.assertTrue(mode & stat.S_IROTH)
135 135 self.assertFalse(mode & stat.S_IWGRP)
136 136 self.assertFalse(mode & stat.S_IWOTH)
137 137 self.assertFalse(mode & stat.S_IXUSR)
138 138 self.assertFalse(mode & stat.S_IXGRP)
139 139 self.assertFalse(mode & stat.S_IXOTH)
140 140
141 141 def test_file_node_is_executable(self):
142 142 node = FileNode('foobar', 'empty... almost', mode=0100755)
143 self.assertTrue(node.is_executable())
143 self.assertTrue(node.is_executable)
144 144
145 145 node = FileNode('foobar', 'empty... almost', mode=0100500)
146 self.assertTrue(node.is_executable())
146 self.assertTrue(node.is_executable)
147 147
148 148 node = FileNode('foobar', 'empty... almost', mode=0100644)
149 self.assertFalse(node.is_executable())
149 self.assertFalse(node.is_executable)
150 150
151 151 def test_mimetype(self):
152 152 py_node = FileNode('test.py')
153 153 tar_node = FileNode('test.tar.gz')
154 154
155 155 ext = 'CustomExtension'
156 156
157 157 my_node2 = FileNode('myfile2')
158 158 my_node2._mimetype = [ext]
159 159
160 160 my_node3 = FileNode('myfile3')
161 161 my_node3._mimetype = [ext,ext]
162 162
163 163 self.assertEqual(py_node.mimetype,'text/x-python')
164 164 self.assertEqual(py_node.get_mimetype(),('text/x-python',None))
165 165
166 166 self.assertEqual(tar_node.mimetype,'application/x-tar')
167 167 self.assertEqual(tar_node.get_mimetype(),('application/x-tar','gzip'))
168 168
169 169 self.assertRaises(NodeError,my_node2.get_mimetype)
170 170
171 171 self.assertEqual(my_node3.mimetype,ext)
172 172 self.assertEqual(my_node3.get_mimetype(),[ext,ext])
173 173
174 174 class NodeContentTest(unittest.TestCase):
175 175
176 176 def test_if_binary(self):
177 177 data = """\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f??a\x00\x00\x00\x04gAMA\x00\x00\xaf?7\x05\x8a?\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq?e<\x00\x00\x025IDAT8?\xa5\x93?K\x94Q\x14\x87\x9f\xf7?Q\x1bs4?\x03\x9a\xa8?B\x02\x8b$\x10[U;i\x13?6h?&h[?"\x14j?\xa2M\x7fB\x14F\x9aQ?&\x842?\x0b\x89"\x82??!?\x9c!\x9c2l??{N\x8bW\x9dY\xb4\t/\x1c?=\x9b?}????\xa9*;9!?\x83\x91?[?\\v*?D\x04\'`EpNp\xa2X\'U?pVq"Sw.\x1e?\x08\x01D?jw????\xbc??7{|\x9b?\x89$\x01??W@\x15\x9c\x05q`Lt/\x97?\x94\xa1d?\x18~?\x18?\x18W[%\xb0?\x83??\x14\x88\x8dB?\xa6H\tL\tl\x19>/\x01`\xac\xabx?\x9cl\nx\xb0\x98\x07\x95\x88D$"q[\x19?d\x00(o\n\xa0??\x7f\xb9\xa4?\x1bF\x1f\x8e\xac\xa8?j??eUU}?.?\x9f\x8cE??x\x94??\r\xbdtoJU5"0N\x10U?\x00??V\t\x02\x9f\x81?U?\x00\x9eM\xae2?r\x9b7\x83\x82\x8aP3????.?&"?\xb7ZP \x0c<?O\xa5\t}\xb8?\x99\xa6?\x87?\x1di|/\xa0??0\xbe\x1fp?d&\x1a\xad\x95\x8a\x07?\t*\x10??b:?d?.\x13C\x8a?\x12\xbe\xbf\x8e?{???\x08?\x80\xa7\x13+d\x13>J?\x80\x15T\x95\x9a\x00??S\x8c\r?\xa1\x03\x07?\x96\x9b\xa7\xab=E??\xa4\xb3?\x19q??B\x91=\x8d??k?J\x0bV"??\xf7x?\xa1\x00?\\.\x87\x87???\x02F@D\x99],??\x10#?X\xb7=\xb9\x10?Z\x1by???cI??\x1ag?\x92\xbc?T?t[\x92\x81?<_\x17~\x92\x88?H%?\x10Q\x02\x9f\n\x81qQ\x0bm?\x1bX?\xb1AK\xa6\x9e\xb9?u\xb2?1\xbe|/\x92M@\xa2!F?\xa9>"\r<DT?>\x92\x8e?>\x9a9Qv\x127?a\xac?Y?8?:??]X???9\x80\xb7?u?\x0b#BZ\x8d=\x1d?p\x00\x00\x00\x00IEND\xaeB`\x82"""
178 178 filenode = FileNode('calendar.png', content=data)
179 179 self.assertTrue(filenode.is_binary)
180 180
181 181
182 182 if __name__ == '__main__':
183 183 unittest.main()
@@ -1,216 +1,216
1 1 from __future__ import with_statement
2 2 import datetime
3 3 from base import BackendTestMixin
4 4 from conf import SCM_TESTS
5 5 from conf import TEST_USER_CONFIG_FILE
6 6 from rhodecode.lib.vcs.nodes import FileNode
7 7 from rhodecode.lib.vcs.utils.compat import unittest
8 8 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
9 9
10 10
11 11 class RepositoryBaseTest(BackendTestMixin):
12 12 recreate_repo_per_test = False
13 13
14 14 @classmethod
15 15 def _get_commits(cls):
16 16 return super(RepositoryBaseTest, cls)._get_commits()[:1]
17 17
18 18 def test_get_config_value(self):
19 19 self.assertEqual(self.repo.get_config_value('universal', 'foo',
20 20 TEST_USER_CONFIG_FILE), 'bar')
21 21
22 22 def test_get_config_value_defaults_to_None(self):
23 23 self.assertEqual(self.repo.get_config_value('universal', 'nonexist',
24 24 TEST_USER_CONFIG_FILE), None)
25 25
26 26 def test_get_user_name(self):
27 27 self.assertEqual(self.repo.get_user_name(TEST_USER_CONFIG_FILE),
28 28 'Foo Bar')
29 29
30 30 def test_get_user_email(self):
31 31 self.assertEqual(self.repo.get_user_email(TEST_USER_CONFIG_FILE),
32 32 'foo.bar@example.com')
33 33
34 34
35 35
36 36 class RepositoryGetDiffTest(BackendTestMixin):
37 37
38 38 @classmethod
39 39 def _get_commits(cls):
40 40 commits = [
41 41 {
42 42 'message': 'Initial commit',
43 43 'author': 'Joe Doe <joe.doe@example.com>',
44 44 'date': datetime.datetime(2010, 1, 1, 20),
45 45 'added': [
46 46 FileNode('foobar', content='foobar'),
47 47 FileNode('foobar2', content='foobar2'),
48 48 ],
49 49 },
50 50 {
51 51 'message': 'Changed foobar, added foobar3',
52 52 'author': 'Jane Doe <jane.doe@example.com>',
53 53 'date': datetime.datetime(2010, 1, 1, 21),
54 54 'added': [
55 55 FileNode('foobar3', content='foobar3'),
56 56 ],
57 57 'changed': [
58 58 FileNode('foobar', 'FOOBAR'),
59 59 ],
60 60 },
61 61 {
62 62 'message': 'Removed foobar, changed foobar3',
63 63 'author': 'Jane Doe <jane.doe@example.com>',
64 64 'date': datetime.datetime(2010, 1, 1, 22),
65 65 'changed': [
66 66 FileNode('foobar3', content='FOOBAR\nFOOBAR\nFOOBAR\n'),
67 67 ],
68 68 'removed': [FileNode('foobar')],
69 69 },
70 70 ]
71 71 return commits
72 72
73 73 def test_raise_for_wrong(self):
74 74 with self.assertRaises(ChangesetDoesNotExistError):
75 75 self.repo.get_diff('a' * 40, 'b' * 40)
76 76
77 77
78 78 class GitRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase):
79 79 backend_alias = 'git'
80 80
81 81 def test_initial_commit_diff(self):
82 82 initial_rev = self.repo.revisions[0]
83 83 self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar
84 84 new file mode 100644
85 85 index 0000000000000000000000000000000000000000..f6ea0495187600e7b2288c8ac19c5886383a4632
86 86 --- /dev/null
87 87 +++ b/foobar
88 88 @@ -0,0 +1 @@
89 89 +foobar
90 90 \ No newline at end of file
91 91 diff --git a/foobar2 b/foobar2
92 92 new file mode 100644
93 93 index 0000000000000000000000000000000000000000..e8c9d6b98e3dce993a464935e1a53f50b56a3783
94 94 --- /dev/null
95 95 +++ b/foobar2
96 96 @@ -0,0 +1 @@
97 97 +foobar2
98 98 \ No newline at end of file
99 99 ''')
100 100
101 101 def test_second_changeset_diff(self):
102 102 revs = self.repo.revisions
103 103 self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar
104 104 index f6ea0495187600e7b2288c8ac19c5886383a4632..389865bb681b358c9b102d79abd8d5f941e96551 100644
105 105 --- a/foobar
106 106 +++ b/foobar
107 107 @@ -1 +1 @@
108 108 -foobar
109 109 \ No newline at end of file
110 110 +FOOBAR
111 111 \ No newline at end of file
112 112 diff --git a/foobar3 b/foobar3
113 113 new file mode 100644
114 114 index 0000000000000000000000000000000000000000..c11c37d41d33fb47741cff93fa5f9d798c1535b0
115 115 --- /dev/null
116 116 +++ b/foobar3
117 117 @@ -0,0 +1 @@
118 118 +foobar3
119 119 \ No newline at end of file
120 120 ''')
121 121
122 122 def test_third_changeset_diff(self):
123 123 revs = self.repo.revisions
124 124 self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar
125 125 deleted file mode 100644
126 126 index 389865bb681b358c9b102d79abd8d5f941e96551..0000000000000000000000000000000000000000
127 127 --- a/foobar
128 128 +++ /dev/null
129 129 @@ -1 +0,0 @@
130 130 -FOOBAR
131 131 \ No newline at end of file
132 132 diff --git a/foobar3 b/foobar3
133 133 index c11c37d41d33fb47741cff93fa5f9d798c1535b0..f9324477362684ff692aaf5b9a81e01b9e9a671c 100644
134 134 --- a/foobar3
135 135 +++ b/foobar3
136 136 @@ -1 +1,3 @@
137 137 -foobar3
138 138 \ No newline at end of file
139 139 +FOOBAR
140 140 +FOOBAR
141 141 +FOOBAR
142 142 ''')
143 143
144 144
145 145 class HgRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase):
146 146 backend_alias = 'hg'
147 147
148 148 def test_initial_commit_diff(self):
149 149 initial_rev = self.repo.revisions[0]
150 150 self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar
151 new file mode 100755
151 new file mode 100644
152 152 --- /dev/null
153 153 +++ b/foobar
154 154 @@ -0,0 +1,1 @@
155 155 +foobar
156 156 \ No newline at end of file
157 157 diff --git a/foobar2 b/foobar2
158 new file mode 100755
158 new file mode 100644
159 159 --- /dev/null
160 160 +++ b/foobar2
161 161 @@ -0,0 +1,1 @@
162 162 +foobar2
163 163 \ No newline at end of file
164 164 ''')
165 165
166 166 def test_second_changeset_diff(self):
167 167 revs = self.repo.revisions
168 168 self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar
169 169 --- a/foobar
170 170 +++ b/foobar
171 171 @@ -1,1 +1,1 @@
172 172 -foobar
173 173 \ No newline at end of file
174 174 +FOOBAR
175 175 \ No newline at end of file
176 176 diff --git a/foobar3 b/foobar3
177 new file mode 100755
177 new file mode 100644
178 178 --- /dev/null
179 179 +++ b/foobar3
180 180 @@ -0,0 +1,1 @@
181 181 +foobar3
182 182 \ No newline at end of file
183 183 ''')
184 184
185 185 def test_third_changeset_diff(self):
186 186 revs = self.repo.revisions
187 187 self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar
188 deleted file mode 100755
188 deleted file mode 100644
189 189 --- a/foobar
190 190 +++ /dev/null
191 191 @@ -1,1 +0,0 @@
192 192 -FOOBAR
193 193 \ No newline at end of file
194 194 diff --git a/foobar3 b/foobar3
195 195 --- a/foobar3
196 196 +++ b/foobar3
197 197 @@ -1,1 +1,3 @@
198 198 -foobar3
199 199 \ No newline at end of file
200 200 +FOOBAR
201 201 +FOOBAR
202 202 +FOOBAR
203 203 ''')
204 204
205 205
206 206 # For each backend create test case class
207 207 for alias in SCM_TESTS:
208 208 attrs = {
209 209 'backend_alias': alias,
210 210 }
211 211 cls_name = alias.capitalize() + RepositoryBaseTest.__name__
212 212 bases = (RepositoryBaseTest, unittest.TestCase)
213 213 globals()[cls_name] = type(cls_name, bases, attrs)
214 214
215 215 if __name__ == '__main__':
216 216 unittest.main()
General Comments 0
You need to be logged in to leave comments. Login now