tests(fix): fixed git tests for new head branches

This commit is contained in:
RhodeCode Admin 2023-12-01 10:41:55 +01:00
parent 0701d1fca5
commit 908be75d8a

View file

@ -1,4 +1,3 @@
# Copyright (C) 2010-2023 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
@ -27,16 +26,15 @@ from rhodecode.tests.vcs.conftest import BackendTestMixin
@pytest.mark.usefixtures("vcs_repository_support")
class TestBranches(BackendTestMixin):
def test_empty_repository_has_no_branches(self, vcsbackend):
empty_repo = vcsbackend.create_repo()
assert empty_repo.branches == {}
def test_branches_all(self, vcsbackend):
branch_count = {
'git': 1,
'hg': 1,
'svn': 0,
"git": 1,
"hg": 1,
"svn": 0,
}
assert len(self.repo.branches_all) == branch_count[vcsbackend.alias]
@ -45,82 +43,79 @@ class TestBranches(BackendTestMixin):
def test_simple(self, local_dt_to_utc):
tip = self.repo.get_commit()
assert tip.message == 'Changes...'
assert tip.message == "Changes..."
assert tip.date == local_dt_to_utc(datetime.datetime(2010, 1, 1, 21))
@pytest.mark.backends("git", "hg")
def test_new_branch(self):
# This check must not be removed to ensure the 'branches' LazyProperty
# gets hit *before* the new 'foobar' branch got created:
assert 'foobar' not in self.repo.branches
self.imc.add(
FileNode(b'docs/index.txt', content=b'Documentation\n')
)
assert "foobar" not in self.repo.branches
self.imc.add(FileNode(b"docs/index.txt", content=b"Documentation\n"))
foobar_tip = self.imc.commit(
message='New branch: foobar',
author='joe <joe@rhodecode.com>',
branch='foobar',
message="New branch: foobar",
author="joe <joe@rhodecode.com>",
branch="foobar",
)
assert 'foobar' in self.repo.branches
assert foobar_tip.branch == 'foobar'
assert "foobar" in self.repo.branches
assert foobar_tip.branch == "foobar"
@pytest.mark.backends("git", "hg")
def test_new_head(self):
tip = self.repo.get_commit()
self.imc.add(
FileNode(b'docs/index.txt',
content=b'Documentation\n')
FileNode(b"docs/index.txt", content=b"Documentation\n")
)
foobar_tip = self.imc.commit(
message='New branch: foobar',
author='joe <joe@rhodecode.com>',
branch='foobar',
message="New branch: foobar",
author="joe <joe@rhodecode.com>",
branch="foobar",
parents=[tip],
)
self.imc.change(FileNode(
b'docs/index.txt',
content=b'Documentation\nand more...\n'))
self.imc.change(
FileNode(b"docs/index.txt", content=b"Documentation\nand more...\n")
)
assert foobar_tip.branch == "foobar"
newtip = self.imc.commit(
message=u'At default branch',
author=u'joe <joe@rhodecode.com>',
message="At foobar_tip branch",
author="joe <joe@rhodecode.com>",
branch=foobar_tip.branch,
parents=[foobar_tip],
)
newest_tip = self.imc.commit(
message=u'Merged with %s' % foobar_tip.raw_id,
author=u'joe <joe@rhodecode.com>',
message=f"Merged with {foobar_tip.raw_id}",
author="joe <joe@rhodecode.com>",
branch=self.backend_class.DEFAULT_BRANCH_NAME,
parents=[newtip, foobar_tip],
parents=[tip, newtip],
)
assert newest_tip.branch == \
self.backend_class.DEFAULT_BRANCH_NAME
assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME
@pytest.mark.backends("git", "hg")
def test_branch_with_slash_in_name(self):
self.imc.add(FileNode(b'extrafile', content=b'Some data\n'))
self.imc.add(FileNode(b"extrafile", content=b"Some data\n"))
self.imc.commit(
u'Branch with a slash!', author=u'joe <joe@rhodecode.com>',
branch='issue/123')
assert 'issue/123' in self.repo.branches
"Branch with a slash!", author="joe <joe@rhodecode.com>", branch="issue/123"
)
assert "issue/123" in self.repo.branches
@pytest.mark.backends("git", "hg")
def test_branch_with_slash_in_name_and_similar_without(self):
self.imc.add(FileNode(b'extrafile', content=b'Some data\n'))
self.imc.add(FileNode(b"extrafile", content=b"Some data\n"))
self.imc.commit(
u'Branch with a slash!', author=u'joe <joe@rhodecode.com>',
branch='issue/123')
self.imc.add(FileNode(b'extrafile II', content=b'Some data\n'))
"Branch with a slash!", author="joe <joe@rhodecode.com>", branch="issue/123"
)
self.imc.add(FileNode(b"extrafile II", content=b"Some data\n"))
self.imc.commit(
u'Branch without a slash...', author=u'joe <joe@rhodecode.com>',
branch='123')
assert 'issue/123' in self.repo.branches
assert '123' in self.repo.branches
"Branch without a slash...", author="joe <joe@rhodecode.com>", branch="123"
)
assert "issue/123" in self.repo.branches
assert "123" in self.repo.branches
class TestSvnBranches(object):
def test_empty_repository_has_no_tags_and_branches(self, vcsbackend_svn):
empty_repo = vcsbackend_svn.create_repo()
assert empty_repo.branches == {}
@ -132,16 +127,15 @@ class TestSvnBranches(object):
assert repo.tags == {}
def test_discovers_ordered_branches(self, vcsbackend_svn):
repo = vcsbackend_svn['svn-simple-layout']
repo = vcsbackend_svn["svn-simple-layout"]
expected_branches = [
'branches/add-docs',
'branches/argparse',
'trunk',
"branches/add-docs",
"branches/argparse",
"trunk",
]
assert list(repo.branches.keys()) == expected_branches
def test_discovers_ordered_tags(self, vcsbackend_svn):
repo = vcsbackend_svn['svn-simple-layout']
expected_tags = [
'tags/v0.1', 'tags/v0.2', 'tags/v0.3', 'tags/v0.5']
repo = vcsbackend_svn["svn-simple-layout"]
expected_tags = ["tags/v0.1", "tags/v0.2", "tags/v0.3", "tags/v0.5"]
assert list(repo.tags.keys()) == expected_tags