##// END OF EJS Templates
feat(configs): deprecared old hooks protocol and ssh wrapper....
feat(configs): deprecared old hooks protocol and ssh wrapper. New defaults are now set on v2 keys, so previous installation are automatically set to new keys. Fallback mode is still available.

File last commit:

r5198:919dd05c default
r5496:cab50adf default
Show More
test_repo_changelog.py
204 lines | 8.0 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2010-2023 RhodeCode GmbH
changelog: ported to pyramid views.
r1931 #
# 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 re
import pytest
from rhodecode.apps.repository.views.repo_changelog import DEFAULT_CHANGELOG_SIZE
from rhodecode.tests import TestController
tests: refactor code to use a single test url generator
r5173 from rhodecode.tests.routes import route_path
changelog: ported to pyramid views.
r1931
tests: refactor code to use a single test url generator
r5173 MATCH_HASH = re.compile(r'<span class="commit_hash">r(\d+):[\da-f]+</span>')
changelog: ported to pyramid views.
r1931
changelog: rename changelog to commits pages
r3742 def assert_commits_on_page(response, indexes):
tests: fixed all tests for python3 BIG changes
r5087 found_indexes = [int(idx) for idx in MATCH_HASH.findall(response.text)]
changelog: rename changelog to commits pages
r3742 assert found_indexes == indexes
changelog: ported to pyramid views.
r1931 class TestChangelogController(TestController):
changelog: rename changelog to commits pages
r3742 def test_commits_page(self, backend):
self.log_user()
response = self.app.get(
route_path('repo_commits', repo_name=backend.repo_name))
first_idx = -1
last_idx = -DEFAULT_CHANGELOG_SIZE
tests: fixed some tests for files pages.
r3776 self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
changelog: rename changelog to commits pages
r3742
changelog: ported to pyramid views.
r1931 def test_changelog(self, backend):
self.log_user()
response = self.app.get(
route_path('repo_changelog', repo_name=backend.repo_name))
first_idx = -1
last_idx = -DEFAULT_CHANGELOG_SIZE
self.assert_commit_range_on_page(
response, first_idx, last_idx, backend)
@pytest.mark.backends("hg", "git")
def test_changelog_filtered_by_branch(self, backend):
self.log_user()
self.app.get(
route_path('repo_changelog', repo_name=backend.repo_name,
params=dict(branch=backend.default_branch_name)),
status=200)
changelog: rename changelog to commits pages
r3742 @pytest.mark.backends("hg", "git")
def test_commits_filtered_by_branch(self, backend):
self.log_user()
self.app.get(
route_path('repo_commits', repo_name=backend.repo_name,
params=dict(branch=backend.default_branch_name)),
status=200)
changelog: ported to pyramid views.
r1931 @pytest.mark.backends("svn")
def test_changelog_filtered_by_branch_svn(self, autologin_user, backend):
repo = backend['svn-simple-layout']
response = self.app.get(
route_path('repo_changelog', repo_name=repo.repo_name,
params=dict(branch='trunk')),
status=200)
changelog: rename changelog to commits pages
r3742 assert_commits_on_page(response, indexes=[15, 12, 7, 3, 2, 1])
changelog: ported to pyramid views.
r1931
changelog: rename changelog to commits pages
r3742 def test_commits_filtered_by_wrong_branch(self, backend):
changelog: ported to pyramid views.
r1931 self.log_user()
branch = 'wrong-branch-name'
response = self.app.get(
changelog: rename changelog to commits pages
r3742 route_path('repo_commits', repo_name=backend.repo_name,
changelog: ported to pyramid views.
r1931 params=dict(branch=branch)),
status=302)
changelog: rename changelog to commits pages
r3742 expected_url = '/{repo}/commits/{branch}'.format(
changelog: ported to pyramid views.
r1931 repo=backend.repo_name, branch=branch)
assert expected_url in response.location
response = response.follow()
modernize: updates for python3
r5095 expected_warning = f'Branch {branch} is not found.'
tests: multiple tests cases fixes for python3
r4994 assert expected_warning in response.text
changelog: ported to pyramid views.
r1931
@pytest.mark.xfail_backends("svn", reason="Depends on branch support")
tests: fixed all tests for python3 BIG changes
r5087 def test_changelog_filtered_by_branch_with_merges(self, autologin_user, backend):
changelog: ported to pyramid views.
r1931
# Note: The changelog of branch "b" does not contain the commit "a1"
# although this is a parent of commit "b1". And branch "b" has commits
# which have a smaller index than commit "a1".
commits = [
fix(tests): fixed the creation of non-linear commits creation in tests...
r5198 {'message': 'a', 'branch': 'master'},
changelog: ported to pyramid views.
r1931 {'message': 'b', 'branch': 'b'},
fix(tests): fixed the creation of non-linear commits creation in tests...
r5198 {'message': 'a1', 'parents': ['a'], 'branch': 'master'},
changelog: ported to pyramid views.
r1931 {'message': 'b1', 'branch': 'b', 'parents': ['b', 'a1']},
]
backend.create_repo(commits)
self.app.get(
route_path('repo_changelog', repo_name=backend.repo_name,
params=dict(branch='b')),
status=200)
@pytest.mark.backends("hg")
changelog: rename changelog to commits pages
r3742 def test_commits_closed_branches(self, autologin_user, backend):
changelog: ported to pyramid views.
r1931 repo = backend['closed_branch']
response = self.app.get(
changelog: rename changelog to commits pages
r3742 route_path('repo_commits', repo_name=repo.repo_name,
changelog: ported to pyramid views.
r1931 params=dict(branch='experimental')),
status=200)
changelog: rename changelog to commits pages
r3742 assert_commits_on_page(response, indexes=[3, 1])
changelog: ported to pyramid views.
r1931
def test_changelog_pagination(self, backend):
self.log_user()
# pagination, walk up to page 6
changelog_url = route_path(
changelog: rename changelog to commits pages
r3742 'repo_commits', repo_name=backend.repo_name)
changelog: ported to pyramid views.
r1931
for page in range(1, 7):
response = self.app.get(changelog_url, {'page': page})
first_idx = -DEFAULT_CHANGELOG_SIZE * (page - 1) - 1
last_idx = -DEFAULT_CHANGELOG_SIZE * page
self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
def assert_commit_range_on_page(
self, response, first_idx, last_idx, backend):
input_template = (
tests: fixing tests for pull-requests and changelog(commits)
r3772 """<input class="commit-range" """
tests: fixed some tests for files pages.
r3776 """data-commit-id="%(raw_id)s" data-commit-idx="%(idx)s" """
"""data-short-id="%(short_id)s" id="%(raw_id)s" """
changelog: ported to pyramid views.
r1931 """name="%(raw_id)s" type="checkbox" value="1" />"""
)
tests: fixing tests for pull-requests and changelog(commits)
r3772
changelog: ported to pyramid views.
r1931 commit_span_template = """<span class="commit_hash">r%s:%s</span>"""
repo = backend.repo
first_commit_on_page = repo.get_commit(commit_idx=first_idx)
response.mustcontain(
tests: fixing tests for pull-requests and changelog(commits)
r3772 input_template % {'raw_id': first_commit_on_page.raw_id,
tests: fixed some tests for files pages.
r3776 'idx': first_commit_on_page.idx,
'short_id': first_commit_on_page.short_id})
tests: fixing tests for pull-requests and changelog(commits)
r3772
changelog: ported to pyramid views.
r1931 response.mustcontain(commit_span_template % (
first_commit_on_page.idx, first_commit_on_page.short_id)
)
last_commit_on_page = repo.get_commit(commit_idx=last_idx)
response.mustcontain(
tests: fixing tests for pull-requests and changelog(commits)
r3772 input_template % {'raw_id': last_commit_on_page.raw_id,
tests: fixed some tests for files pages.
r3776 'idx': last_commit_on_page.idx,
'short_id': last_commit_on_page.short_id})
changelog: ported to pyramid views.
r1931 response.mustcontain(commit_span_template % (
last_commit_on_page.idx, last_commit_on_page.short_id)
)
first_commit_of_next_page = repo.get_commit(commit_idx=last_idx - 1)
first_span_of_next_page = commit_span_template % (
first_commit_of_next_page.idx, first_commit_of_next_page.short_id)
assert first_span_of_next_page not in response
@pytest.mark.parametrize('test_path', [
'vcs/exceptions.py',
'/vcs/exceptions.py',
'//vcs/exceptions.py'
])
changelog: rename changelog to commits pages
r3742 def test_commits_with_filenode(self, backend, test_path):
changelog: ported to pyramid views.
r1931 self.log_user()
response = self.app.get(
changelog: rename changelog to commits pages
r3742 route_path('repo_commits_file', repo_name=backend.repo_name,
changelog: ported to pyramid views.
r1931 commit_id='tip', f_path=test_path),
)
# history commits messages
response.mustcontain('Added exceptions module, this time for real')
response.mustcontain('Added not implemented hg backend test case')
response.mustcontain('Added BaseChangeset class')
changelog: rename changelog to commits pages
r3742 def test_commits_with_filenode_that_is_dirnode(self, backend):
changelog: ported to pyramid views.
r1931 self.log_user()
self.app.get(
changelog: rename changelog to commits pages
r3742 route_path('repo_commits_file', repo_name=backend.repo_name,
changelog: ported to pyramid views.
r1931 commit_id='tip', f_path='/tests'),
status=302)
changelog: rename changelog to commits pages
r3742 def test_commits_with_filenode_not_existing(self, backend):
changelog: ported to pyramid views.
r1931 self.log_user()
self.app.get(
changelog: rename changelog to commits pages
r3742 route_path('repo_commits_file', repo_name=backend.repo_name,
changelog: ported to pyramid views.
r1931 commit_id='tip', f_path='wrong_path'),
status=302)