Mercurial > kallithea
comparison rhodecode/tests/vcs/test_repository.py @ 2451:402a96fcfa22 beta
Added vcs testsuite for better integration tests + added fetching
of two new repos into test env for rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 13 Jun 2012 23:27:33 +0200 |
parents | |
children | 32471bd1f4ee |
comparison
equal
deleted
inserted
replaced
2450:26193dba1f0e | 2451:402a96fcfa22 |
---|---|
1 from __future__ import with_statement | |
2 import datetime | |
3 from base import BackendTestMixin | |
4 from conf import SCM_TESTS | |
5 from conf import TEST_USER_CONFIG_FILE | |
6 from rhodecode.lib.vcs.nodes import FileNode | |
7 from rhodecode.lib.vcs.utils.compat import unittest | |
8 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError | |
9 | |
10 | |
11 class RepositoryBaseTest(BackendTestMixin): | |
12 recreate_repo_per_test = False | |
13 | |
14 @classmethod | |
15 def _get_commits(cls): | |
16 return super(RepositoryBaseTest, cls)._get_commits()[:1] | |
17 | |
18 def test_get_config_value(self): | |
19 self.assertEqual(self.repo.get_config_value('universal', 'foo', | |
20 TEST_USER_CONFIG_FILE), 'bar') | |
21 | |
22 def test_get_config_value_defaults_to_None(self): | |
23 self.assertEqual(self.repo.get_config_value('universal', 'nonexist', | |
24 TEST_USER_CONFIG_FILE), None) | |
25 | |
26 def test_get_user_name(self): | |
27 self.assertEqual(self.repo.get_user_name(TEST_USER_CONFIG_FILE), | |
28 'Foo Bar') | |
29 | |
30 def test_get_user_email(self): | |
31 self.assertEqual(self.repo.get_user_email(TEST_USER_CONFIG_FILE), | |
32 'foo.bar@example.com') | |
33 | |
34 | |
35 | |
36 class RepositoryGetDiffTest(BackendTestMixin): | |
37 | |
38 @classmethod | |
39 def _get_commits(cls): | |
40 commits = [ | |
41 { | |
42 'message': 'Initial commit', | |
43 'author': 'Joe Doe <joe.doe@example.com>', | |
44 'date': datetime.datetime(2010, 1, 1, 20), | |
45 'added': [ | |
46 FileNode('foobar', content='foobar'), | |
47 FileNode('foobar2', content='foobar2'), | |
48 ], | |
49 }, | |
50 { | |
51 'message': 'Changed foobar, added foobar3', | |
52 'author': 'Jane Doe <jane.doe@example.com>', | |
53 'date': datetime.datetime(2010, 1, 1, 21), | |
54 'added': [ | |
55 FileNode('foobar3', content='foobar3'), | |
56 ], | |
57 'changed': [ | |
58 FileNode('foobar', 'FOOBAR'), | |
59 ], | |
60 }, | |
61 { | |
62 'message': 'Removed foobar, changed foobar3', | |
63 'author': 'Jane Doe <jane.doe@example.com>', | |
64 'date': datetime.datetime(2010, 1, 1, 22), | |
65 'changed': [ | |
66 FileNode('foobar3', content='FOOBAR\nFOOBAR\nFOOBAR\n'), | |
67 ], | |
68 'removed': [FileNode('foobar')], | |
69 }, | |
70 ] | |
71 return commits | |
72 | |
73 def test_raise_for_wrong(self): | |
74 with self.assertRaises(ChangesetDoesNotExistError): | |
75 self.repo.get_diff('a' * 40, 'b' * 40) | |
76 | |
77 class GitRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase): | |
78 backend_alias = 'git' | |
79 | |
80 def test_initial_commit_diff(self): | |
81 initial_rev = self.repo.revisions[0] | |
82 self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar | |
83 new file mode 100644 | |
84 index 0000000..f6ea049 | |
85 --- /dev/null | |
86 +++ b/foobar | |
87 @@ -0,0 +1 @@ | |
88 +foobar | |
89 \ No newline at end of file | |
90 diff --git a/foobar2 b/foobar2 | |
91 new file mode 100644 | |
92 index 0000000..e8c9d6b | |
93 --- /dev/null | |
94 +++ b/foobar2 | |
95 @@ -0,0 +1 @@ | |
96 +foobar2 | |
97 \ No newline at end of file | |
98 ''') | |
99 | |
100 def test_second_changeset_diff(self): | |
101 revs = self.repo.revisions | |
102 self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar | |
103 index f6ea049..389865b 100644 | |
104 --- a/foobar | |
105 +++ b/foobar | |
106 @@ -1 +1 @@ | |
107 -foobar | |
108 \ No newline at end of file | |
109 +FOOBAR | |
110 \ No newline at end of file | |
111 diff --git a/foobar3 b/foobar3 | |
112 new file mode 100644 | |
113 index 0000000..c11c37d | |
114 --- /dev/null | |
115 +++ b/foobar3 | |
116 @@ -0,0 +1 @@ | |
117 +foobar3 | |
118 \ No newline at end of file | |
119 ''') | |
120 | |
121 def test_third_changeset_diff(self): | |
122 revs = self.repo.revisions | |
123 self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar | |
124 deleted file mode 100644 | |
125 index 389865b..0000000 | |
126 --- a/foobar | |
127 +++ /dev/null | |
128 @@ -1 +0,0 @@ | |
129 -FOOBAR | |
130 \ No newline at end of file | |
131 diff --git a/foobar3 b/foobar3 | |
132 index c11c37d..f932447 100644 | |
133 --- a/foobar3 | |
134 +++ b/foobar3 | |
135 @@ -1 +1,3 @@ | |
136 -foobar3 | |
137 \ No newline at end of file | |
138 +FOOBAR | |
139 +FOOBAR | |
140 +FOOBAR | |
141 ''') | |
142 | |
143 | |
144 class HgRepositoryGetDiffTest(RepositoryGetDiffTest, unittest.TestCase): | |
145 backend_alias = 'hg' | |
146 | |
147 def test_initial_commit_diff(self): | |
148 initial_rev = self.repo.revisions[0] | |
149 self.assertEqual(self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev), '''diff --git a/foobar b/foobar | |
150 new file mode 100755 | |
151 --- /dev/null | |
152 +++ b/foobar | |
153 @@ -0,0 +1,1 @@ | |
154 +foobar | |
155 \ No newline at end of file | |
156 diff --git a/foobar2 b/foobar2 | |
157 new file mode 100755 | |
158 --- /dev/null | |
159 +++ b/foobar2 | |
160 @@ -0,0 +1,1 @@ | |
161 +foobar2 | |
162 \ No newline at end of file | |
163 ''') | |
164 | |
165 def test_second_changeset_diff(self): | |
166 revs = self.repo.revisions | |
167 self.assertEqual(self.repo.get_diff(revs[0], revs[1]), '''diff --git a/foobar b/foobar | |
168 --- a/foobar | |
169 +++ b/foobar | |
170 @@ -1,1 +1,1 @@ | |
171 -foobar | |
172 \ No newline at end of file | |
173 +FOOBAR | |
174 \ No newline at end of file | |
175 diff --git a/foobar3 b/foobar3 | |
176 new file mode 100755 | |
177 --- /dev/null | |
178 +++ b/foobar3 | |
179 @@ -0,0 +1,1 @@ | |
180 +foobar3 | |
181 \ No newline at end of file | |
182 ''') | |
183 | |
184 def test_third_changeset_diff(self): | |
185 revs = self.repo.revisions | |
186 self.assertEqual(self.repo.get_diff(revs[1], revs[2]), '''diff --git a/foobar b/foobar | |
187 deleted file mode 100755 | |
188 --- a/foobar | |
189 +++ /dev/null | |
190 @@ -1,1 +0,0 @@ | |
191 -FOOBAR | |
192 \ No newline at end of file | |
193 diff --git a/foobar3 b/foobar3 | |
194 --- a/foobar3 | |
195 +++ b/foobar3 | |
196 @@ -1,1 +1,3 @@ | |
197 -foobar3 | |
198 \ No newline at end of file | |
199 +FOOBAR | |
200 +FOOBAR | |
201 +FOOBAR | |
202 ''') | |
203 | |
204 | |
205 # For each backend create test case class | |
206 for alias in SCM_TESTS: | |
207 attrs = { | |
208 'backend_alias': alias, | |
209 } | |
210 cls_name = alias.capitalize() + RepositoryBaseTest.__name__ | |
211 bases = (RepositoryBaseTest, unittest.TestCase) | |
212 globals()[cls_name] = type(cls_name, bases, attrs) | |
213 | |
214 if __name__ == '__main__': | |
215 unittest.main() |