##// END OF EJS Templates
fix(tests): on jenkins ensure re-creation of the path
fix(tests): on jenkins ensure re-creation of the path

File last commit:

r5608:6d33e504 default
r5609:cccd61c3 default
Show More
test_vcs_operations_special.py
275 lines | 11.6 KiB | text/x-python | PythonLexer
/ rhodecode / tests / vcs_operations / test_vcs_operations_special.py
core: updated copyright to 2024
r5608 # Copyright (C) 2010-2024 RhodeCode GmbH
tests: move vcs_operations into its own module.
r2456 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import os
import pytest
from rhodecode.lib.vcs.backends.git.repository import GitRepository
from rhodecode.lib.vcs.backends.hg.repository import MercurialRepository
from rhodecode.lib.vcs.nodes import FileNode
repositories: added option to archive repositories instead of deleting them....
r3090 from rhodecode.model.db import Repository
tests: move vcs_operations into its own module.
r2456 from rhodecode.model.meta import Session
from rhodecode.tests.vcs_operations import (
repositories: added option to archive repositories instead of deleting them....
r3090 Command, _check_proper_clone, _check_proper_git_push, _check_proper_hg_push,
_add_files_and_push)
tests: move vcs_operations into its own module.
r2456
tests: fixed test suite for celery adoption
r5607 @pytest.mark.usefixtures(
"init_pyramid_app",
"repo_group_repos",
"disable_locking",
)
tests: move vcs_operations into its own module.
r2456 class TestVCSOperationsSpecial(object):
tests: fixed test suite for celery adoption
r5607 def test_git_sets_default_branch_if_not_master(self, vcs_backend_git, tmpdir, rcstack):
empty_repo = vcs_backend_git.create_repo()
clone_url = rcstack.repo_clone_url(empty_repo.repo_name)
tests: move vcs_operations into its own module.
r2456
cmd = Command(tmpdir.strpath)
cmd.execute('git clone', clone_url)
repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: further test fixes
r3778 repo._checkout('test', create=True)
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'file', content=b'some-content'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message='Commit on branch test',
tests: fixed author for commit messages to be in a proper format.
r3840 author='Automatic test <automatic@rhodecode.com>',
tests: move vcs_operations into its own module.
r2456 branch='test')
repo_cmd = Command(repo.path)
stdout, stderr = repo_cmd.execute('git push --verbose origin test')
_check_proper_git_push(
stdout, stderr, branch='test', should_set_default_branch=True)
stdout, stderr = cmd.execute(
'git clone', clone_url, empty_repo.repo_name + '-clone')
_check_proper_clone(stdout, stderr, 'git')
# Doing an explicit commit in order to get latest user logs on MySQL
Session().commit()
tests: fixed test suite for celery adoption
r5607 def test_git_fetches_from_remote_repository_with_annotated_tags(self, vcs_backend_git, rcstack):
tests: rewrote code for running vcs_operations. Now it starts it's own...
r2457 # Note: This is a test specific to the git backend. It checks the
# integration of fetching from a remote repository which contains
# annotated tags.
# Dulwich shows this specific behavior only when
# operating against a remote repository.
tests: fixed test suite for celery adoption
r5607 source_repo = vcs_backend_git['annotated-tag']
target_vcs_repo = vcs_backend_git.create_repo().scm_instance()
target_vcs_repo.fetch(rcstack.repo_clone_url(source_repo.repo_name))
tests: move vcs_operations into its own module.
r2456
tests: fixed test suite for celery adoption
r5607 def test_git_push_shows_pull_request_refs(self, vcs_backend_git, rcstack, tmpdir):
tests: move vcs_operations into its own module.
r2456 """
test if remote info about refs is visible
"""
tests: fixed test suite for celery adoption
r5607 empty_repo = vcs_backend_git.create_repo()
tests: move vcs_operations into its own module.
r2456
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(empty_repo.repo_name)
tests: move vcs_operations into its own module.
r2456
cmd = Command(tmpdir.strpath)
cmd.execute('git clone', clone_url)
repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'readme.md', content=b'## Hello'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message='Commit on branch Master',
tests: fixed author for commit messages to be in a proper format.
r3840 author='Automatic test <automatic@rhodecode.com>',
tests: move vcs_operations into its own module.
r2456 branch='master')
repo_cmd = Command(repo.path)
stdout, stderr = repo_cmd.execute('git push --verbose origin master')
_check_proper_git_push(stdout, stderr, branch='master')
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?branch=master'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stderr
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stderr
# push on the same branch
repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'setup.py', content=b'print\n'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message='Commit2 on branch Master',
tests: fixed author for commit messages to be in a proper format.
r3840 author='Automatic test2 <automatic@rhodecode.com>',
tests: move vcs_operations into its own module.
r2456 branch='master')
repo_cmd = Command(repo.path)
stdout, stderr = repo_cmd.execute('git push --verbose origin master')
_check_proper_git_push(stdout, stderr, branch='master')
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stderr
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stderr
# new Branch
repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo._create_branch('feature', repo.commit_ids[1])
repo.in_memory_commit.add(FileNode(b'feature1.py', content=b'## Hello world'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message='Commit on branch feature',
tests: fixed author for commit messages to be in a proper format.
r3840 author='Automatic test <automatic@rhodecode.com>',
tests: move vcs_operations into its own module.
r2456 branch='feature')
repo_cmd = Command(repo.path)
stdout, stderr = repo_cmd.execute('git push --verbose origin feature')
_check_proper_git_push(stdout, stderr, branch='feature')
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?branch=feature'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stderr
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stderr
tests: fixed test suite for celery adoption
r5607 def test_hg_push_shows_pull_request_refs(self, vcs_backend_hg, rcstack, tmpdir):
empty_repo = vcs_backend_hg.create_repo()
tests: move vcs_operations into its own module.
r2456
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(empty_repo.repo_name)
tests: move vcs_operations into its own module.
r2456
cmd = Command(tmpdir.strpath)
cmd.execute('hg clone', clone_url)
repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'readme.md', content=b'## Hello'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message=u'Commit on branch default',
author=u'Automatic test',
branch='default')
repo_cmd = Command(repo.path)
repo_cmd.execute('hg checkout default')
stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url)
_check_proper_hg_push(stdout, stderr, branch='default')
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?branch=default'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stdout
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stdout
# push on the same branch
repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'setup.py', content=b'print\n'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message=u'Commit2 on branch default',
author=u'Automatic test2',
branch=u'default')
repo_cmd = Command(repo.path)
repo_cmd.execute('hg checkout default')
stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url)
_check_proper_hg_push(stdout, stderr, branch='default')
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stdout
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stdout
# new Branch
repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'feature1.py', content=b'## Hello world'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message=u'Commit on branch feature',
author=u'Automatic test',
branch=u'feature')
repo_cmd = Command(repo.path)
repo_cmd.execute('hg checkout feature')
stdout, stderr = repo_cmd.execute('hg push --new-branch --verbose', clone_url)
_check_proper_hg_push(stdout, stderr, branch='feature')
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?branch=feature'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stdout
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stdout
tests: fixed test suite for celery adoption
r5607 def test_hg_push_shows_pull_request_refs_book(self, vcs_backend_hg, rcstack, tmpdir):
empty_repo = vcs_backend_hg.create_repo()
tests: move vcs_operations into its own module.
r2456
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(empty_repo.repo_name)
tests: move vcs_operations into its own module.
r2456
cmd = Command(tmpdir.strpath)
cmd.execute('hg clone', clone_url)
repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'readme.md', content=b'## Hello'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message=u'Commit on branch default',
author=u'Automatic test',
branch='default')
repo_cmd = Command(repo.path)
repo_cmd.execute('hg checkout default')
stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url)
_check_proper_hg_push(stdout, stderr, branch='default')
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?branch=default'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stdout
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stdout
# add bookmark
repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
tests: fixed all tests for python3 BIG changes
r5087 repo.in_memory_commit.add(FileNode(b'setup.py', content=b'print\n'))
tests: move vcs_operations into its own module.
r2456 repo.in_memory_commit.commit(
message=u'Commit2 on branch default',
author=u'Automatic test2',
branch=u'default')
repo_cmd = Command(repo.path)
repo_cmd.execute('hg checkout default')
repo_cmd.execute('hg bookmark feature2')
stdout, stderr = repo_cmd.execute('hg push -B feature2 --verbose', clone_url)
_check_proper_hg_push(stdout, stderr, branch='default')
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?branch=default'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stdout
tests: fixed test suite for celery adoption
r5607 ref = f'{rcstack.host_url()}/{empty_repo.repo_name}/pull-request/new?bookmark=feature2'
tests: fixed all tests for python3 BIG changes
r5087 assert f'remote: RhodeCode: open pull request link: {ref}' in stdout
tests: move vcs_operations into its own module.
r2456 assert 'remote: RhodeCode: push completed' in stdout
assert 'exporting bookmark feature2' in stdout
repositories: added option to archive repositories instead of deleting them....
r3090
tests: fixed test suite for celery adoption
r5607 def test_push_is_forbidden_on_archived_repo_hg(self, vcs_backend_hg, rcstack, tmpdir):
empty_repo = vcs_backend_hg.create_repo()
repositories: added option to archive repositories instead of deleting them....
r3090 repo_name = empty_repo.repo_name
repo = Repository.get_by_repo_name(repo_name)
repo.archived = True
Session().commit()
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(repo_name)
stdout, stderr = Command(tmpdir.strpath).execute(
repositories: added option to archive repositories instead of deleting them....
r3090 'hg clone', clone_url, tmpdir.strpath)
stdout, stderr = _add_files_and_push(
'hg', tmpdir.strpath, clone_url=clone_url)
assert 'abort: HTTP Error 403: Forbidden' in stderr
tests: fixed test suite for celery adoption
r5607 def test_push_is_forbidden_on_archived_repo_git(self, vcs_backend_git, rcstack, tmpdir):
empty_repo = vcs_backend_git.create_repo()
repositories: added option to archive repositories instead of deleting them....
r3090 repo_name = empty_repo.repo_name
repo = Repository.get_by_repo_name(repo_name)
repo.archived = True
Session().commit()
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(repo_name)
stdout, stderr = Command(tmpdir.strpath).execute(
repositories: added option to archive repositories instead of deleting them....
r3090 'git clone', clone_url, tmpdir.strpath)
stdout, stderr = _add_files_and_push(
'git', tmpdir.strpath, clone_url=clone_url)
assert "The requested URL returned error: 403" in stderr