##// END OF EJS Templates
fix(caching): fixed problems with Cache query for users....
fix(caching): fixed problems with Cache query for users. The old way of querying caused the user get query to be always cached, and returning old results even in 2fa forms. The new limited query doesn't cache the user object resolving issues

File last commit:

r5088:8f6d1ed6 default
r5365:ae8a165b default
Show More
test_pullrequest_git.py
70 lines | 3.0 KiB | text/x-python | PythonLexer
# Copyright (C) 2010-2023 RhodeCode GmbH
#
# 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 pytest
from rhodecode.lib.vcs.nodes import FileNode
from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError
from rhodecode.model.pull_request import PullRequestModel
@pytest.mark.usefixtures('config_stub')
@pytest.mark.backends('git')
class TestGetDiffForPrOrVersion(object):
def test_works_for_missing_git_references(self, pr_util):
pull_request = self._prepare_pull_request(pr_util)
removed_commit_id = pr_util.remove_one_commit()
self.assert_commit_cannot_be_accessed(removed_commit_id, pull_request)
self.assert_diff_can_be_fetched(pull_request)
def test_works_for_missing_git_references_during_update(self, pr_util):
pull_request = self._prepare_pull_request(pr_util)
removed_commit_id = pr_util.remove_one_commit()
self.assert_commit_cannot_be_accessed(removed_commit_id, pull_request)
pr_version = PullRequestModel().get_versions(pull_request)[0]
self.assert_diff_can_be_fetched(pr_version)
def _prepare_pull_request(self, pr_util):
commits = [
{'message': 'a'},
{'message': 'b', 'added': [FileNode(b'file_b', 'test_content\n')]},
{'message': 'c', 'added': [FileNode(b'file_c', 'test_content\n')]},
]
pull_request = pr_util.create_pull_request(
commits=commits, target_head='a', source_head='c',
revisions=['b', 'c'])
return pull_request
def assert_diff_can_be_fetched(self, pr_or_version):
source_repo = pr_or_version.source_repo
source_ref_id = pr_or_version.source_ref_parts.commit_id
target_ref_id = pr_or_version.target_ref_parts.commit_id
diff = PullRequestModel()._get_diff_from_pr_or_version(
source_repo, source_ref_id, target_ref_id,
hide_whitespace_changes=False, diff_context=6)
assert b'file_b' in diff.raw.tobytes()
def assert_commit_cannot_be_accessed(
self, removed_commit_id, pull_request):
source_vcs = pull_request.source_repo.scm_instance()
with pytest.raises(CommitDoesNotExistError):
source_vcs.get_commit(commit_id=removed_commit_id)