diff --git a/rhodecode/tests/other/vcs_operations/conftest.py b/rhodecode/tests/other/vcs_operations/conftest.py --- a/rhodecode/tests/other/vcs_operations/conftest.py +++ b/rhodecode/tests/other/vcs_operations/conftest.py @@ -173,9 +173,9 @@ def rc_web_server( assert_no_running_instance(host_url) command = ['gunicorn', '--worker-class', 'gevent', '--paste', rc_web_server_config] - print('Starting rhodecode server: {}'.format(host_url)) - print('Command: {}'.format(command)) - print('Logfile: {}'.format(rc_log)) + print('rhodecode-web starting at: {}'.format(host_url)) + print('rhodecode-web command: {}'.format(command)) + print('rhodecode-web logfile: {}'.format(rc_log)) proc = subprocess32.Popen( command, bufsize=0, env=env, stdout=server_out, stderr=server_out) diff --git a/rhodecode/tests/other/vcs_operations/test_vcs_calls_small_post_buffer.py b/rhodecode/tests/other/vcs_operations/test_vcs_calls_small_post_buffer.py --- a/rhodecode/tests/other/vcs_operations/test_vcs_calls_small_post_buffer.py +++ b/rhodecode/tests/other/vcs_operations/test_vcs_calls_small_post_buffer.py @@ -52,7 +52,8 @@ def rc_web_server_config(testini_factory def test_git_clone_with_small_push_buffer(backend_git, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO) cmd = Command('/tmp') - stdout, stderr = cmd.execute('git -c http.postBuffer=1024 clone', clone_url, tmpdir.strpath) + stdout, stderr = cmd.execute( + 'git -c http.postBuffer=1024 clone', clone_url, tmpdir.strpath) _check_proper_clone(stdout, stderr, 'git') cmd.assert_returncode_success() @@ -73,5 +74,6 @@ def test_git_push_with_small_push_buffer branch='master') repo_cmd = Command(repo.path) - stdout, stderr = repo_cmd.execute('git -c http.postBuffer=1024 push --verbose origin master') + stdout, stderr = repo_cmd.execute( + 'git -c http.postBuffer=1024 push --verbose origin master') _check_proper_git_push(stdout, stderr, branch='master') diff --git a/rhodecode/tests/other/vcs_operations/test_vcs_operations.py b/rhodecode/tests/other/vcs_operations/test_vcs_operations.py --- a/rhodecode/tests/other/vcs_operations/test_vcs_operations.py +++ b/rhodecode/tests/other/vcs_operations/test_vcs_operations.py @@ -49,6 +49,11 @@ from rhodecode.tests.other.vcs_operation HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP) +@pytest.fixture(scope="session") +def vcs_server_config_override(): + return ({'server:main': {'workers': 2}},) + + @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") class TestVCSOperations(object): @@ -464,215 +469,214 @@ class TestVCSOperations(object): assert 'abort: authorization failed' in stderr -def test_git_sets_default_branch_if_not_master( - backend_git, tmpdir, disable_locking, rc_web_server): - empty_repo = backend_git.create_repo() - clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) +@pytest.mark.usefixtures("disable_locking") +class TestVCSOperationsSpecial(object): - cmd = Command(tmpdir.strpath) - cmd.execute('git clone', clone_url) + def test_git_sets_default_branch_if_not_master( + self, backend_git, tmpdir, rc_web_server): + empty_repo = backend_git.create_repo() + clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) + + cmd = Command(tmpdir.strpath) + cmd.execute('git clone', clone_url) - repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode('file', content='')) - repo.in_memory_commit.commit( - message='Commit on branch test', - author='Automatic test', - branch='test') + repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode('file', content='')) + repo.in_memory_commit.commit( + message='Commit on branch test', + author='Automatic test', + 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') + 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) - # Doing an explicit commit in order to get latest user logs on MySQL - Session().commit() - + stdout, stderr = cmd.execute( + 'git clone', clone_url, empty_repo.repo_name + '-clone') + _check_proper_clone(stdout, stderr, 'git') -def test_git_fetches_from_remote_repository_with_annotated_tags( - backend_git, disable_locking, rc_web_server): - # Note: This is a test specific to the git backend. It checks the - # integration of fetching from a remote repository which contains - # annotated tags. + # Doing an explicit commit in order to get latest user logs on MySQL + Session().commit() + + def test_git_fetches_from_remote_repository_with_annotated_tags( + self, backend_git, rc_web_server): + # 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. - source_repo = backend_git['annotated-tag'] - target_vcs_repo = backend_git.create_repo().scm_instance() - target_vcs_repo.fetch(rc_web_server.repo_clone_url(source_repo.repo_name)) - + # Dulwich shows this specific behavior only when + # operating against a remote repository. + source_repo = backend_git['annotated-tag'] + target_vcs_repo = backend_git.create_repo().scm_instance() + target_vcs_repo.fetch(rc_web_server.repo_clone_url(source_repo.repo_name)) -def test_git_push_shows_pull_request_refs(backend_git, rc_web_server, tmpdir): - """ - test if remote info about refs is visible - """ - empty_repo = backend_git.create_repo() + def test_git_push_shows_pull_request_refs(self, backend_git, rc_web_server, tmpdir): + """ + test if remote info about refs is visible + """ + empty_repo = backend_git.create_repo() - clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) + clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) - cmd = Command(tmpdir.strpath) - cmd.execute('git clone', clone_url) + cmd = Command(tmpdir.strpath) + cmd.execute('git clone', clone_url) - repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode('readme.md', content='## Hello')) - repo.in_memory_commit.commit( - message='Commit on branch Master', - author='Automatic test', - branch='master') + repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode('readme.md', content='## Hello')) + repo.in_memory_commit.commit( + message='Commit on branch Master', + author='Automatic test', + 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') + repo_cmd = Command(repo.path) + stdout, stderr = repo_cmd.execute('git push --verbose origin master') + _check_proper_git_push(stdout, stderr, branch='master') - ref = '{}/{}/pull-request/new?branch=master'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr - assert 'remote: RhodeCode: push completed' in stderr + ref = '{}/{}/pull-request/new?branch=master'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr + assert 'remote: RhodeCode: push completed' in stderr - # push on the same branch - repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode('setup.py', content='print\n')) - repo.in_memory_commit.commit( - message='Commit2 on branch Master', - author='Automatic test2', - branch='master') + # push on the same branch + repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode('setup.py', content='print\n')) + repo.in_memory_commit.commit( + message='Commit2 on branch Master', + author='Automatic test2', + 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') - - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr - assert 'remote: RhodeCode: push completed' in stderr + repo_cmd = Command(repo.path) + stdout, stderr = repo_cmd.execute('git push --verbose origin master') + _check_proper_git_push(stdout, stderr, branch='master') - # new Branch - repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode('feature1.py', content='## Hello world')) - repo.in_memory_commit.commit( - message='Commit on branch feature', - author='Automatic test', - branch='feature') + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr + assert 'remote: RhodeCode: push completed' in stderr - repo_cmd = Command(repo.path) - stdout, stderr = repo_cmd.execute('git push --verbose origin feature') - _check_proper_git_push(stdout, stderr, branch='feature') + # new Branch + repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode('feature1.py', content='## Hello world')) + repo.in_memory_commit.commit( + message='Commit on branch feature', + author='Automatic test', + branch='feature') - ref = '{}/{}/pull-request/new?branch=feature'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr - assert 'remote: RhodeCode: push completed' in stderr + repo_cmd = Command(repo.path) + stdout, stderr = repo_cmd.execute('git push --verbose origin feature') + _check_proper_git_push(stdout, stderr, branch='feature') + ref = '{}/{}/pull-request/new?branch=feature'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr + assert 'remote: RhodeCode: push completed' in stderr -def test_hg_push_shows_pull_request_refs(backend_hg, rc_web_server, tmpdir): - empty_repo = backend_hg.create_repo() + def test_hg_push_shows_pull_request_refs(self, backend_hg, rc_web_server, tmpdir): + empty_repo = backend_hg.create_repo() - clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) + clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) - cmd = Command(tmpdir.strpath) - cmd.execute('hg clone', clone_url) + cmd = Command(tmpdir.strpath) + cmd.execute('hg clone', clone_url) - repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode(u'readme.md', content=u'## Hello')) - repo.in_memory_commit.commit( - message=u'Commit on branch default', - author=u'Automatic test', - branch='default') + repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode(u'readme.md', content=u'## Hello')) + 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') + 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') + stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url) + _check_proper_hg_push(stdout, stderr, branch='default') - ref = '{}/{}/pull-request/new?branch=default'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout - assert 'remote: RhodeCode: push completed' in stdout + ref = '{}/{}/pull-request/new?branch=default'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout + assert 'remote: RhodeCode: push completed' in stdout - # push on the same branch - repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode(u'setup.py', content=u'print\n')) - repo.in_memory_commit.commit( - message=u'Commit2 on branch default', - author=u'Automatic test2', - branch=u'default') + # push on the same branch + repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode(u'setup.py', content=u'print\n')) + 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 = 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') + stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url) + _check_proper_hg_push(stdout, stderr, branch='default') - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout - assert 'remote: RhodeCode: push completed' in stdout + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout + assert 'remote: RhodeCode: push completed' in stdout - # new Branch - repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode(u'feature1.py', content=u'## Hello world')) - repo.in_memory_commit.commit( - message=u'Commit on branch feature', - author=u'Automatic test', - branch=u'feature') + # new Branch + repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode(u'feature1.py', content=u'## Hello world')) + 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') + 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') + stdout, stderr = repo_cmd.execute('hg push --new-branch --verbose', clone_url) + _check_proper_hg_push(stdout, stderr, branch='feature') - ref = '{}/{}/pull-request/new?branch=feature'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout - assert 'remote: RhodeCode: push completed' in stdout + ref = '{}/{}/pull-request/new?branch=feature'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout + assert 'remote: RhodeCode: push completed' in stdout + def test_hg_push_shows_pull_request_refs_book(self, backend_hg, rc_web_server, tmpdir): + empty_repo = backend_hg.create_repo() -def test_hg_push_shows_pull_request_refs_book(backend_hg, rc_web_server, tmpdir): - empty_repo = backend_hg.create_repo() + clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) - clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) + cmd = Command(tmpdir.strpath) + cmd.execute('hg clone', clone_url) - cmd = Command(tmpdir.strpath) - cmd.execute('hg clone', clone_url) + repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode(u'readme.md', content=u'## Hello')) + repo.in_memory_commit.commit( + message=u'Commit on branch default', + author=u'Automatic test', + branch='default') - repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode(u'readme.md', content=u'## Hello')) - 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') - 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') + stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url) + _check_proper_hg_push(stdout, stderr, branch='default') - ref = '{}/{}/pull-request/new?branch=default'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout - assert 'remote: RhodeCode: push completed' in stdout + ref = '{}/{}/pull-request/new?branch=default'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout + assert 'remote: RhodeCode: push completed' in stdout - # add bookmark - repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) - repo.in_memory_commit.add(FileNode(u'setup.py', content=u'print\n')) - repo.in_memory_commit.commit( - message=u'Commit2 on branch default', - author=u'Automatic test2', - branch=u'default') + # add bookmark + repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) + repo.in_memory_commit.add(FileNode(u'setup.py', content=u'print\n')) + 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') + 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') - ref = '{}/{}/pull-request/new?branch=default'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout - ref = '{}/{}/pull-request/new?bookmark=feature2'.format( - rc_web_server.host_url(), empty_repo.repo_name) - assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout - assert 'remote: RhodeCode: push completed' in stdout - assert 'exporting bookmark feature2' in stdout + ref = '{}/{}/pull-request/new?branch=default'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout + ref = '{}/{}/pull-request/new?bookmark=feature2'.format( + rc_web_server.host_url(), empty_repo.repo_name) + assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout + assert 'remote: RhodeCode: push completed' in stdout + assert 'exporting bookmark feature2' in stdout diff --git a/rhodecode/tests/other/vcs_operations/test_vcs_operations_tag_push.py b/rhodecode/tests/other/vcs_operations/test_vcs_operations_tag_push.py --- a/rhodecode/tests/other/vcs_operations/test_vcs_operations_tag_push.py +++ b/rhodecode/tests/other/vcs_operations/test_vcs_operations_tag_push.py @@ -91,6 +91,11 @@ def enable_webhook_push_integration(requ Session().commit() +@pytest.fixture(scope="session") +def vcs_server_config_override(): + return ({'server:main': {'workers': 2}},) + + @pytest.mark.usefixtures( "disable_locking", "disable_anonymous_user", "enable_webhook_push_integration") diff --git a/rhodecode/tests/pylons_plugin.py b/rhodecode/tests/pylons_plugin.py --- a/rhodecode/tests/pylons_plugin.py +++ b/rhodecode/tests/pylons_plugin.py @@ -96,8 +96,17 @@ def pytest_addoption(parser): "Start the VCSServer with HTTP protocol support.") +@pytest.fixture(scope="session") +def vcs_server_config_override(request): + """ + Allows injecting the overrides by specifying this inside test class + """ + + return () + + @pytest.fixture(scope='session') -def vcsserver(request, vcsserver_port, vcsserver_factory): +def vcsserver(request, vcsserver_port, vcsserver_factory, vcs_server_config_override): """ Session scope VCSServer. @@ -120,7 +129,8 @@ def vcsserver(request, vcsserver_port, v use_http = _use_vcs_http_server(request.config) return vcsserver_factory( - request, use_http=use_http, vcsserver_port=vcsserver_port) + request, use_http=use_http, vcsserver_port=vcsserver_port, + overrides=vcs_server_config_override) @pytest.fixture(scope='session') @@ -213,7 +223,7 @@ class HttpVCSServer(VCSServer): config_data = configobj.ConfigObj(config_file) self._config = config_data['server:main'] - args = ['gunicorn', '--workers', '1', '--paste', config_file] + args = ['gunicorn', '--paste', config_file] self._args = args @property @@ -232,9 +242,9 @@ class HttpVCSServer(VCSServer): server_out = open(rc_log, 'w') command = ' '.join(self._args) - print('Starting rhodecode-vcsserver: {}'.format(host_url)) - print('Command: {}'.format(command)) - print('Logfile: {}'.format(rc_log)) + print('rhodecode-vcsserver starting at: {}'.format(host_url)) + print('rhodecode-vcsserver command: {}'.format(command)) + print('rhodecode-vcsserver logfile: {}'.format(rc_log)) self.process = subprocess32.Popen( self._args, bufsize=0, env=env, stdout=server_out, stderr=server_out)