From fcec7f0bbcaa7f469ca302f714524c6a551740a2 Mon Sep 17 00:00:00 2001 From: ievgenii vdovenko Date: Wed, 25 Jun 2025 17:16:34 +0200 Subject: [PATCH] feature: adds tests if a new checkbox is shown for CE and EE --- .../tests/test_repo_pullrequests.py | 52 ++++++++++++++++++- rhodecode/tests/fixtures/fixture_utils.py | 14 +++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/rhodecode/apps/repository/tests/test_repo_pullrequests.py b/rhodecode/apps/repository/tests/test_repo_pullrequests.py index 850163db..499fc5a6 100644 --- a/rhodecode/apps/repository/tests/test_repo_pullrequests.py +++ b/rhodecode/apps/repository/tests/test_repo_pullrequests.py @@ -45,7 +45,7 @@ from rhodecode.tests import ( TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN, ) -from rhodecode.tests.fixtures.fixture_utils import PRTestUtility, Backend +from rhodecode.tests.fixtures.fixture_utils import PRTestUtility, Backend, temporary_settings from rhodecode.tests.routes import route_path @@ -855,6 +855,56 @@ class TestPullrequestsView(object): ) assert response.status_int == 403 + def test_new_pull_request_view_close_branch_before_merging_setting_present_for_ee( + self, backend, pr_util, xhr_header, baseapp + ): + with temporary_settings(baseapp, **{"rhodecode.edition_id": "EE"}): + response = self.app.get(route_path("pullrequest_new", repo_name=backend.repo_name), status=200) + + assert_response = response.assert_response() + assert_response.one_element_exists("#close_branch_before_merging") + + def test_new_pull_request_view_close_branch_before_merging_setting_not_present_for_ce( + self, backend, pr_util, xhr_header, baseapp + ): + response = self.app.get(route_path("pullrequest_new", repo_name=backend.repo_name), status=200) + + assert_response = response.assert_response() + assert_response.no_element_exists("#close_branch_before_merging") + + def test_show_pull_request_view_close_branch_before_merging_setting_present_for_ee( + self, backend, pr_util, xhr_header, baseapp + ): + with temporary_settings(baseapp, **{"rhodecode.edition_id": "EE"}): + pull_request = pr_util.create_pull_request(mergeable=True, enable_notifications=False) + + response = self.app.get( + route_path( + "pullrequest_show", + repo_name=pull_request.target_repo.scm_instance().name, + pull_request_id=pull_request.pull_request_id, + ) + ) + + assert_response = response.assert_response() + assert_response.one_element_exists("#close_branch_before_merging") + + def test_show_pull_request_view_close_branch_before_merging_setting_not_present_for_ce( + self, backend, pr_util, xhr_header, baseapp + ): + pull_request = pr_util.create_pull_request(mergeable=True, enable_notifications=False) + + response = self.app.get( + route_path( + "pullrequest_show", + repo_name=pull_request.target_repo.scm_instance().name, + pull_request_id=pull_request.pull_request_id, + ) + ) + + assert_response = response.assert_response() + assert_response.no_element_exists("#close_branch_before_merging") + def test_create_pull_request_user_set_test_create_pull_request_to_true(self, backend, csrf_token): commits = [ {"message": "ancestor"}, diff --git a/rhodecode/tests/fixtures/fixture_utils.py b/rhodecode/tests/fixtures/fixture_utils.py index 9599e549..ff0ab6d6 100644 --- a/rhodecode/tests/fixtures/fixture_utils.py +++ b/rhodecode/tests/fixtures/fixture_utils.py @@ -26,6 +26,9 @@ import socket import subprocess import time import uuid +from contextlib import contextmanager +from copy import copy, deepcopy + import dateutil.tz import logging import functools @@ -172,6 +175,17 @@ def plain_http_environ(): } +@contextmanager +def temporary_settings(baseapp, **overrides): + original = deepcopy(baseapp.config.registry.settings) + try: + baseapp.config.registry.settings.update(overrides) + yield + finally: + baseapp.config.registry.settings.clear() + baseapp.config.registry.settings.update(original) + + @pytest.fixture(scope="session") def baseapp(request, ini_config, http_environ_session, available_port_factory, vcsserver_factory, celery_factory): from rhodecode.lib.config_utils import get_app_config