Refactor package approval validation to unify implementation
This commit is contained in:
0
app/tests/unit/utils/__init__.py
Normal file
0
app/tests/unit/utils/__init__.py
Normal file
69
app/tests/unit/utils/test_git.py
Normal file
69
app/tests/unit/utils/test_git.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# ContentDB
|
||||
# Copyright (C) rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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 Affero 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
|
||||
from app.utils.git import get_latest_tag, get_latest_commit, clone_repo
|
||||
|
||||
|
||||
test_repo = "https://gitlab.com/rubenwardy/testmod"
|
||||
master_head = "87b11d91d84aea1f867ed1732afeb27cefd01078"
|
||||
test_branch_head = "51b54f00c3b3d712417a1cc4bfaa6cbdc7aac3fc"
|
||||
v4_commit = "c07d27c3a466d2102d1ba5473d172c74e6b3e0d7"
|
||||
random_commit = "84a2e53ff046eacbdbb80f3a00c58510885fefca"
|
||||
|
||||
|
||||
def test_get_latest_tag():
|
||||
tag, commit = get_latest_tag(test_repo)
|
||||
assert tag == "v4"
|
||||
assert commit == v4_commit
|
||||
|
||||
|
||||
def test_get_latest_commit():
|
||||
assert get_latest_commit(test_repo) == master_head
|
||||
assert get_latest_commit(test_repo, "test-branch") == test_branch_head
|
||||
|
||||
|
||||
def test_git_clone_head():
|
||||
with clone_repo(test_repo, recursive=True) as repo:
|
||||
assert repo.head.commit.hexsha == master_head
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua"))
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua"))
|
||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "test-branch.txt"))
|
||||
|
||||
|
||||
def test_git_clone_branch():
|
||||
with clone_repo(test_repo, "test-branch", recursive=True) as repo:
|
||||
assert repo.head.commit.hexsha == test_branch_head
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua"))
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua"))
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "test-branch.txt"))
|
||||
|
||||
|
||||
def test_git_clone_tag():
|
||||
with clone_repo(test_repo, "v4", recursive=True) as repo:
|
||||
assert repo.head.commit.hexsha == v4_commit
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua"))
|
||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua"))
|
||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "test-branch.txt"))
|
||||
|
||||
|
||||
def test_git_clone_commit():
|
||||
with clone_repo(test_repo, random_commit, recursive=True) as repo:
|
||||
assert repo.head.commit.hexsha == random_commit
|
||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua"))
|
||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua"))
|
||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "test-branch.txt"))
|
||||
116
app/tests/unit/utils/test_minetest_hypertext.py
Normal file
116
app/tests/unit/utils/test_minetest_hypertext.py
Normal file
@@ -0,0 +1,116 @@
|
||||
# ContentDB
|
||||
# Copyright (C) rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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 Affero 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
from app.utils.minetest_hypertext import html_to_minetest
|
||||
|
||||
|
||||
conquer_html = """
|
||||
<p>
|
||||
Welcome to <b>Conquer</b>, a mod that adds RTS gameplay. It allows players to start
|
||||
Conquer sub-games, where they can place buildings, train units, and
|
||||
fight other players.
|
||||
</p>
|
||||
|
||||
<h2>Starting or joining a session</h2>
|
||||
|
||||
<p>
|
||||
You can list running sessions by typing:
|
||||
</p>
|
||||
|
||||
<pre><code>/conquer list
|
||||
new line
|
||||
|
||||
another new line</code></pre>
|
||||
|
||||
<p>
|
||||
You'll switch into Conquer playing mode, where you will be given buildings that you can place.
|
||||
You'll need to place a keep, which you must protect at all costs.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You may leave a game and return to normal playing mode at anytime by typing:
|
||||
</p>
|
||||
|
||||
<h2>Conquer GUI</h2>
|
||||
|
||||
<p>
|
||||
The Conquer GUI is the central place for monitoring your kingdom.
|
||||
Once in a session, you can view it by pressing the inventory key (I),
|
||||
or by punching/right-clicking the keep node.
|
||||
</p>
|
||||
"""
|
||||
|
||||
|
||||
conquer_expected = """
|
||||
Welcome to <b>Conquer</b>, a mod that adds RTS gameplay. It allows players to start Conquer sub-games, where they can place buildings, train units, and fight other players.
|
||||
|
||||
<big>Starting or joining a session</big>
|
||||
You can list running sessions by typing:
|
||||
<code>/conquer list
|
||||
new line
|
||||
|
||||
another new line</code>
|
||||
You'll switch into Conquer playing mode, where you will be given buildings that you can place. You'll need to place a keep, which you must protect at all costs.
|
||||
You may leave a game and return to normal playing mode at anytime by typing:
|
||||
|
||||
<big>Conquer GUI</big>
|
||||
The Conquer GUI is the central place for monitoring your kingdom. Once in a session, you can view it by pressing the inventory key (I), or by punching/right-clicking the keep node.
|
||||
"""
|
||||
|
||||
|
||||
def test_conquer():
|
||||
assert html_to_minetest(conquer_html)["body"].strip() == conquer_expected.strip()
|
||||
|
||||
|
||||
def test_images():
|
||||
html = """
|
||||
<img src="/path/to/img.png">
|
||||
"""
|
||||
|
||||
expected = "<img name=image_0 width=128 height=128>"
|
||||
result = html_to_minetest(html)
|
||||
assert result["body"].strip() == expected.strip()
|
||||
assert len(result["images"]) == 1
|
||||
assert result["images"]["image_0"] == "/path/to/img.png"
|
||||
|
||||
|
||||
def test_bullets():
|
||||
html = """
|
||||
<ul>
|
||||
<li>One</li>
|
||||
<li>two three<ul><li>sub one</li><li>sub two</li></ul></li>
|
||||
<li>four</li>
|
||||
</ul>
|
||||
"""
|
||||
|
||||
expected = "<img name=blank.png width=16 height=1>• One\n" \
|
||||
"<img name=blank.png width=16 height=1>• two three\n" \
|
||||
"<img name=blank.png width=32 height=1>• sub one\n" \
|
||||
"<img name=blank.png width=32 height=1>• sub two\n\n" \
|
||||
"<img name=blank.png width=16 height=1>• four\n"
|
||||
|
||||
result = html_to_minetest(html)
|
||||
assert result["body"].strip() == expected.strip()
|
||||
|
||||
|
||||
def test_inline():
|
||||
html = """
|
||||
<b>One <i>two</i> three</b>
|
||||
"""
|
||||
|
||||
expected = "<b>One <i>two</i> three</b>"
|
||||
result = html_to_minetest(html)
|
||||
assert result["body"].strip() == expected.strip()
|
||||
29
app/tests/unit/utils/test_url.py
Normal file
29
app/tests/unit/utils/test_url.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# ContentDB
|
||||
# Copyright (C) rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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 Affero 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
from app.utils.url import clean_youtube_url
|
||||
|
||||
|
||||
def test_clean_youtube_url():
|
||||
assert clean_youtube_url(
|
||||
"https://www.youtube.com/watch?v=AABBCC") == "https://www.youtube.com/watch?v=AABBCC"
|
||||
assert clean_youtube_url(
|
||||
"https://www.youtube.com/watch?v=boGcB4H5-WA&other=1") == "https://www.youtube.com/watch?v=boGcB4H5-WA"
|
||||
assert clean_youtube_url("https://www.youtube.com/watch?kk=boGcB4H5-WA&other=1") is None
|
||||
assert clean_youtube_url("https://www.bob.com/watch?v=AABBCC") is None
|
||||
|
||||
assert clean_youtube_url("https://youtu.be/boGcB4H5-WA") == "https://www.youtube.com/watch?v=boGcB4H5-WA"
|
||||
assert clean_youtube_url("https://youtu.be/boGcB4H5-WA?this=1") == "https://www.youtube.com/watch?v=boGcB4H5-WA"
|
||||
21
app/tests/unit/utils/test_utils.py
Normal file
21
app/tests/unit/utils/test_utils.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# ContentDB
|
||||
# Copyright (C) rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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 Affero 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import user_agents
|
||||
|
||||
|
||||
def test_minetest_is_not_bot():
|
||||
assert not user_agents.parse("Minetest/5.5.1 (Linux/4.14.193+-ab49821 aarch64)").is_bot
|
||||
Reference in New Issue
Block a user