##// END OF EJS Templates
deps: bumped unidecode==1.3.8
deps: bumped unidecode==1.3.8

File last commit:

r5608:6d33e504 default
r5617:09fe92d1 default
Show More
test_nodes.py
276 lines | 9.8 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 stat
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.lib.vcs.nodes import DirNode
from rhodecode.lib.vcs.nodes import FileNode
from rhodecode.lib.vcs.nodes import Node
from rhodecode.lib.vcs.nodes import NodeError
from rhodecode.lib.vcs.nodes import NodeKind
tests: use gunicorn for testing. This is close to production testing...
r2453 from rhodecode.tests.vcs.conftest import BackendTestMixin
project: added all source files and assets
r1
@pytest.fixture()
def binary_filenode():
def node_maker(filename):
data = (
tests: fixed all tests for python3 BIG changes
r5087 b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00"
b"\x10\x08\x06\x00\x00\x00\x1f??a\x00\x00\x00\x04gAMA\x00\x00\xaf?7"
b"\x05\x8a?\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq?e<\x00"
b"\x00\x025IDAT8?\xa5\x93?K\x94Q\x14\x87\x9f\xf7?Q\x1bs4?\x03\x9a"
tests: fixed test suite for celery adoption
r5607 b'\xa8?B\x02\x8b$\x10[U;i\x13?6h?&h[?"\x14j?\xa2M\x7fB\x14F\x9aQ?&'
b'\x842?\x0b\x89"\x82??!?\x9c!\x9c2l??{N\x8bW\x9dY\xb4\t/\x1c?='
b"\x9b?}????\xa9*;9!?\x83\x91?[?\\v*?D\x04'`EpNp\xa2X'U?pVq\"Sw."
tests: fixed all tests for python3 BIG changes
r5087 b"\x1e?\x08\x01D?jw????\xbc??7{|\x9b?\x89$\x01??W@\x15\x9c\x05q`Lt/"
b"\x97?\x94\xa1d?\x18~?\x18?\x18W[%\xb0?\x83??\x14\x88\x8dB?\xa6H"
tests: fixed test suite for celery adoption
r5607 b'\tL\tl\x19>/\x01`\xac\xabx?\x9cl\nx\xb0\x98\x07\x95\x88D$"q['
tests: fixed all tests for python3 BIG changes
r5087 b"\x19?d\x00(o\n\xa0??\x7f\xb9\xa4?\x1bF\x1f\x8e\xac\xa8?j??eUU}?.?"
tests: fixed test suite for celery adoption
r5607 b'\x9f\x8cE??x\x94??\r\xbdtoJU5"0N\x10U?\x00??V\t\x02\x9f\x81?U?'
b'\x00\x9eM\xae2?r\x9b7\x83\x82\x8aP3????.?&"?\xb7ZP \x0c<?O'
tests: fixed all tests for python3 BIG changes
r5087 b"\xa5\t}\xb8?\x99\xa6?\x87?\x1di|/\xa0??0\xbe\x1fp?d&\x1a\xad"
b"\x95\x8a\x07?\t*\x10??b:?d?.\x13C\x8a?\x12\xbe\xbf\x8e?{???"
b"\x08?\x80\xa7\x13+d\x13>J?\x80\x15T\x95\x9a\x00??S\x8c\r?\xa1"
b"\x03\x07?\x96\x9b\xa7\xab=E??\xa4\xb3?\x19q??B\x91=\x8d??k?J"
tests: fixed test suite for celery adoption
r5607 b'\x0bV"??\xf7x?\xa1\x00?\\.\x87\x87???\x02F@D\x99],??\x10#?X'
tests: fixed all tests for python3 BIG changes
r5087 b"\xb7=\xb9\x10?Z\x1by???cI??\x1ag?\x92\xbc?T?t[\x92\x81?<_\x17~"
b"\x92\x88?H%?\x10Q\x02\x9f\n\x81qQ\x0bm?\x1bX?\xb1AK\xa6\x9e\xb9?u"
tests: fixed test suite for celery adoption
r5607 b'\xb2?1\xbe|/\x92M@\xa2!F?\xa9>"\r<DT?>\x92\x8e?>\x9a9Qv\x127?a'
tests: fixed all tests for python3 BIG changes
r5087 b"\xac?Y?8?:??]X???9\x80\xb7?u?\x0b#BZ\x8d=\x1d?p\x00\x00\x00\x00"
tests: fixed test suite for celery adoption
r5607 b"IEND\xaeB`\x82"
)
project: added all source files and assets
r1 return FileNode(filename, content=data)
tests: fixed test suite for celery adoption
r5607
project: added all source files and assets
r1 return node_maker
class TestNodeBasics:
tests: fixed test suite for celery adoption
r5607 @pytest.mark.parametrize("path", ["/foo", "/foo/bar"])
@pytest.mark.parametrize("kind", [NodeKind.FILE, NodeKind.DIR], ids=["FILE", "DIR"])
project: added all source files and assets
r1 def test_init_wrong_paths(self, path, kind):
"""
tests: fixed all tests for python3 BIG changes
r5087 Cannot initialize Node objects with path with slash at the beginning.
project: added all source files and assets
r1 """
tests: fixed all tests for python3 BIG changes
r5087 path = safe_bytes(path)
project: added all source files and assets
r1 with pytest.raises(NodeError):
Node(path, kind)
tests: fixed test suite for celery adoption
r5607 @pytest.mark.parametrize("path", ["path", "some/path"])
@pytest.mark.parametrize("kind", [NodeKind.FILE, NodeKind.DIR], ids=["FILE", "DIR"])
project: added all source files and assets
r1 def test_name(self, path, kind):
tests: fixed all tests for python3 BIG changes
r5087 path = safe_bytes(path)
project: added all source files and assets
r1 node = Node(path, kind)
tests: fixed test suite for celery adoption
r5607 assert node.name == "path"
project: added all source files and assets
r1
def test_name_root(self):
tests: fixed test suite for celery adoption
r5607 node = Node(b"", NodeKind.DIR)
assert node.name == ""
project: added all source files and assets
r1
def test_root_node_cannot_be_file(self):
with pytest.raises(NodeError):
tests: fixed test suite for celery adoption
r5607 Node(b"", NodeKind.FILE)
project: added all source files and assets
r1
def test_kind_setter(self):
tests: fixed test suite for celery adoption
r5607 node = Node(b"", NodeKind.DIR)
project: added all source files and assets
r1 with pytest.raises(NodeError):
node.kind = NodeKind.FILE
def test_compare_equal(self):
tests: fixed test suite for celery adoption
r5607 node1 = FileNode(b"test", content=b"")
node2 = FileNode(b"test", content=b"")
project: added all source files and assets
r1 assert node1 == node2
assert not node1 != node2
def test_compare_unequal(self):
tests: fixed test suite for celery adoption
r5607 node1 = FileNode(b"test", content=b"a")
node2 = FileNode(b"test", content=b"b")
project: added all source files and assets
r1 assert node1 != node2
assert not node1 == node2
tests: fixed test suite for celery adoption
r5607 @pytest.mark.parametrize(
"node_path, expected_parent_path",
[
("", b""),
("some/path/", b"some/"),
("some/longer/path/", b"some/longer/"),
],
)
project: added all source files and assets
r1 def test_parent_path_new(self, node_path, expected_parent_path):
"""
Tests if node's parent path are properly computed.
"""
tests: fixed all tests for python3 BIG changes
r5087 node_path = safe_bytes(node_path)
project: added all source files and assets
r1 node = Node(node_path, NodeKind.DIR)
parent_path = node.get_parent_path()
tests: fixed test suite for celery adoption
r5607 assert parent_path.endswith(b"/") or node.is_root() and parent_path == b""
project: added all source files and assets
r1 assert parent_path == expected_parent_path
tests: fixed test suite for celery adoption
r5607 """
project: added all source files and assets
r1 def _test_trailing_slash(self, path):
if not path.endswith('/'):
pytest.fail("Trailing slash tests needs paths to end with slash")
for kind in NodeKind.FILE, NodeKind.DIR:
with pytest.raises(NodeError):
Node(path=path, kind=kind)
def test_trailing_slash(self):
for path in ('/', 'foo/', 'foo/bar/', 'foo/bar/biz/'):
self._test_trailing_slash(path)
tests: fixed test suite for celery adoption
r5607 """
project: added all source files and assets
r1
def test_is_file(self):
tests: fixed test suite for celery adoption
r5607 node = Node(b"any", NodeKind.FILE)
project: added all source files and assets
r1 assert node.is_file()
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"any")
project: added all source files and assets
r1 assert node.is_file()
with pytest.raises(AttributeError):
tests: fixed all tests for python3 BIG changes
r5087 node.nodes # noqa
project: added all source files and assets
r1
def test_is_dir(self):
tests: fixed test suite for celery adoption
r5607 node = Node(b"any_dir", NodeKind.DIR)
project: added all source files and assets
r1 assert node.is_dir()
tests: fixed test suite for celery adoption
r5607 node = DirNode(b"any_dir")
project: added all source files and assets
r1
assert node.is_dir()
with pytest.raises(NodeError):
tests: fixed all tests for python3 BIG changes
r5087 node.content # noqa
project: added all source files and assets
r1
def test_dir_node_iter(self):
nodes = [
tests: fixed test suite for celery adoption
r5607 DirNode(b"docs"),
DirNode(b"tests"),
FileNode(b"bar"),
FileNode(b"foo"),
FileNode(b"readme.txt"),
FileNode(b"setup.py"),
project: added all source files and assets
r1 ]
tests: fixed test suite for celery adoption
r5607 dirnode = DirNode(b"", nodes=nodes)
project: added all source files and assets
r1 for node in dirnode:
assert node == dirnode.get_node(node.path)
def test_node_state(self):
"""
Without link to commit nodes should raise NodeError.
"""
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"anything")
project: added all source files and assets
r1 with pytest.raises(NodeError):
tests: fixed all tests for python3 BIG changes
r5087 node.state # noqa
tests: fixed test suite for celery adoption
r5607 node = DirNode(b"anything")
project: added all source files and assets
r1 with pytest.raises(NodeError):
tests: fixed all tests for python3 BIG changes
r5087 node.state # noqa
project: added all source files and assets
r1
def test_file_node_stat(self):
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"foobar", b"empty... almost")
project: added all source files and assets
r1 mode = node.mode # default should be 0100644
assert mode & stat.S_IRUSR
assert mode & stat.S_IWUSR
assert mode & stat.S_IRGRP
assert mode & stat.S_IROTH
assert not mode & stat.S_IWGRP
assert not mode & stat.S_IWOTH
assert not mode & stat.S_IXUSR
assert not mode & stat.S_IXGRP
assert not mode & stat.S_IXOTH
def test_file_node_is_executable(self):
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"foobar", b"empty... almost", mode=0o100755)
project: added all source files and assets
r1 assert node.is_executable
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"foobar", b"empty... almost", mode=0o100500)
project: added all source files and assets
r1 assert node.is_executable
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"foobar", b"empty... almost", mode=0o100644)
project: added all source files and assets
r1 assert not node.is_executable
def test_file_node_is_not_symlink(self):
tests: fixed test suite for celery adoption
r5607 node = FileNode(b"foobar", b"empty...")
project: added all source files and assets
r1 assert not node.is_link()
def test_mimetype(self):
tests: fixed test suite for celery adoption
r5607 py_node = FileNode(b"test.py")
tar_node = FileNode(b"test.tar.gz")
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 ext = "CustomExtension"
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 my_node2 = FileNode(b"myfile2")
project: added all source files and assets
r1 my_node2._mimetype = [ext]
tests: fixed test suite for celery adoption
r5607 my_node3 = FileNode(b"myfile3")
project: added all source files and assets
r1 my_node3._mimetype = [ext, ext]
tests: fixed test suite for celery adoption
r5607 assert py_node.mimetype == "text/x-python"
assert py_node.get_mimetype() == ("text/x-python", None)
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 assert tar_node.mimetype == "application/x-tar"
assert tar_node.get_mimetype() == ("application/x-tar", "gzip")
project: added all source files and assets
r1
with pytest.raises(NodeError):
my_node2.get_mimetype()
assert my_node3.mimetype == ext
assert my_node3.get_mimetype() == [ext, ext]
def test_lines_counts(self):
lines = [
tests: fixed test suite for celery adoption
r5607 b"line1\n",
b"line2\n",
b"line3\n",
b"\n",
b"\n",
b"line4\n",
project: added all source files and assets
r1 ]
tests: fixed test suite for celery adoption
r5607 py_node = FileNode(b"test.py", b"".join(lines))
project: added all source files and assets
r1
assert (len(lines), len(lines)) == py_node.lines()
assert (len(lines), len(lines) - 2) == py_node.lines(count_empty=True)
def test_lines_no_newline(self):
tests: fixed test suite for celery adoption
r5607 py_node = FileNode(b"test.py", b"oneline")
project: added all source files and assets
r1
assert (1, 1) == py_node.lines()
assert (1, 1) == py_node.lines(count_empty=True)
tests: use gunicorn for testing. This is close to production testing...
r2453 class TestNodeContent(object):
project: added all source files and assets
r1 def test_if_binary(self, binary_filenode):
tests: fixed test suite for celery adoption
r5607 filenode = binary_filenode(b"calendar.jpg")
project: added all source files and assets
r1 assert filenode.is_binary
def test_binary_line_counts(self, binary_filenode):
tests: fixed test suite for celery adoption
r5607 tar_node = binary_filenode(b"archive.tar.gz")
project: added all source files and assets
r1 assert (0, 0) == tar_node.lines(count_empty=True)
def test_binary_mimetype(self, binary_filenode):
tests: fixed test suite for celery adoption
r5607 tar_node = binary_filenode(b"archive.tar.gz")
assert tar_node.mimetype == "application/x-tar"
project: added all source files and assets
r1
tests: use gunicorn for testing. This is close to production testing...
r2453 @pytest.mark.usefixtures("vcs_repository_support")
project: added all source files and assets
r1 class TestNodesCommits(BackendTestMixin):
def test_node_last_commit(self, generate_repo_with_commits):
repo = generate_repo_with_commits(20)
last_commit = repo.get_commit()
python3: removed use of xrang
r4906 for x in range(3):
tests: fixed test suite for celery adoption
r5607 node = last_commit.get_node(f"file_{x}.txt")
project: added all source files and assets
r1 assert node.last_commit == repo[x]