aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli/test_fietsctl.py57
-rw-r--r--tests/conftest.py3
-rw-r--r--tests/playwright/test_basic.py7
-rw-r--r--tests/testutils.py41
4 files changed, 101 insertions, 7 deletions
diff --git a/tests/cli/test_fietsctl.py b/tests/cli/test_fietsctl.py
index 6e19f21..c033b23 100644
--- a/tests/cli/test_fietsctl.py
+++ b/tests/cli/test_fietsctl.py
@@ -182,3 +182,60 @@ def test_user_modify(fietsctl, dbengine, data_manager):
assert not user.is_verified
assert user.is_admin
assert user.email == "ser.davos@seaworth.com"
+
+
+def test_track_list(fietsctl, dbengine, data_manager):
+ populate(dbengine, data_manager)
+
+ res = fietsctl(["track", "list"])
+ assert res.successful()
+ assert res.has_line("Jon.*Trip around Winterfell")
+ assert res.has_line("Jon.*Road to Riverrun")
+
+
+def test_track_del(fietsctl, dbengine, data_manager):
+ ids = populate(dbengine, data_manager)
+
+ res = fietsctl(["track", "del", "-i", str(ids.winterfell)])
+ assert not res.successful()
+
+ res = fietsctl(["track", "del", "-i", str(ids.winterfell), "-f"])
+ assert res.successful()
+
+ with Session(dbengine) as session:
+ track = session.get(models.Track, ids.winterfell)
+ assert track is None
+
+ with pytest.raises(FileNotFoundError):
+ data_manager.open(ids.winterfell)
+
+
+def test_maintenance_mode_get(fietsctl, data_manager):
+ res = fietsctl(["maintenance-mode"])
+ assert res.successful()
+ assert res.has_line("Maintenance mode is disabled")
+
+ (data_manager.data_dir / "MAINTENANCE").write_bytes(b"Updating")
+ res = fietsctl(["maintenance-mode"])
+ assert res.successful()
+ assert res.has_line("enabled: Updating")
+
+
+def test_maintenance_mode_set(fietsctl, data_manager):
+ assert data_manager.maintenance_mode() is None
+
+ res = fietsctl(["maintenance-mode", "Discombobulating"])
+ assert res.successful()
+ assert data_manager.maintenance_mode() == "Discombobulating"
+
+ res = fietsctl(["maintenance-mode", "Frobnicating"])
+ assert res.successful()
+ assert data_manager.maintenance_mode() == "Frobnicating"
+
+
+def test_maintenance_mode_disable(fietsctl, data_manager):
+ (data_manager.data_dir / "MAINTENANCE").write_bytes(b"Updating")
+
+ res = fietsctl(["maintenance-mode", "--disable"])
+ assert res.successful()
+ assert data_manager.maintenance_mode() is None
diff --git a/tests/conftest.py b/tests/conftest.py
index add3b3f..c31554d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -65,6 +65,8 @@ def clean_directory_content(path: Path):
if path.is_dir():
shutil.rmtree(path)
path.mkdir()
+ elif path.is_file():
+ path.unlink()
@pytest.fixture(autouse=True)
@@ -85,6 +87,7 @@ def _cleanup_data(app_settings):
clean_directory_content(data_dir / "tracks")
clean_directory_content(data_dir / "users")
clean_directory_content(data_dir / "journeys")
+ clean_directory_content(data_dir / "MAINTENANCE")
@pytest.fixture(scope='module')
def app(app_settings, dbengine, tmp_path_factory):
diff --git a/tests/playwright/test_basic.py b/tests/playwright/test_basic.py
index 3ae0f58..19ef8ff 100644
--- a/tests/playwright/test_basic.py
+++ b/tests/playwright/test_basic.py
@@ -4,7 +4,7 @@ import pytest
from playwright.sync_api import Page, expect
from sqlalchemy import select
-from testutils import load_gpx_asset
+from testutils import asset_path, load_gpx_asset
from fietsboek import models
from fietsboek.models.track import Visibility
@@ -60,6 +60,10 @@ def test_upload(page: Page, playwright_helper, tmp_path, dbaccess):
page.get_by_role("button", name="Add Tag").click()
page.get_by_label("Description").fill("Beschreibung der tollen Tour")
+ page.locator("#imageSelector").set_input_files(
+ [asset_path("picture01.jpg"), asset_path("picture02.jpg")],
+ )
+
page.locator(".btn", has_text="Upload").click()
# Once we have finished the upload, extract the ID of the track and check
@@ -72,6 +76,7 @@ def test_upload(page: Page, playwright_helper, tmp_path, dbaccess):
assert track.visibility == Visibility.PUBLIC
assert track.text_tags() == {"Tolle Tour"}
assert track.description == "Beschreibung der tollen Tour"
+ assert len(track.images) == 2
def test_edit(page: Page, playwright_helper, dbaccess):
diff --git a/tests/testutils.py b/tests/testutils.py
index 9db3673..e49a0b5 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -17,6 +17,18 @@ class PopulationIds(NamedTuple):
"""Collection of database IDs that :func:`populate` returns."""
jon: int
davos: int
+ winterfell: int
+ riverrun: int
+
+
+def asset_path(filename: str) -> Path:
+ """Returns the path to the test asset given by the filename.
+
+ :param filename: The filename of the asset.
+ :return: The complete path.
+ """
+ asset_dir = Path(__file__).parent / "assets"
+ return asset_dir / filename
def load_test_asset(filename: str) -> bytes:
@@ -27,8 +39,7 @@ def load_test_asset(filename: str) -> bytes:
:param filkename: Name of the asset to load.
:return: The content of the file as bytes.
"""
- asset_dir = Path(__file__).parent / "assets"
- return (asset_dir / filename).read_bytes()
+ return asset_path(filename).read_bytes()
def load_gpx_asset(filename: str) -> bytes:
@@ -40,8 +51,7 @@ def load_gpx_asset(filename: str) -> bytes:
:param filename: Name of the asset to load.
:return: The content of the asset as bytes.
"""
- asset_dir = Path(__file__).parent / 'assets'
- test_file = asset_dir / filename
+ test_file = asset_path(filename)
with gzip.open(test_file, 'rb') as fobj:
return fobj.read()
@@ -65,7 +75,18 @@ def extract_and_upload(page: Page, filename: str, tmp_path: Path):
def populate(dbengine: Engine, data_manager: DataManager) -> PopulationIds:
- """Populates the database and data directory with some test data."""
+ """Populates the database and data directory with some test data.
+
+ This adds:
+
+ Jon (jon.snow@nw.org, admin, password: ygritte)
+ Trip around Winterfell (2 images)
+ Road to Riverrun
+
+ Davos (davos@seaworth.com, password: 123456)
+
+ :return: An object carrying the database IDs of the added objects.
+ """
user_ids = []
with Session(dbengine) as session:
user = models.User(name="Jon", email="jon.snow@nw.org", is_verified=True, is_admin=True)
@@ -87,6 +108,7 @@ def populate(dbengine: Engine, data_manager: DataManager) -> PopulationIds:
for user_id in user_ids:
data_manager.initialize_user(user_id)
+ track_ids = []
# First track for Jon:
gpx_data = load_gpx_asset("Teasi_1.gpx.gz")
@@ -110,6 +132,7 @@ def populate(dbengine: Engine, data_manager: DataManager) -> PopulationIds:
session.flush()
assert track.id is not None
+ track_ids.append(track.id)
manager = data_manager.initialize(track.id)
manager.compress_backup(gpx_data)
@@ -152,6 +175,7 @@ def populate(dbengine: Engine, data_manager: DataManager) -> PopulationIds:
session.flush()
assert track.id is not None
+ track_ids.append(track.id)
manager = data_manager.initialize(track.id)
manager.compress_backup(gpx_data)
@@ -161,4 +185,9 @@ def populate(dbengine: Engine, data_manager: DataManager) -> PopulationIds:
session.commit()
- return PopulationIds(jon=user_ids[0], davos=user_ids[1])
+ return PopulationIds(
+ jon=user_ids[0],
+ davos=user_ids[1],
+ winterfell=track_ids[0],
+ riverrun=track_ids[1],
+ )