##// END OF EJS Templates
deps: bumped gevent==24.11.1
deps: bumped gevent==24.11.1

File last commit:

r5608:6d33e504 default
r5611:2402f9a9 default
Show More
test_svn.py
195 lines | 6.1 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2010-2024 RhodeCode GmbH
project: added all source files and assets
r1 #
# 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 os
import mock
import pytest
tests: fixed all tests for python3 BIG changes
r5087 from rhodecode.lib.str_utils import safe_bytes
project: added all source files and assets
r1 from rhodecode.tests import SVN_REPO, TEST_DIR, TESTS_TMP_PATH
from rhodecode.lib.vcs.backends.svn.repository import SubversionRepository
from rhodecode.lib.vcs.conf import settings
from rhodecode.lib.vcs.exceptions import VCSError
pytestmark = [
pytest.mark.backends("svn"),
pylons: remove pylons as dependency...
r2351 pytest.mark.usefixtures("baseapp"),
project: added all source files and assets
r1 ]
pytest: use consistent way of creating a fixture by using pytest.fixture()
r3946 @pytest.fixture()
pylons: remove pylons as dependency...
r2351 def repo(baseapp):
project: added all source files and assets
r1 repo = SubversionRepository(os.path.join(TESTS_TMP_PATH, SVN_REPO))
return repo
pytest: use consistent way of creating a fixture by using pytest.fixture()
r3946 @pytest.fixture()
project: added all source files and assets
r1 def head(repo):
return repo.get_commit()
def test_init_fails_if_path_does_not_exist():
tests: fixed test suite for celery adoption
r5607 path = os.path.join(TEST_DIR, "i-do-not-exist")
project: added all source files and assets
r1 with pytest.raises(VCSError):
SubversionRepository(path)
def test_init_fails_if_path_is_not_a_valid_repository(tmpdir):
tests: fixed test suite for celery adoption
r5607 path = str(tmpdir.mkdir("unicode ä"))
project: added all source files and assets
r1 with pytest.raises(VCSError):
SubversionRepository(path)
def test_repo_clone(vcsbackend, reposerver):
source = vcsbackend.create_repo(number_of_commits=3)
reposerver.serve(source)
tests: fixed test suite for celery adoption
r5607 repo = SubversionRepository(vcsbackend.new_repo_path(), create=True, src_url=reposerver.url)
project: added all source files and assets
r1
assert source.commit_ids == repo.commit_ids
assert source[0].message == repo[0].message
def test_latest_commit(head):
tests: fixed test suite for celery adoption
r5607 assert head.raw_id == "393"
project: added all source files and assets
r1
def test_commit_description(head):
assert head.message == """Added a symlink"""
def test_commit_author(head):
tests: fixed test suite for celery adoption
r5607 assert head.author == "marcin"
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 @pytest.mark.parametrize(
"filename, content, mime_type",
[
(b"test.txt", b"Text content\n", None),
(b"test.bin", b"\0 binary \0", "application/octet-stream"),
],
ids=["text", "binary"],
)
project: added all source files and assets
r1 def test_sets_mime_type_correctly(vcsbackend, filename, content, mime_type):
repo = vcsbackend.create_repo()
vcsbackend.ensure_file(filename, content)
file_properties = repo._remote.node_properties(filename, 1)
tests: fixed test suite for celery adoption
r5607 assert file_properties.get("svn:mime-type") == mime_type
project: added all source files and assets
r1
def test_slice_access(repo):
page_size = 5
page = 0
start = page * page_size
end = start + page_size - 1
commits = list(repo[start:end])
tests: fixed test suite for celery adoption
r5607 assert [commit.raw_id for commit in commits] == ["1", "2", "3", "4"]
project: added all source files and assets
r1
def test_walk_changelog_page(repo):
page_size = 5
page = 0
start = page * page_size
end = start + page_size - 1
commits = list(repo[start:end])
tests: fixed test suite for celery adoption
r5607 changelog = ["r%s, %s, %s" % (c.raw_id, c.author, c.message) for c in commits]
project: added all source files and assets
r1
expexted_messages = [
tests: fixed test suite for celery adoption
r5607 "r1, marcin, initial import",
"r2, marcin, hg ignore",
"r3, marcin, Pip standards refactor",
"r4, marcin, Base repository few new functions added",
]
project: added all source files and assets
r1 assert changelog == expexted_messages
def test_read_full_file_tree(head):
for topnode, dirs, files in head.walk():
for f in files:
len(f.content)
def test_topnode_files_attribute(head):
tests: fixed test suite for celery adoption
r5607 topnode = head.get_node("")
project: added all source files and assets
r1 topnode.files
tests: fixed test suite for celery adoption
r5607 @pytest.mark.parametrize(
"filename, content, branch, mime_type",
[
("branches/plain/test.txt", b"Text content\n", "plain", None),
("branches/uniçö∂e/test.bin", b"\0 binary \0", "uniçö∂e", "application/octet-stream"),
],
ids=["text", "binary"],
)
project: added all source files and assets
r1 def test_unicode_refs(vcsbackend, filename, content, branch, mime_type):
tests: fixed all tests for python3 BIG changes
r5087 filename = safe_bytes(filename)
project: added all source files and assets
r1 repo = vcsbackend.create_repo()
vcsbackend.ensure_file(filename, content)
tests: fixed test suite for celery adoption
r5607 with mock.patch(
("rhodecode.lib.vcs.backends.svn.repository" ".SubversionRepository._patterns_from_section"),
return_value=["branches/*"],
):
assert f"branches/{branch}" in repo.branches
project: added all source files and assets
r1
def test_compatible_version(monkeypatch, vcsbackend):
tests: fixed test suite for celery adoption
r5607 monkeypatch.setattr(settings, "SVN_COMPATIBLE_VERSION", "pre-1.8-compatible")
project: added all source files and assets
r1 path = vcsbackend.new_repo_path()
SubversionRepository(path, create=True)
tests: fixed test suite for celery adoption
r5607 with open(f"{path}/db/format") as f:
project: added all source files and assets
r1 first_line = f.readline().strip()
tests: fixed test suite for celery adoption
r5607 assert first_line == "4"
project: added all source files and assets
r1
def test_invalid_compatible_version(monkeypatch, vcsbackend):
tests: fixed test suite for celery adoption
r5607 monkeypatch.setattr(settings, "SVN_COMPATIBLE_VERSION", "i-am-an-invalid-setting")
project: added all source files and assets
r1 path = vcsbackend.new_repo_path()
with pytest.raises(Exception):
SubversionRepository(path, create=True)
class TestSVNCommit(object):
@pytest.fixture(autouse=True)
def prepare(self, repo):
self.repo = repo
def test_file_history_from_commits(self):
tests: fixed test suite for celery adoption
r5607 node = self.repo[10].get_node("setup.py")
project: added all source files and assets
r1 commit_ids = [commit.raw_id for commit in node.history]
tests: fixed test suite for celery adoption
r5607 assert ["8"] == commit_ids
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 node = self.repo[20].get_node("setup.py")
project: added all source files and assets
r1 node_ids = [commit.raw_id for commit in node.history]
tests: fixed test suite for celery adoption
r5607 assert ["18", "8"] == node_ids
project: added all source files and assets
r1
# special case we check history from commit that has this particular
# file changed this means we check if it's included as well
tests: fixed test suite for celery adoption
r5607 node = self.repo.get_commit("18").get_node("setup.py")
project: added all source files and assets
r1 node_ids = [commit.raw_id for commit in node.history]
tests: fixed test suite for celery adoption
r5607 assert ["18", "8"] == node_ids
tests: fixed all tests for python3 BIG changes
r5087
def test_repo_files_content_type(self):
test_commit = self.repo.get_commit(commit_idx=100)
tests: fixed test suite for celery adoption
r5607 for node in test_commit.get_node("/"):
tests: fixed all tests for python3 BIG changes
r5087 if node.is_file():
assert type(node.content) == bytes
assert type(node.str_content) == str