##// END OF EJS Templates
tests(fix): fixed git tests for new head branches
super-admin -
r5218:e92a0575 default
parent child Browse files
Show More
@@ -1,147 +1,141 b''
1
2 # Copyright (C) 2010-2023 RhodeCode GmbH
1 # Copyright (C) 2010-2023 RhodeCode GmbH
3 #
2 #
4 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License, version 3
4 # it under the terms of the GNU Affero General Public License, version 3
6 # (only), as published by the Free Software Foundation.
5 # (only), as published by the Free Software Foundation.
7 #
6 #
8 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
10 # GNU General Public License for more details.
12 #
11 #
13 # You should have received a copy of the GNU Affero General Public License
12 # You should have received a copy of the GNU Affero General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 #
14 #
16 # This program is dual-licensed. If you wish to learn more about the
15 # This program is dual-licensed. If you wish to learn more about the
17 # RhodeCode Enterprise Edition, including its added features, Support services,
16 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # and proprietary license terms, please see https://rhodecode.com/licenses/
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
19
18
20 import datetime
19 import datetime
21
20
22 import pytest
21 import pytest
23
22
24 from rhodecode.lib.vcs.nodes import FileNode
23 from rhodecode.lib.vcs.nodes import FileNode
25 from rhodecode.tests.vcs.conftest import BackendTestMixin
24 from rhodecode.tests.vcs.conftest import BackendTestMixin
26
25
27
26
28 @pytest.mark.usefixtures("vcs_repository_support")
27 @pytest.mark.usefixtures("vcs_repository_support")
29 class TestBranches(BackendTestMixin):
28 class TestBranches(BackendTestMixin):
30
31 def test_empty_repository_has_no_branches(self, vcsbackend):
29 def test_empty_repository_has_no_branches(self, vcsbackend):
32 empty_repo = vcsbackend.create_repo()
30 empty_repo = vcsbackend.create_repo()
33 assert empty_repo.branches == {}
31 assert empty_repo.branches == {}
34
32
35 def test_branches_all(self, vcsbackend):
33 def test_branches_all(self, vcsbackend):
36 branch_count = {
34 branch_count = {
37 'git': 1,
35 "git": 1,
38 'hg': 1,
36 "hg": 1,
39 'svn': 0,
37 "svn": 0,
40 }
38 }
41 assert len(self.repo.branches_all) == branch_count[vcsbackend.alias]
39 assert len(self.repo.branches_all) == branch_count[vcsbackend.alias]
42
40
43 def test_closed_branches(self):
41 def test_closed_branches(self):
44 assert len(self.repo.branches_closed) == 0
42 assert len(self.repo.branches_closed) == 0
45
43
46 def test_simple(self, local_dt_to_utc):
44 def test_simple(self, local_dt_to_utc):
47 tip = self.repo.get_commit()
45 tip = self.repo.get_commit()
48 assert tip.message == 'Changes...'
46 assert tip.message == "Changes..."
49 assert tip.date == local_dt_to_utc(datetime.datetime(2010, 1, 1, 21))
47 assert tip.date == local_dt_to_utc(datetime.datetime(2010, 1, 1, 21))
50
48
51 @pytest.mark.backends("git", "hg")
49 @pytest.mark.backends("git", "hg")
52 def test_new_branch(self):
50 def test_new_branch(self):
53 # This check must not be removed to ensure the 'branches' LazyProperty
51 # This check must not be removed to ensure the 'branches' LazyProperty
54 # gets hit *before* the new 'foobar' branch got created:
52 # gets hit *before* the new 'foobar' branch got created:
55 assert 'foobar' not in self.repo.branches
53 assert "foobar" not in self.repo.branches
56 self.imc.add(
54 self.imc.add(FileNode(b"docs/index.txt", content=b"Documentation\n"))
57 FileNode(b'docs/index.txt', content=b'Documentation\n')
58 )
59 foobar_tip = self.imc.commit(
55 foobar_tip = self.imc.commit(
60 message='New branch: foobar',
56 message="New branch: foobar",
61 author='joe <joe@rhodecode.com>',
57 author="joe <joe@rhodecode.com>",
62 branch='foobar',
58 branch="foobar",
63 )
59 )
64 assert 'foobar' in self.repo.branches
60 assert "foobar" in self.repo.branches
65 assert foobar_tip.branch == 'foobar'
61 assert foobar_tip.branch == "foobar"
66
62
67 @pytest.mark.backends("git", "hg")
63 @pytest.mark.backends("git", "hg")
68 def test_new_head(self):
64 def test_new_head(self):
69 tip = self.repo.get_commit()
65 tip = self.repo.get_commit()
66
70 self.imc.add(
67 self.imc.add(
71 FileNode(b'docs/index.txt',
68 FileNode(b"docs/index.txt", content=b"Documentation\n")
72 content=b'Documentation\n')
73 )
69 )
74 foobar_tip = self.imc.commit(
70 foobar_tip = self.imc.commit(
75 message='New branch: foobar',
71 message="New branch: foobar",
76 author='joe <joe@rhodecode.com>',
72 author="joe <joe@rhodecode.com>",
77 branch='foobar',
73 branch="foobar",
78 parents=[tip],
74 parents=[tip],
79 )
75 )
80 self.imc.change(FileNode(
76 self.imc.change(
81 b'docs/index.txt',
77 FileNode(b"docs/index.txt", content=b"Documentation\nand more...\n")
82 content=b'Documentation\nand more...\n'))
78 )
79 assert foobar_tip.branch == "foobar"
83 newtip = self.imc.commit(
80 newtip = self.imc.commit(
84 message=u'At default branch',
81 message="At foobar_tip branch",
85 author=u'joe <joe@rhodecode.com>',
82 author="joe <joe@rhodecode.com>",
86 branch=foobar_tip.branch,
83 branch=foobar_tip.branch,
87 parents=[foobar_tip],
84 parents=[foobar_tip],
88 )
85 )
89
86
90 newest_tip = self.imc.commit(
87 newest_tip = self.imc.commit(
91 message=u'Merged with %s' % foobar_tip.raw_id,
88 message=f"Merged with {foobar_tip.raw_id}",
92 author=u'joe <joe@rhodecode.com>',
89 author="joe <joe@rhodecode.com>",
93 branch=self.backend_class.DEFAULT_BRANCH_NAME,
90 branch=self.backend_class.DEFAULT_BRANCH_NAME,
94 parents=[newtip, foobar_tip],
91 parents=[tip, newtip],
95 )
92 )
96
93
97 assert newest_tip.branch == \
94 assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME
98 self.backend_class.DEFAULT_BRANCH_NAME
99
95
100 @pytest.mark.backends("git", "hg")
96 @pytest.mark.backends("git", "hg")
101 def test_branch_with_slash_in_name(self):
97 def test_branch_with_slash_in_name(self):
102 self.imc.add(FileNode(b'extrafile', content=b'Some data\n'))
98 self.imc.add(FileNode(b"extrafile", content=b"Some data\n"))
103 self.imc.commit(
99 self.imc.commit(
104 u'Branch with a slash!', author=u'joe <joe@rhodecode.com>',
100 "Branch with a slash!", author="joe <joe@rhodecode.com>", branch="issue/123"
105 branch='issue/123')
101 )
106 assert 'issue/123' in self.repo.branches
102 assert "issue/123" in self.repo.branches
107
103
108 @pytest.mark.backends("git", "hg")
104 @pytest.mark.backends("git", "hg")
109 def test_branch_with_slash_in_name_and_similar_without(self):
105 def test_branch_with_slash_in_name_and_similar_without(self):
110 self.imc.add(FileNode(b'extrafile', content=b'Some data\n'))
106 self.imc.add(FileNode(b"extrafile", content=b"Some data\n"))
111 self.imc.commit(
107 self.imc.commit(
112 u'Branch with a slash!', author=u'joe <joe@rhodecode.com>',
108 "Branch with a slash!", author="joe <joe@rhodecode.com>", branch="issue/123"
113 branch='issue/123')
109 )
114 self.imc.add(FileNode(b'extrafile II', content=b'Some data\n'))
110 self.imc.add(FileNode(b"extrafile II", content=b"Some data\n"))
115 self.imc.commit(
111 self.imc.commit(
116 u'Branch without a slash...', author=u'joe <joe@rhodecode.com>',
112 "Branch without a slash...", author="joe <joe@rhodecode.com>", branch="123"
117 branch='123')
113 )
118 assert 'issue/123' in self.repo.branches
114 assert "issue/123" in self.repo.branches
119 assert '123' in self.repo.branches
115 assert "123" in self.repo.branches
120
116
121
117
122 class TestSvnBranches(object):
118 class TestSvnBranches(object):
123
124 def test_empty_repository_has_no_tags_and_branches(self, vcsbackend_svn):
119 def test_empty_repository_has_no_tags_and_branches(self, vcsbackend_svn):
125 empty_repo = vcsbackend_svn.create_repo()
120 empty_repo = vcsbackend_svn.create_repo()
126 assert empty_repo.branches == {}
121 assert empty_repo.branches == {}
127 assert empty_repo.tags == {}
122 assert empty_repo.tags == {}
128
123
129 def test_missing_structure_has_no_tags_and_branches(self, vcsbackend_svn):
124 def test_missing_structure_has_no_tags_and_branches(self, vcsbackend_svn):
130 repo = vcsbackend_svn.create_repo(number_of_commits=1)
125 repo = vcsbackend_svn.create_repo(number_of_commits=1)
131 assert repo.branches == {}
126 assert repo.branches == {}
132 assert repo.tags == {}
127 assert repo.tags == {}
133
128
134 def test_discovers_ordered_branches(self, vcsbackend_svn):
129 def test_discovers_ordered_branches(self, vcsbackend_svn):
135 repo = vcsbackend_svn['svn-simple-layout']
130 repo = vcsbackend_svn["svn-simple-layout"]
136 expected_branches = [
131 expected_branches = [
137 'branches/add-docs',
132 "branches/add-docs",
138 'branches/argparse',
133 "branches/argparse",
139 'trunk',
134 "trunk",
140 ]
135 ]
141 assert list(repo.branches.keys()) == expected_branches
136 assert list(repo.branches.keys()) == expected_branches
142
137
143 def test_discovers_ordered_tags(self, vcsbackend_svn):
138 def test_discovers_ordered_tags(self, vcsbackend_svn):
144 repo = vcsbackend_svn['svn-simple-layout']
139 repo = vcsbackend_svn["svn-simple-layout"]
145 expected_tags = [
140 expected_tags = ["tags/v0.1", "tags/v0.2", "tags/v0.3", "tags/v0.5"]
146 'tags/v0.1', 'tags/v0.2', 'tags/v0.3', 'tags/v0.5']
147 assert list(repo.tags.keys()) == expected_tags
141 assert list(repo.tags.keys()) == expected_tags
General Comments 0
You need to be logged in to leave comments. Login now