# HG changeset patch # User RhodeCode Admin # Date 2023-08-25 12:33:35 # Node ID 1fa672f51b7243ba35338af2b99afde290105e3b # Parent ef80e1c5655c9024b83c272825cedce90ca87d44 tests: fixed tests for archivals diff --git a/rhodecode/apps/repository/tests/test_repo_files.py b/rhodecode/apps/repository/tests/test_repo_files.py --- a/rhodecode/apps/repository/tests/test_repo_files.py +++ b/rhodecode/apps/repository/tests/test_repo_files.py @@ -21,19 +21,19 @@ import os import mock import pytest +from collections import OrderedDict from rhodecode.apps.repository.tests.test_repo_compare import ComparePage from rhodecode.apps.repository.views.repo_files import RepoFilesView, get_archive_name, get_path_sha from rhodecode.lib import helpers as h -from collections import OrderedDict from rhodecode.lib.ext_json import json from rhodecode.lib.str_utils import safe_str from rhodecode.lib.vcs import nodes +from rhodecode.lib.vcs.conf import settings +from rhodecode.model.db import Session, Repository -from rhodecode.lib.vcs.conf import settings from rhodecode.tests import assert_session_flash from rhodecode.tests.fixture import Fixture -from rhodecode.model.db import Session fixture = Fixture() @@ -171,7 +171,7 @@ class TestFilesViews(object): {'message': 'b', 'branch': new_branch} ] backend.create_repo(commits) - backend.repo.landing_rev = "branch:%s" % new_branch + backend.repo.landing_rev = f"branch:{new_branch}" Session().commit() # get response based on tip and not new commit @@ -187,8 +187,7 @@ class TestFilesViews(object): commit_id=landing_rev, params={'at': landing_rev}) assert landing_rev != 'tip' - response.mustcontain( - '
  • ' % files_url) + response.mustcontain(f'
  • ') def test_show_files_commit(self, backend): commit = backend.repo.get_commit(commit_idx=32) @@ -526,9 +525,10 @@ class TestRepositoryArchival(object): def test_archival(self, backend): backend.enable_downloads() commit = backend.repo.get_commit(commit_idx=173) + for a_type, content_type, extension in settings.ARCHIVE_SPECS: path_sha = get_path_sha('/') - filename = get_archive_name(backend.repo_name, commit_sha=commit.short_id, ext=extension, path_sha=path_sha) + filename = get_archive_name(backend.repo_id, backend.repo_name, commit_sha=commit.short_id, ext=extension, path_sha=path_sha) fname = commit.raw_id + extension response = self.app.get( @@ -538,19 +538,19 @@ class TestRepositoryArchival(object): assert response.status == '200 OK' headers = [ - ('Content-Disposition', 'attachment; filename=%s' % filename), - ('Content-Type', '%s' % content_type), + ('Content-Disposition', f'attachment; filename={filename}'), + ('Content-Type', content_type), ] for header in headers: - assert header in response.headers.items() + assert header in list(response.headers.items()) def test_archival_no_hash(self, backend): backend.enable_downloads() commit = backend.repo.get_commit(commit_idx=173) for a_type, content_type, extension in settings.ARCHIVE_SPECS: path_sha = get_path_sha('/') - filename = get_archive_name(backend.repo_name, commit_sha=commit.short_id, ext=extension, path_sha=path_sha, with_hash=False) + filename = get_archive_name(backend.repo_id, backend.repo_name, commit_sha=commit.short_id, ext=extension, path_sha=path_sha, with_hash=False) fname = commit.raw_id + extension response = self.app.get( @@ -560,8 +560,8 @@ class TestRepositoryArchival(object): assert response.status == '200 OK' headers = [ - ('Content-Disposition', 'attachment; filename=%s' % filename), - ('Content-Type', '%s' % content_type), + ('Content-Disposition', f'attachment; filename={filename}'), + ('Content-Type', content_type), ] for header in headers: @@ -574,7 +574,7 @@ class TestRepositoryArchival(object): for a_type, content_type, extension in settings.ARCHIVE_SPECS: path_sha = get_path_sha(at_path) - filename = get_archive_name(backend.repo_name, commit_sha=commit.short_id, ext=extension, path_sha=path_sha) + filename = get_archive_name(backend.repo_id, backend.repo_name, commit_sha=commit.short_id, ext=extension, path_sha=path_sha) fname = commit.raw_id + extension response = self.app.get( @@ -584,8 +584,8 @@ class TestRepositoryArchival(object): assert response.status == '200 OK' headers = [ - ('Content-Disposition', 'attachment; filename=%s' % filename), - ('Content-Type', '%s' % content_type), + ('Content-Disposition', f'attachment; filename={filename}'), + ('Content-Type', content_type), ] for header in headers: @@ -610,7 +610,7 @@ class TestRepositoryArchival(object): '00x000000', 'tar', 'wrong', '@$@$42413232', '232dffcd']) def test_archival_wrong_commit_id(self, backend, commit_id): backend.enable_downloads() - fname = '%s.zip' % commit_id + fname = f'{commit_id}.zip' response = self.app.get( route_path('repo_archivefile', diff --git a/rhodecode/lib/index/search_utils.py b/rhodecode/lib/index/search_utils.py --- a/rhodecode/lib/index/search_utils.py +++ b/rhodecode/lib/index/search_utils.py @@ -125,7 +125,7 @@ def get_matching_phrase_offsets(text, ph def get_matching_markers_offsets(text, markers=None): - """ + r""" Returns a list of string offsets in `text` that the are between matching markers >>> get_matching_markers_offsets('$1some$2 text $1here$2 marked', ['\$1(.*?)\$2']) diff --git a/rhodecode/tests/fixture_mods/fixture_utils.py b/rhodecode/tests/fixture_mods/fixture_utils.py --- a/rhodecode/tests/fixture_mods/fixture_utils.py +++ b/rhodecode/tests/fixture_mods/fixture_utils.py @@ -489,6 +489,11 @@ class Backend(object): return self._test_repo_container(key, self.alias, config) @property + def repo_id(self): + # just fake some repo_id + return self.repo.repo_id + + @property def repo(self): """ Returns the "current" repository. This is the vcs_test repo or the