Show More
@@ -1,183 +1,183 b'' | |||||
1 | from __future__ import with_statement |
|
1 | from __future__ import with_statement | |
2 |
|
2 | |||
3 | import stat |
|
3 | import stat | |
4 | from rhodecode.lib.vcs.nodes import DirNode |
|
4 | from rhodecode.lib.vcs.nodes import DirNode | |
5 | from rhodecode.lib.vcs.nodes import FileNode |
|
5 | from rhodecode.lib.vcs.nodes import FileNode | |
6 | from rhodecode.lib.vcs.nodes import Node |
|
6 | from rhodecode.lib.vcs.nodes import Node | |
7 | from rhodecode.lib.vcs.nodes import NodeError |
|
7 | from rhodecode.lib.vcs.nodes import NodeError | |
8 | from rhodecode.lib.vcs.nodes import NodeKind |
|
8 | from rhodecode.lib.vcs.nodes import NodeKind | |
9 | from rhodecode.lib.vcs.utils.compat import unittest |
|
9 | from rhodecode.lib.vcs.utils.compat import unittest | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | class NodeBasicTest(unittest.TestCase): |
|
12 | class NodeBasicTest(unittest.TestCase): | |
13 |
|
13 | |||
14 | def test_init(self): |
|
14 | def test_init(self): | |
15 | """ |
|
15 | """ | |
16 | Cannot innitialize Node objects with path with slash at the beginning. |
|
16 | Cannot innitialize Node objects with path with slash at the beginning. | |
17 | """ |
|
17 | """ | |
18 | wrong_paths = ( |
|
18 | wrong_paths = ( | |
19 | '/foo', |
|
19 | '/foo', | |
20 | '/foo/bar' |
|
20 | '/foo/bar' | |
21 | ) |
|
21 | ) | |
22 | for path in wrong_paths: |
|
22 | for path in wrong_paths: | |
23 | self.assertRaises(NodeError, Node, path, NodeKind.FILE) |
|
23 | self.assertRaises(NodeError, Node, path, NodeKind.FILE) | |
24 |
|
24 | |||
25 | wrong_paths = ( |
|
25 | wrong_paths = ( | |
26 | '/foo/', |
|
26 | '/foo/', | |
27 | '/foo/bar/' |
|
27 | '/foo/bar/' | |
28 | ) |
|
28 | ) | |
29 | for path in wrong_paths: |
|
29 | for path in wrong_paths: | |
30 | self.assertRaises(NodeError, Node, path, NodeKind.DIR) |
|
30 | self.assertRaises(NodeError, Node, path, NodeKind.DIR) | |
31 |
|
31 | |||
32 | def test_name(self): |
|
32 | def test_name(self): | |
33 | node = Node('', NodeKind.DIR) |
|
33 | node = Node('', NodeKind.DIR) | |
34 | self.assertEqual(node.name, '') |
|
34 | self.assertEqual(node.name, '') | |
35 |
|
35 | |||
36 | node = Node('path', NodeKind.FILE) |
|
36 | node = Node('path', NodeKind.FILE) | |
37 | self.assertEqual(node.name, 'path') |
|
37 | self.assertEqual(node.name, 'path') | |
38 |
|
38 | |||
39 | node = Node('path/', NodeKind.DIR) |
|
39 | node = Node('path/', NodeKind.DIR) | |
40 | self.assertEqual(node.name, 'path') |
|
40 | self.assertEqual(node.name, 'path') | |
41 |
|
41 | |||
42 | node = Node('some/path', NodeKind.FILE) |
|
42 | node = Node('some/path', NodeKind.FILE) | |
43 | self.assertEqual(node.name, 'path') |
|
43 | self.assertEqual(node.name, 'path') | |
44 |
|
44 | |||
45 | node = Node('some/path/', NodeKind.DIR) |
|
45 | node = Node('some/path/', NodeKind.DIR) | |
46 | self.assertEqual(node.name, 'path') |
|
46 | self.assertEqual(node.name, 'path') | |
47 |
|
47 | |||
48 | def test_root_node(self): |
|
48 | def test_root_node(self): | |
49 | self.assertRaises(NodeError, Node, '', NodeKind.FILE) |
|
49 | self.assertRaises(NodeError, Node, '', NodeKind.FILE) | |
50 |
|
50 | |||
51 | def test_kind_setter(self): |
|
51 | def test_kind_setter(self): | |
52 | node = Node('', NodeKind.DIR) |
|
52 | node = Node('', NodeKind.DIR) | |
53 | self.assertRaises(NodeError, setattr, node, 'kind', NodeKind.FILE) |
|
53 | self.assertRaises(NodeError, setattr, node, 'kind', NodeKind.FILE) | |
54 |
|
54 | |||
55 | def _test_parent_path(self, node_path, expected_parent_path): |
|
55 | def _test_parent_path(self, node_path, expected_parent_path): | |
56 | """ |
|
56 | """ | |
57 | Tests if node's parent path are properly computed. |
|
57 | Tests if node's parent path are properly computed. | |
58 | """ |
|
58 | """ | |
59 | node = Node(node_path, NodeKind.DIR) |
|
59 | node = Node(node_path, NodeKind.DIR) | |
60 | parent_path = node.get_parent_path() |
|
60 | parent_path = node.get_parent_path() | |
61 | self.assertTrue(parent_path.endswith('/') or \ |
|
61 | self.assertTrue(parent_path.endswith('/') or \ | |
62 | node.is_root() and parent_path == '') |
|
62 | node.is_root() and parent_path == '') | |
63 | self.assertEqual(parent_path, expected_parent_path, |
|
63 | self.assertEqual(parent_path, expected_parent_path, | |
64 | "Node's path is %r and parent path is %r but should be %r" |
|
64 | "Node's path is %r and parent path is %r but should be %r" | |
65 | % (node.path, parent_path, expected_parent_path)) |
|
65 | % (node.path, parent_path, expected_parent_path)) | |
66 |
|
66 | |||
67 | def test_parent_path(self): |
|
67 | def test_parent_path(self): | |
68 | test_paths = ( |
|
68 | test_paths = ( | |
69 | # (node_path, expected_parent_path) |
|
69 | # (node_path, expected_parent_path) | |
70 | ('', ''), |
|
70 | ('', ''), | |
71 | ('some/path/', 'some/'), |
|
71 | ('some/path/', 'some/'), | |
72 | ('some/longer/path/', 'some/longer/'), |
|
72 | ('some/longer/path/', 'some/longer/'), | |
73 | ) |
|
73 | ) | |
74 | for node_path, expected_parent_path in test_paths: |
|
74 | for node_path, expected_parent_path in test_paths: | |
75 | self._test_parent_path(node_path, expected_parent_path) |
|
75 | self._test_parent_path(node_path, expected_parent_path) | |
76 |
|
76 | |||
77 | ''' |
|
77 | ''' | |
78 | def _test_trailing_slash(self, path): |
|
78 | def _test_trailing_slash(self, path): | |
79 | if not path.endswith('/'): |
|
79 | if not path.endswith('/'): | |
80 | self.fail("Trailing slash tests needs paths to end with slash") |
|
80 | self.fail("Trailing slash tests needs paths to end with slash") | |
81 | for kind in NodeKind.FILE, NodeKind.DIR: |
|
81 | for kind in NodeKind.FILE, NodeKind.DIR: | |
82 | self.assertRaises(NodeError, Node, path=path, kind=kind) |
|
82 | self.assertRaises(NodeError, Node, path=path, kind=kind) | |
83 |
|
83 | |||
84 | def test_trailing_slash(self): |
|
84 | def test_trailing_slash(self): | |
85 | for path in ('/', 'foo/', 'foo/bar/', 'foo/bar/biz/'): |
|
85 | for path in ('/', 'foo/', 'foo/bar/', 'foo/bar/biz/'): | |
86 | self._test_trailing_slash(path) |
|
86 | self._test_trailing_slash(path) | |
87 | ''' |
|
87 | ''' | |
88 |
|
88 | |||
89 | def test_is_file(self): |
|
89 | def test_is_file(self): | |
90 | node = Node('any', NodeKind.FILE) |
|
90 | node = Node('any', NodeKind.FILE) | |
91 | self.assertTrue(node.is_file()) |
|
91 | self.assertTrue(node.is_file()) | |
92 |
|
92 | |||
93 | node = FileNode('any') |
|
93 | node = FileNode('any') | |
94 | self.assertTrue(node.is_file()) |
|
94 | self.assertTrue(node.is_file()) | |
95 | self.assertRaises(AttributeError, getattr, node, 'nodes') |
|
95 | self.assertRaises(AttributeError, getattr, node, 'nodes') | |
96 |
|
96 | |||
97 | def test_is_dir(self): |
|
97 | def test_is_dir(self): | |
98 | node = Node('any_dir', NodeKind.DIR) |
|
98 | node = Node('any_dir', NodeKind.DIR) | |
99 | self.assertTrue(node.is_dir()) |
|
99 | self.assertTrue(node.is_dir()) | |
100 |
|
100 | |||
101 | node = DirNode('any_dir') |
|
101 | node = DirNode('any_dir') | |
102 |
|
102 | |||
103 | self.assertTrue(node.is_dir()) |
|
103 | self.assertTrue(node.is_dir()) | |
104 | self.assertRaises(NodeError, getattr, node, 'content') |
|
104 | self.assertRaises(NodeError, getattr, node, 'content') | |
105 |
|
105 | |||
106 | def test_dir_node_iter(self): |
|
106 | def test_dir_node_iter(self): | |
107 | nodes = [ |
|
107 | nodes = [ | |
108 | DirNode('docs'), |
|
108 | DirNode('docs'), | |
109 | DirNode('tests'), |
|
109 | DirNode('tests'), | |
110 | FileNode('bar'), |
|
110 | FileNode('bar'), | |
111 | FileNode('foo'), |
|
111 | FileNode('foo'), | |
112 | FileNode('readme.txt'), |
|
112 | FileNode('readme.txt'), | |
113 | FileNode('setup.py'), |
|
113 | FileNode('setup.py'), | |
114 | ] |
|
114 | ] | |
115 | dirnode = DirNode('', nodes=nodes) |
|
115 | dirnode = DirNode('', nodes=nodes) | |
116 | for node in dirnode: |
|
116 | for node in dirnode: | |
117 | node == dirnode.get_node(node.path) |
|
117 | node == dirnode.get_node(node.path) | |
118 |
|
118 | |||
119 | def test_node_state(self): |
|
119 | def test_node_state(self): | |
120 | """ |
|
120 | """ | |
121 | Without link to changeset nodes should raise NodeError. |
|
121 | Without link to changeset nodes should raise NodeError. | |
122 | """ |
|
122 | """ | |
123 | node = FileNode('anything') |
|
123 | node = FileNode('anything') | |
124 | self.assertRaises(NodeError, getattr, node, 'state') |
|
124 | self.assertRaises(NodeError, getattr, node, 'state') | |
125 | node = DirNode('anything') |
|
125 | node = DirNode('anything') | |
126 | self.assertRaises(NodeError, getattr, node, 'state') |
|
126 | self.assertRaises(NodeError, getattr, node, 'state') | |
127 |
|
127 | |||
128 | def test_file_node_stat(self): |
|
128 | def test_file_node_stat(self): | |
129 | node = FileNode('foobar', 'empty... almost') |
|
129 | node = FileNode('foobar', 'empty... almost') | |
130 | mode = node.mode # default should be 0100644 |
|
130 | mode = node.mode # default should be 0100644 | |
131 | self.assertTrue(mode & stat.S_IRUSR) |
|
131 | self.assertTrue(mode & stat.S_IRUSR) | |
132 | self.assertTrue(mode & stat.S_IWUSR) |
|
132 | self.assertTrue(mode & stat.S_IWUSR) | |
133 | self.assertTrue(mode & stat.S_IRGRP) |
|
133 | self.assertTrue(mode & stat.S_IRGRP) | |
134 | self.assertTrue(mode & stat.S_IROTH) |
|
134 | self.assertTrue(mode & stat.S_IROTH) | |
135 | self.assertFalse(mode & stat.S_IWGRP) |
|
135 | self.assertFalse(mode & stat.S_IWGRP) | |
136 | self.assertFalse(mode & stat.S_IWOTH) |
|
136 | self.assertFalse(mode & stat.S_IWOTH) | |
137 | self.assertFalse(mode & stat.S_IXUSR) |
|
137 | self.assertFalse(mode & stat.S_IXUSR) | |
138 | self.assertFalse(mode & stat.S_IXGRP) |
|
138 | self.assertFalse(mode & stat.S_IXGRP) | |
139 | self.assertFalse(mode & stat.S_IXOTH) |
|
139 | self.assertFalse(mode & stat.S_IXOTH) | |
140 |
|
140 | |||
141 | def test_file_node_is_executable(self): |
|
141 | def test_file_node_is_executable(self): | |
142 | node = FileNode('foobar', 'empty... almost', mode=0100755) |
|
142 | node = FileNode('foobar', 'empty... almost', mode=0100755) | |
143 |
self.assertTrue(node.is_executable |
|
143 | self.assertTrue(node.is_executable) | |
144 |
|
144 | |||
145 | node = FileNode('foobar', 'empty... almost', mode=0100500) |
|
145 | node = FileNode('foobar', 'empty... almost', mode=0100500) | |
146 |
self.assertTrue(node.is_executable |
|
146 | self.assertTrue(node.is_executable) | |
147 |
|
147 | |||
148 | node = FileNode('foobar', 'empty... almost', mode=0100644) |
|
148 | node = FileNode('foobar', 'empty... almost', mode=0100644) | |
149 |
self.assertFalse(node.is_executable |
|
149 | self.assertFalse(node.is_executable) | |
150 |
|
150 | |||
151 | def test_mimetype(self): |
|
151 | def test_mimetype(self): | |
152 | py_node = FileNode('test.py') |
|
152 | py_node = FileNode('test.py') | |
153 | tar_node = FileNode('test.tar.gz') |
|
153 | tar_node = FileNode('test.tar.gz') | |
154 |
|
154 | |||
155 | ext = 'CustomExtension' |
|
155 | ext = 'CustomExtension' | |
156 |
|
156 | |||
157 | my_node2 = FileNode('myfile2') |
|
157 | my_node2 = FileNode('myfile2') | |
158 | my_node2._mimetype = [ext] |
|
158 | my_node2._mimetype = [ext] | |
159 |
|
159 | |||
160 | my_node3 = FileNode('myfile3') |
|
160 | my_node3 = FileNode('myfile3') | |
161 | my_node3._mimetype = [ext,ext] |
|
161 | my_node3._mimetype = [ext,ext] | |
162 |
|
162 | |||
163 | self.assertEqual(py_node.mimetype,'text/x-python') |
|
163 | self.assertEqual(py_node.mimetype,'text/x-python') | |
164 | self.assertEqual(py_node.get_mimetype(),('text/x-python',None)) |
|
164 | self.assertEqual(py_node.get_mimetype(),('text/x-python',None)) | |
165 |
|
165 | |||
166 | self.assertEqual(tar_node.mimetype,'application/x-tar') |
|
166 | self.assertEqual(tar_node.mimetype,'application/x-tar') | |
167 | self.assertEqual(tar_node.get_mimetype(),('application/x-tar','gzip')) |
|
167 | self.assertEqual(tar_node.get_mimetype(),('application/x-tar','gzip')) | |
168 |
|
168 | |||
169 | self.assertRaises(NodeError,my_node2.get_mimetype) |
|
169 | self.assertRaises(NodeError,my_node2.get_mimetype) | |
170 |
|
170 | |||
171 | self.assertEqual(my_node3.mimetype,ext) |
|
171 | self.assertEqual(my_node3.mimetype,ext) | |
172 | self.assertEqual(my_node3.get_mimetype(),[ext,ext]) |
|
172 | self.assertEqual(my_node3.get_mimetype(),[ext,ext]) | |
173 |
|
173 | |||
174 | class NodeContentTest(unittest.TestCase): |
|
174 | class NodeContentTest(unittest.TestCase): | |
175 |
|
175 | |||
176 | def test_if_binary(self): |
|
176 | def test_if_binary(self): | |
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""" |
|
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 | filenode = FileNode('calendar.png', content=data) |
|
178 | filenode = FileNode('calendar.png', content=data) | |
179 | self.assertTrue(filenode.is_binary) |
|
179 | self.assertTrue(filenode.is_binary) | |
180 |
|
180 | |||
181 |
|
181 | |||
182 | if __name__ == '__main__': |
|
182 | if __name__ == '__main__': | |
183 | unittest.main() |
|
183 | unittest.main() |
@@ -1,229 +1,229 b'' | |||||
1 | from __future__ import with_statement |
|
1 | from __future__ import with_statement | |
2 | import datetime |
|
2 | import datetime | |
3 | from rhodecode.tests.vcs.base import BackendTestMixin |
|
3 | from rhodecode.tests.vcs.base import BackendTestMixin | |
4 | from rhodecode.tests.vcs.conf import SCM_TESTS |
|
4 | from rhodecode.tests.vcs.conf import SCM_TESTS | |
5 | from rhodecode.tests.vcs.conf import TEST_USER_CONFIG_FILE |
|
5 | from rhodecode.tests.vcs.conf import TEST_USER_CONFIG_FILE | |
6 | from rhodecode.lib.vcs.nodes import FileNode |
|
6 | from rhodecode.lib.vcs.nodes import FileNode | |
7 | from rhodecode.lib.vcs.utils.compat import unittest |
|
7 | from rhodecode.lib.vcs.utils.compat import unittest | |
8 | from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError |
|
8 | from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | class RepositoryBaseTest(BackendTestMixin): |
|
11 | class RepositoryBaseTest(BackendTestMixin): | |
12 | recreate_repo_per_test = False |
|
12 | recreate_repo_per_test = False | |
13 |
|
13 | |||
14 | @classmethod |
|
14 | @classmethod | |
15 | def _get_commits(cls): |
|
15 | def _get_commits(cls): | |
16 | return super(RepositoryBaseTest, cls)._get_commits()[:1] |
|
16 | return super(RepositoryBaseTest, cls)._get_commits()[:1] | |
17 |
|
17 | |||
18 | def test_get_config_value(self): |
|
18 | def test_get_config_value(self): | |
19 | self.assertEqual(self.repo.get_config_value('universal', 'foo', |
|
19 | self.assertEqual(self.repo.get_config_value('universal', 'foo', | |
20 | TEST_USER_CONFIG_FILE), 'bar') |
|
20 | TEST_USER_CONFIG_FILE), 'bar') | |
21 |
|
21 | |||
22 | def test_get_config_value_defaults_to_None(self): |
|
22 | def test_get_config_value_defaults_to_None(self): | |
23 | self.assertEqual(self.repo.get_config_value('universal', 'nonexist', |
|
23 | self.assertEqual(self.repo.get_config_value('universal', 'nonexist', | |
24 | TEST_USER_CONFIG_FILE), None) |
|
24 | TEST_USER_CONFIG_FILE), None) | |
25 |
|
25 | |||
26 | def test_get_user_name(self): |
|
26 | def test_get_user_name(self): | |
27 | self.assertEqual(self.repo.get_user_name(TEST_USER_CONFIG_FILE), |
|
27 | self.assertEqual(self.repo.get_user_name(TEST_USER_CONFIG_FILE), | |
28 | 'Foo Bar') |
|
28 | 'Foo Bar') | |
29 |
|
29 | |||
30 | def test_get_user_email(self): |
|
30 | def test_get_user_email(self): | |
31 | self.assertEqual(self.repo.get_user_email(TEST_USER_CONFIG_FILE), |
|
31 | self.assertEqual(self.repo.get_user_email(TEST_USER_CONFIG_FILE), | |
32 | 'foo.bar@example.com') |
|
32 | 'foo.bar@example.com') | |
33 |
|
33 | |||
34 | def test_repo_equality(self): |
|
34 | def test_repo_equality(self): | |
35 | self.assertTrue(self.repo == self.repo) |
|
35 | self.assertTrue(self.repo == self.repo) | |
36 |
|
36 | |||
37 | def test_repo_equality_broken_object(self): |
|
37 | def test_repo_equality_broken_object(self): | |
38 | import copy |
|
38 | import copy | |
39 | _repo = copy.copy(self.repo) |
|
39 | _repo = copy.copy(self.repo) | |
40 | delattr(_repo, 'path') |
|
40 | delattr(_repo, 'path') | |
41 | self.assertTrue(self.repo != _repo) |
|
41 | self.assertTrue(self.repo != _repo) | |
42 |
|
42 | |||
43 | def test_repo_equality_other_object(self): |
|
43 | def test_repo_equality_other_object(self): | |
44 | class dummy(object): |
|
44 | class dummy(object): | |
45 | path = self.repo.path |
|
45 | path = self.repo.path | |
46 | self.assertTrue(self.repo != dummy()) |
|
46 | self.assertTrue(self.repo != dummy()) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | class RepositoryGetDiffTest(BackendTestMixin): |
|
49 | class RepositoryGetDiffTest(BackendTestMixin): | |
50 |
|
50 | |||
51 | @classmethod |
|
51 | @classmethod | |
52 | def _get_commits(cls): |
|
52 | def _get_commits(cls): | |
53 | commits = [ |
|
53 | commits = [ | |
54 | { |
|
54 | { | |
55 | 'message': 'Initial commit', |
|
55 | 'message': 'Initial commit', | |
56 | 'author': 'Joe Doe <joe.doe@example.com>', |
|
56 | 'author': 'Joe Doe <joe.doe@example.com>', | |
57 | 'date': datetime.datetime(2010, 1, 1, 20), |
|
57 | 'date': datetime.datetime(2010, 1, 1, 20), | |
58 | 'added': [ |
|
58 | 'added': [ | |
59 | FileNode('foobar', content='foobar'), |
|
59 | FileNode('foobar', content='foobar'), | |
60 | FileNode('foobar2', content='foobar2'), |
|
60 | FileNode('foobar2', content='foobar2'), | |
61 | ], |
|
61 | ], | |
62 | }, |
|
62 | }, | |
63 | { |
|
63 | { | |
64 | 'message': 'Changed foobar, added foobar3', |
|
64 | 'message': 'Changed foobar, added foobar3', | |
65 | 'author': 'Jane Doe <jane.doe@example.com>', |
|
65 | 'author': 'Jane Doe <jane.doe@example.com>', | |
66 | 'date': datetime.datetime(2010, 1, 1, 21), |
|
66 | 'date': datetime.datetime(2010, 1, 1, 21), | |
67 | 'added': [ |
|
67 | 'added': [ | |
68 | FileNode('foobar3', content='foobar3'), |
|
68 | FileNode('foobar3', content='foobar3'), | |
69 | ], |
|
69 | ], | |
70 | 'changed': [ |
|
70 | 'changed': [ | |
71 | FileNode('foobar', 'FOOBAR'), |
|
71 | FileNode('foobar', 'FOOBAR'), | |
72 | ], |
|
72 | ], | |
73 | }, |
|
73 | }, | |
74 | { |
|
74 | { | |
75 | 'message': 'Removed foobar, changed foobar3', |
|
75 | 'message': 'Removed foobar, changed foobar3', | |
76 | 'author': 'Jane Doe <jane.doe@example.com>', |
|
76 | 'author': 'Jane Doe <jane.doe@example.com>', | |
77 | 'date': datetime.datetime(2010, 1, 1, 22), |
|
77 | 'date': datetime.datetime(2010, 1, 1, 22), | |
78 | 'changed': [ |
|
78 | 'changed': [ | |
79 | FileNode('foobar3', content='FOOBAR\nFOOBAR\nFOOBAR\n'), |
|
79 | FileNode('foobar3', content='FOOBAR\nFOOBAR\nFOOBAR\n'), | |
80 | ], |
|
80 | ], | |
81 | 'removed': [FileNode('foobar')], |
|
81 | 'removed': [FileNode('foobar')], | |
82 | }, |
|
82 | }, | |
83 | ] |
|
83 | ] | |
84 | return commits |
|
84 | return commits | |
85 |
|
85 | |||
86 | def test_raise_for_wrong(self): |
|
86 | def test_raise_for_wrong(self): | |
87 | with self.assertRaises(ChangesetDoesNotExistError): |
|
87 | with self.assertRaises(ChangesetDoesNotExistError): | |
88 | self.repo.get_diff('a' * 40, 'b' * 40) |
|
88 | self.repo.get_diff('a' * 40, 'b' * 40) | |
89 |
|
89 | |||
90 |
|
90 | |||
91 | class GitRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase): |
|
91 | class GitRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase): | |
92 | backend_alias = 'git' |
|
92 | backend_alias = 'git' | |
93 |
|
93 | |||
94 | def test_initial_commit_diff(self): |
|
94 | def test_initial_commit_diff(self): | |
95 | initial_rev = self.repo.revisions[0] |
|
95 | initial_rev = self.repo.revisions[0] | |
96 | self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar |
|
96 | self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar | |
97 | new file mode 100644 |
|
97 | new file mode 100644 | |
98 | index 0000000000000000000000000000000000000000..f6ea0495187600e7b2288c8ac19c5886383a4632 |
|
98 | index 0000000000000000000000000000000000000000..f6ea0495187600e7b2288c8ac19c5886383a4632 | |
99 | --- /dev/null |
|
99 | --- /dev/null | |
100 | +++ b/foobar |
|
100 | +++ b/foobar | |
101 | @@ -0,0 +1 @@ |
|
101 | @@ -0,0 +1 @@ | |
102 | +foobar |
|
102 | +foobar | |
103 | \ No newline at end of file |
|
103 | \ No newline at end of file | |
104 | diff --git a/foobar2 b/foobar2 |
|
104 | diff --git a/foobar2 b/foobar2 | |
105 | new file mode 100644 |
|
105 | new file mode 100644 | |
106 | index 0000000000000000000000000000000000000000..e8c9d6b98e3dce993a464935e1a53f50b56a3783 |
|
106 | index 0000000000000000000000000000000000000000..e8c9d6b98e3dce993a464935e1a53f50b56a3783 | |
107 | --- /dev/null |
|
107 | --- /dev/null | |
108 | +++ b/foobar2 |
|
108 | +++ b/foobar2 | |
109 | @@ -0,0 +1 @@ |
|
109 | @@ -0,0 +1 @@ | |
110 | +foobar2 |
|
110 | +foobar2 | |
111 | \ No newline at end of file |
|
111 | \ No newline at end of file | |
112 | ''') |
|
112 | ''') | |
113 |
|
113 | |||
114 | def test_second_changeset_diff(self): |
|
114 | def test_second_changeset_diff(self): | |
115 | revs = self.repo.revisions |
|
115 | revs = self.repo.revisions | |
116 | self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar |
|
116 | self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar | |
117 | index f6ea0495187600e7b2288c8ac19c5886383a4632..389865bb681b358c9b102d79abd8d5f941e96551 100644 |
|
117 | index f6ea0495187600e7b2288c8ac19c5886383a4632..389865bb681b358c9b102d79abd8d5f941e96551 100644 | |
118 | --- a/foobar |
|
118 | --- a/foobar | |
119 | +++ b/foobar |
|
119 | +++ b/foobar | |
120 | @@ -1 +1 @@ |
|
120 | @@ -1 +1 @@ | |
121 | -foobar |
|
121 | -foobar | |
122 | \ No newline at end of file |
|
122 | \ No newline at end of file | |
123 | +FOOBAR |
|
123 | +FOOBAR | |
124 | \ No newline at end of file |
|
124 | \ No newline at end of file | |
125 | diff --git a/foobar3 b/foobar3 |
|
125 | diff --git a/foobar3 b/foobar3 | |
126 | new file mode 100644 |
|
126 | new file mode 100644 | |
127 | index 0000000000000000000000000000000000000000..c11c37d41d33fb47741cff93fa5f9d798c1535b0 |
|
127 | index 0000000000000000000000000000000000000000..c11c37d41d33fb47741cff93fa5f9d798c1535b0 | |
128 | --- /dev/null |
|
128 | --- /dev/null | |
129 | +++ b/foobar3 |
|
129 | +++ b/foobar3 | |
130 | @@ -0,0 +1 @@ |
|
130 | @@ -0,0 +1 @@ | |
131 | +foobar3 |
|
131 | +foobar3 | |
132 | \ No newline at end of file |
|
132 | \ No newline at end of file | |
133 | ''') |
|
133 | ''') | |
134 |
|
134 | |||
135 | def test_third_changeset_diff(self): |
|
135 | def test_third_changeset_diff(self): | |
136 | revs = self.repo.revisions |
|
136 | revs = self.repo.revisions | |
137 | self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar |
|
137 | self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar | |
138 | deleted file mode 100644 |
|
138 | deleted file mode 100644 | |
139 | index 389865bb681b358c9b102d79abd8d5f941e96551..0000000000000000000000000000000000000000 |
|
139 | index 389865bb681b358c9b102d79abd8d5f941e96551..0000000000000000000000000000000000000000 | |
140 | --- a/foobar |
|
140 | --- a/foobar | |
141 | +++ /dev/null |
|
141 | +++ /dev/null | |
142 | @@ -1 +0,0 @@ |
|
142 | @@ -1 +0,0 @@ | |
143 | -FOOBAR |
|
143 | -FOOBAR | |
144 | \ No newline at end of file |
|
144 | \ No newline at end of file | |
145 | diff --git a/foobar3 b/foobar3 |
|
145 | diff --git a/foobar3 b/foobar3 | |
146 | index c11c37d41d33fb47741cff93fa5f9d798c1535b0..f9324477362684ff692aaf5b9a81e01b9e9a671c 100644 |
|
146 | index c11c37d41d33fb47741cff93fa5f9d798c1535b0..f9324477362684ff692aaf5b9a81e01b9e9a671c 100644 | |
147 | --- a/foobar3 |
|
147 | --- a/foobar3 | |
148 | +++ b/foobar3 |
|
148 | +++ b/foobar3 | |
149 | @@ -1 +1,3 @@ |
|
149 | @@ -1 +1,3 @@ | |
150 | -foobar3 |
|
150 | -foobar3 | |
151 | \ No newline at end of file |
|
151 | \ No newline at end of file | |
152 | +FOOBAR |
|
152 | +FOOBAR | |
153 | +FOOBAR |
|
153 | +FOOBAR | |
154 | +FOOBAR |
|
154 | +FOOBAR | |
155 | ''') |
|
155 | ''') | |
156 |
|
156 | |||
157 |
|
157 | |||
158 | class HgRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase): |
|
158 | class HgRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase): | |
159 | backend_alias = 'hg' |
|
159 | backend_alias = 'hg' | |
160 |
|
160 | |||
161 | def test_initial_commit_diff(self): |
|
161 | def test_initial_commit_diff(self): | |
162 | initial_rev = self.repo.revisions[0] |
|
162 | initial_rev = self.repo.revisions[0] | |
163 | self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar |
|
163 | self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar | |
164 |
new file mode 100 |
|
164 | new file mode 100644 | |
165 | --- /dev/null |
|
165 | --- /dev/null | |
166 | +++ b/foobar |
|
166 | +++ b/foobar | |
167 | @@ -0,0 +1,1 @@ |
|
167 | @@ -0,0 +1,1 @@ | |
168 | +foobar |
|
168 | +foobar | |
169 | \ No newline at end of file |
|
169 | \ No newline at end of file | |
170 | diff --git a/foobar2 b/foobar2 |
|
170 | diff --git a/foobar2 b/foobar2 | |
171 |
new file mode 100 |
|
171 | new file mode 100644 | |
172 | --- /dev/null |
|
172 | --- /dev/null | |
173 | +++ b/foobar2 |
|
173 | +++ b/foobar2 | |
174 | @@ -0,0 +1,1 @@ |
|
174 | @@ -0,0 +1,1 @@ | |
175 | +foobar2 |
|
175 | +foobar2 | |
176 | \ No newline at end of file |
|
176 | \ No newline at end of file | |
177 | ''') |
|
177 | ''') | |
178 |
|
178 | |||
179 | def test_second_changeset_diff(self): |
|
179 | def test_second_changeset_diff(self): | |
180 | revs = self.repo.revisions |
|
180 | revs = self.repo.revisions | |
181 | self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar |
|
181 | self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar | |
182 | --- a/foobar |
|
182 | --- a/foobar | |
183 | +++ b/foobar |
|
183 | +++ b/foobar | |
184 | @@ -1,1 +1,1 @@ |
|
184 | @@ -1,1 +1,1 @@ | |
185 | -foobar |
|
185 | -foobar | |
186 | \ No newline at end of file |
|
186 | \ No newline at end of file | |
187 | +FOOBAR |
|
187 | +FOOBAR | |
188 | \ No newline at end of file |
|
188 | \ No newline at end of file | |
189 | diff --git a/foobar3 b/foobar3 |
|
189 | diff --git a/foobar3 b/foobar3 | |
190 |
new file mode 100 |
|
190 | new file mode 100644 | |
191 | --- /dev/null |
|
191 | --- /dev/null | |
192 | +++ b/foobar3 |
|
192 | +++ b/foobar3 | |
193 | @@ -0,0 +1,1 @@ |
|
193 | @@ -0,0 +1,1 @@ | |
194 | +foobar3 |
|
194 | +foobar3 | |
195 | \ No newline at end of file |
|
195 | \ No newline at end of file | |
196 | ''') |
|
196 | ''') | |
197 |
|
197 | |||
198 | def test_third_changeset_diff(self): |
|
198 | def test_third_changeset_diff(self): | |
199 | revs = self.repo.revisions |
|
199 | revs = self.repo.revisions | |
200 | self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar |
|
200 | self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar | |
201 |
deleted file mode 100 |
|
201 | deleted file mode 100644 | |
202 | --- a/foobar |
|
202 | --- a/foobar | |
203 | +++ /dev/null |
|
203 | +++ /dev/null | |
204 | @@ -1,1 +0,0 @@ |
|
204 | @@ -1,1 +0,0 @@ | |
205 | -FOOBAR |
|
205 | -FOOBAR | |
206 | \ No newline at end of file |
|
206 | \ No newline at end of file | |
207 | diff --git a/foobar3 b/foobar3 |
|
207 | diff --git a/foobar3 b/foobar3 | |
208 | --- a/foobar3 |
|
208 | --- a/foobar3 | |
209 | +++ b/foobar3 |
|
209 | +++ b/foobar3 | |
210 | @@ -1,1 +1,3 @@ |
|
210 | @@ -1,1 +1,3 @@ | |
211 | -foobar3 |
|
211 | -foobar3 | |
212 | \ No newline at end of file |
|
212 | \ No newline at end of file | |
213 | +FOOBAR |
|
213 | +FOOBAR | |
214 | +FOOBAR |
|
214 | +FOOBAR | |
215 | +FOOBAR |
|
215 | +FOOBAR | |
216 | ''') |
|
216 | ''') | |
217 |
|
217 | |||
218 |
|
218 | |||
219 | # For each backend create test case class |
|
219 | # For each backend create test case class | |
220 | for alias in SCM_TESTS: |
|
220 | for alias in SCM_TESTS: | |
221 | attrs = { |
|
221 | attrs = { | |
222 | 'backend_alias': alias, |
|
222 | 'backend_alias': alias, | |
223 | } |
|
223 | } | |
224 | cls_name = alias.capitalize() + RepositoryBaseTest.__name__ |
|
224 | cls_name = alias.capitalize() + RepositoryBaseTest.__name__ | |
225 | bases = (RepositoryBaseTest, unittest.TestCase) |
|
225 | bases = (RepositoryBaseTest, unittest.TestCase) | |
226 | globals()[cls_name] = type(cls_name, bases, attrs) |
|
226 | globals()[cls_name] = type(cls_name, bases, attrs) | |
227 |
|
227 | |||
228 | if __name__ == '__main__': |
|
228 | if __name__ == '__main__': | |
229 | unittest.main() |
|
229 | unittest.main() |
General Comments 0
You need to be logged in to leave comments.
Login now