aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2024-04-16 22:48:23 +0200
committerDaniel Schadt <kingdread@gmx.de>2024-04-16 22:48:23 +0200
commit83e08799d6b55bc2119aff4f9749bad103b5f574 (patch)
tree75bfc99932df07c74a801a228d799cf26187619c
parentd6ad20a3df26e80fddd6a304550514f19d54811a (diff)
downloadfietsboek-83e08799d6b55bc2119aff4f9749bad103b5f574.tar.gz
fietsboek-83e08799d6b55bc2119aff4f9749bad103b5f574.tar.bz2
fietsboek-83e08799d6b55bc2119aff4f9749bad103b5f574.zip
add test for fietsupdate bootstrapping
-rw-r--r--tests/bootstrap/test_new_instance.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/bootstrap/test_new_instance.py b/tests/bootstrap/test_new_instance.py
new file mode 100644
index 0000000..e136579
--- /dev/null
+++ b/tests/bootstrap/test_new_instance.py
@@ -0,0 +1,70 @@
+"""Test to ensure that bootstrapping a new instance works with the fietsupdate
+script, as described in the documentation.
+"""
+
+import contextlib
+import logging
+import os
+import shutil
+import subprocess
+import venv
+from pathlib import Path
+
+LOGGER = logging.getLogger(__name__)
+REPO_BASE = Path(__file__).parent.parent.parent
+
+
+@contextlib.contextmanager
+def chdir(path: Path):
+ """Change path as context manager.
+
+ Changes back to the previous path on ``__exit__``.
+ """
+ cwd = Path.cwd()
+ os.chdir(path)
+ try:
+ yield
+ finally:
+ os.chdir(cwd)
+
+
+def install_fietsboek(venv_path: Path) -> Path:
+ """Creates a virtual env in the given path and installs fietsboek.
+
+ :param venv_path: Path in which the virtual environment should be created.
+ :return: The path to the ``bin`` directory in which all scripts reside.
+ """
+ venv.create(venv_path, with_pip=True)
+ subprocess.check_call([venv_path / "bin" / "pip", "install", str(REPO_BASE)])
+ return venv_path / "bin"
+
+
+def test_setup_via_fietsupdate(tmpdir):
+ with chdir(tmpdir):
+ # We create a new temporary virtual environment with a fresh install, just
+ # to be sure there's as little interference as possible.
+ LOGGER.info("Installing Fietsboek into clean env")
+ binaries_path = install_fietsboek(tmpdir / "venv")
+
+ LOGGER.info("Creating a test configuration")
+ shutil.copy(REPO_BASE / "testing.ini", "testing.ini")
+ Path("data").mkdir()
+
+ # Try to run the migrations
+ subprocess.check_call(
+ [binaries_path / "fietsupdate", "update", "-c", "testing.ini", "-f"]
+ )
+
+ # Also try to add an administrator
+ subprocess.check_call([
+ binaries_path / "fietsctl",
+ "user",
+ "add",
+ "-c", "testing.ini",
+ "--email", "foobar@example.com",
+ "--name", "Foo Bar",
+ "--password", "raboof",
+ "--admin",
+ ])
+
+ assert True