Show More
@@ -1,97 +1,97 b'' | |||||
1 |
|
1 | |||
2 | import datetime |
|
2 | import datetime | |
3 | from kallithea.lib.vcs.nodes import FileNode |
|
3 | from kallithea.lib.vcs.nodes import FileNode | |
4 | from kallithea.lib.vcs.utils.compat import unittest |
|
4 | from kallithea.lib.vcs.utils.compat import unittest | |
5 | from kallithea.tests.vcs.base import _BackendTestMixin |
|
5 | from kallithea.tests.vcs.base import _BackendTestMixin | |
6 | from kallithea.tests.vcs.conf import SCM_TESTS |
|
6 | from kallithea.tests.vcs.conf import SCM_TESTS | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | class WorkdirTestCaseMixin(_BackendTestMixin): |
|
9 | class WorkdirTestCaseMixin(_BackendTestMixin): | |
10 |
|
10 | |||
11 | @classmethod |
|
11 | @classmethod | |
12 | def _get_commits(cls): |
|
12 | def _get_commits(cls): | |
13 | commits = [ |
|
13 | commits = [ | |
14 | { |
|
14 | { | |
15 | 'message': u'Initial commit', |
|
15 | 'message': u'Initial commit', | |
16 | 'author': u'Joe Doe <joe.doe@example.com>', |
|
16 | 'author': u'Joe Doe <joe.doe@example.com>', | |
17 | 'date': datetime.datetime(2010, 1, 1, 20), |
|
17 | 'date': datetime.datetime(2010, 1, 1, 20), | |
18 | 'added': [ |
|
18 | 'added': [ | |
19 | FileNode('foobar', content='Foobar'), |
|
19 | FileNode('foobar', content='Foobar'), | |
20 | FileNode('foobar2', content='Foobar II'), |
|
20 | FileNode('foobar2', content='Foobar II'), | |
21 | FileNode('foo/bar/baz', content='baz here!'), |
|
21 | FileNode('foo/bar/baz', content='baz here!'), | |
22 | ], |
|
22 | ], | |
23 | }, |
|
23 | }, | |
24 | { |
|
24 | { | |
25 | 'message': u'Changes...', |
|
25 | 'message': u'Changes...', | |
26 | 'author': u'Jane Doe <jane.doe@example.com>', |
|
26 | 'author': u'Jane Doe <jane.doe@example.com>', | |
27 | 'date': datetime.datetime(2010, 1, 1, 21), |
|
27 | 'date': datetime.datetime(2010, 1, 1, 21), | |
28 | 'added': [ |
|
28 | 'added': [ | |
29 | FileNode('some/new.txt', content='news...'), |
|
29 | FileNode('some/new.txt', content='news...'), | |
30 | ], |
|
30 | ], | |
31 | 'changed': [ |
|
31 | 'changed': [ | |
32 | FileNode('foobar', 'Foobar I'), |
|
32 | FileNode('foobar', 'Foobar I'), | |
33 | ], |
|
33 | ], | |
34 | 'removed': [], |
|
34 | 'removed': [], | |
35 | }, |
|
35 | }, | |
36 | ] |
|
36 | ] | |
37 | return commits |
|
37 | return commits | |
38 |
|
38 | |||
39 | def test_get_branch_for_default_branch(self): |
|
39 | def test_get_branch_for_default_branch(self): | |
40 | self.assertEqual(self.repo.workdir.get_branch(), |
|
40 | self.assertEqual(self.repo.workdir.get_branch(), | |
41 | self.repo.DEFAULT_BRANCH_NAME) |
|
41 | self.repo.DEFAULT_BRANCH_NAME) | |
42 |
|
42 | |||
43 | def test_get_branch_after_adding_one(self): |
|
43 | def test_get_branch_after_adding_one(self): | |
44 | self.imc.add(FileNode('docs/index.txt', |
|
44 | self.imc.add(FileNode('docs/index.txt', | |
45 | content='Documentation\n')) |
|
45 | content='Documentation\n')) | |
46 | self.imc.commit( |
|
46 | self.imc.commit( | |
47 | message=u'New branch: foobar', |
|
47 | message=u'New branch: foobar', | |
48 | author=u'joe', |
|
48 | author=u'joe', | |
49 | branch='foobar', |
|
49 | branch='foobar', | |
50 | ) |
|
50 | ) | |
51 | self.assertEqual(self.repo.workdir.get_branch(), self.default_branch) |
|
51 | self.assertEqual(self.repo.workdir.get_branch(), self.default_branch) | |
52 |
|
52 | |||
53 | def test_get_changeset(self): |
|
53 | def test_get_changeset(self): | |
54 | old_head = self.repo.get_changeset() |
|
54 | old_head = self.repo.get_changeset() | |
55 | self.imc.add(FileNode('docs/index.txt', |
|
55 | self.imc.add(FileNode('docs/index.txt', | |
56 | content='Documentation\n')) |
|
56 | content='Documentation\n')) | |
57 | head = self.imc.commit( |
|
57 | head = self.imc.commit( | |
58 | message=u'New branch: foobar', |
|
58 | message=u'New branch: foobar', | |
59 | author=u'joe', |
|
59 | author=u'joe', | |
60 | branch='foobar', |
|
60 | branch='foobar', | |
61 | ) |
|
61 | ) | |
62 | self.assertEqual(self.repo.workdir.get_branch(), self.default_branch) |
|
62 | self.assertEqual(self.repo.workdir.get_branch(), self.default_branch) | |
63 | self.repo.workdir.checkout_branch('foobar') |
|
63 | self.repo.workdir.checkout_branch('foobar') | |
64 | self.assertEqual(self.repo.workdir.get_changeset(), head) |
|
64 | self.assertEqual(self.repo.workdir.get_changeset(), head) | |
65 |
|
65 | |||
66 |
# Make sure that old head is still there after update to def |
|
66 | # Make sure that old head is still there after update to default branch | |
67 | self.repo.workdir.checkout_branch(self.default_branch) |
|
67 | self.repo.workdir.checkout_branch(self.default_branch) | |
68 | self.assertEqual(self.repo.workdir.get_changeset(), old_head) |
|
68 | self.assertEqual(self.repo.workdir.get_changeset(), old_head) | |
69 |
|
69 | |||
70 | def test_checkout_branch(self): |
|
70 | def test_checkout_branch(self): | |
71 | from kallithea.lib.vcs.exceptions import BranchDoesNotExistError |
|
71 | from kallithea.lib.vcs.exceptions import BranchDoesNotExistError | |
72 | # first, 'foobranch' does not exist. |
|
72 | # first, 'foobranch' does not exist. | |
73 | self.assertRaises(BranchDoesNotExistError, self.repo.workdir.checkout_branch, |
|
73 | self.assertRaises(BranchDoesNotExistError, self.repo.workdir.checkout_branch, | |
74 | branch='foobranch') |
|
74 | branch='foobranch') | |
75 | # create new branch 'foobranch'. |
|
75 | # create new branch 'foobranch'. | |
76 | self.imc.add(FileNode('file1', content='blah')) |
|
76 | self.imc.add(FileNode('file1', content='blah')) | |
77 | self.imc.commit(message=u'asd', author=u'john', branch='foobranch') |
|
77 | self.imc.commit(message=u'asd', author=u'john', branch='foobranch') | |
78 | # go back to the default branch |
|
78 | # go back to the default branch | |
79 | self.repo.workdir.checkout_branch() |
|
79 | self.repo.workdir.checkout_branch() | |
80 | self.assertEqual(self.repo.workdir.get_branch(), self.backend_class.DEFAULT_BRANCH_NAME) |
|
80 | self.assertEqual(self.repo.workdir.get_branch(), self.backend_class.DEFAULT_BRANCH_NAME) | |
81 | # checkout 'foobranch' |
|
81 | # checkout 'foobranch' | |
82 | self.repo.workdir.checkout_branch('foobranch') |
|
82 | self.repo.workdir.checkout_branch('foobranch') | |
83 | self.assertEqual(self.repo.workdir.get_branch(), 'foobranch') |
|
83 | self.assertEqual(self.repo.workdir.get_branch(), 'foobranch') | |
84 |
|
84 | |||
85 |
|
85 | |||
86 | # For each backend create test case class |
|
86 | # For each backend create test case class | |
87 | for alias in SCM_TESTS: |
|
87 | for alias in SCM_TESTS: | |
88 | attrs = { |
|
88 | attrs = { | |
89 | 'backend_alias': alias, |
|
89 | 'backend_alias': alias, | |
90 | } |
|
90 | } | |
91 | cls_name = ''.join(('%s branch test' % alias).title().split()) |
|
91 | cls_name = ''.join(('%s branch test' % alias).title().split()) | |
92 | bases = (WorkdirTestCaseMixin, unittest.TestCase) |
|
92 | bases = (WorkdirTestCaseMixin, unittest.TestCase) | |
93 | globals()[cls_name] = type(cls_name, bases, attrs) |
|
93 | globals()[cls_name] = type(cls_name, bases, attrs) | |
94 |
|
94 | |||
95 |
|
95 | |||
96 | if __name__ == '__main__': |
|
96 | if __name__ == '__main__': | |
97 | unittest.main() |
|
97 | unittest.main() |
General Comments 0
You need to be logged in to leave comments.
Login now