aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-11-13 20:33:57 +0100
committerWojtek Kosior <koszko@koszko.org>2021-11-13 20:33:57 +0100
commita14ab0a7601ff5c197fe43d42410d8ed6bfd26a8 (patch)
treebefa6fc0b1de552bae1e2a832a25cb0dd8f58412 /src/test
downloadhaketilo-hydrilla-a14ab0a7601ff5c197fe43d42410d8ed6bfd26a8.tar.gz
haketilo-hydrilla-a14ab0a7601ff5c197fe43d42410d8ed6bfd26a8.zip
initial commit
Diffstat (limited to 'src/test')
-rw-r--r--src/test/__init__.py0
-rw-r--r--src/test/test_pydrilla.py90
2 files changed, 90 insertions, 0 deletions
diff --git a/src/test/__init__.py b/src/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/test/__init__.py
diff --git a/src/test/test_pydrilla.py b/src/test/test_pydrilla.py
new file mode 100644
index 0000000..0ed5fa9
--- /dev/null
+++ b/src/test/test_pydrilla.py
@@ -0,0 +1,90 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+# Repository tests
+#
+# This file is part of Hydrilla
+#
+# Copyright (C) 2021 Wojtek Kosior
+#
+# 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/>.
+#
+#
+# I, Wojtek Kosior, thereby promise not to sue for violation of this
+# file's license. Although I request that you do not make use this code
+# in a proprietary program, I am not going to enforce this in court.
+
+import pytest
+import sys
+import shutil
+from pathlib import Path
+from os import mkdir, unlink, environ
+import json
+
+import pydrilla
+
+test_dir = Path(__file__).resolve().parent
+pydrilla_dir = Path(hydrilla.__file__).resolve().parent
+test_config_path = test_dir / 'config.json'
+
+@pytest.fixture
+def client():
+ app = pydrilla.create_app(test_config_path, flask_config={'TESTING': True})
+
+ with app.test_client() as client:
+ yield client
+
+def test_basic(client):
+ response = client.get('/')
+ assert b'html' in response.data
+
+def test_normalize_version():
+ assert pydrilla.normalize_version([4, 5, 3, 0, 0]) == [4, 5, 3]
+ assert pydrilla.normalize_version([1, 0, 5, 0]) == [1, 0, 5]
+ assert pydrilla.normalize_version([3, 3]) == [3, 3]
+
+### pad_versions() and compare_versions() likely won't be needed
+
+# def test_compare_versions():
+# compare_versions = pydrilla.compare_versions
+# # without revision
+# assert compare_versions([43], [43]) == 0
+# assert compare_versions([54], [34]) == 1
+# assert compare_versions([1], [3]) == -1
+# assert compare_versions([10, 2], [10, 2]) == 0
+# assert compare_versions([11, 6], [11, 2]) == 1
+# assert compare_versions([3, 0], [3, 8]) == -1
+# assert compare_versions([1, 2, 3], [1, 2]) == 1
+# assert compare_versions([1, 2], [1, 2, 3]) == -1
+# assert compare_versions([1], [1, 0, 0]) == 0
+
+# # with revision
+# assert compare_versions([43], [43], rev2=3) == -1
+# assert compare_versions([54], [34]), rev2=41) == 1
+# assert compare_versions([1], [3]), rev1=6) == -1
+# assert compare_versions([10, 2], [10, 2]), rev1=8, rev2=5) == 1
+# assert compare_versions([11, 6], [11, 2]), rev2=19) == 1
+# assert compare_versions([3, 0], [3, 8]), rev2=5) == -1
+# assert compare_versions([1, 2, 3], [1, 2]), rev1=4) == 1
+# assert compare_versions([1, 2], [1, 2, 3]), rev2=7) == -1
+# assert compare_versions([1], [1, 0, 0]), rev2=9, rev1=9) == 0
+
+# from functools import cmp_to_key
+
+# versions = [[43], [54], [3, 0], [34], [3], [1], [4, 5, 3], [1, 0, 5],
+# [3, 3], [10, 2], [11, 2], [11, 6], [3, 8], [1, 2], [1, 2, 3],
+# [1, 0, 0]]
+# versions.sort(cmp_to_key(compare_versions))
+# assert versions == [[1], [1, 0, 0], [1, 0, 5], [1, 2], [1, 2, 3], [3, 0],
+# [3], [3, 3], [3, 8], [4, 5, 3], [10, 2], [11, 2],
+# [11, 6], [34], [43], [54]]