tests: fixed tests for archivals

This commit is contained in:
RhodeCode Admin 2023-08-25 14:33:35 +02:00
parent e278d7d3ad
commit d886335b3e
3 changed files with 23 additions and 18 deletions

View file

@ -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.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(
'<li class="active"><a class="menulink" href="%s">' % files_url)
response.mustcontain(f'<li class="active"><a class="menulink" href="{files_url}">')
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',

View file

@ -125,7 +125,7 @@ def get_matching_phrase_offsets(text, phrases):
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'])

View file

@ -488,6 +488,11 @@ class Backend(object):
def create_test_repo(self, key, config=None):
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):
"""