diff --git a/collector/models.py b/collector/models.py index e925ab4..500b69a 100644 --- a/collector/models.py +++ b/collector/models.py @@ -16,7 +16,6 @@ class Teil(models.Model): verbose_name = "Teil" verbose_name_plural = "Teile" - ordering = ["-modified"] def __str__(self) -> str: modified = self.modified.isoformat(timespec="seconds") diff --git a/collector/tests.py b/collector/tests.py index 26040f2..8ca27e8 100644 --- a/collector/tests.py +++ b/collector/tests.py @@ -1,11 +1,9 @@ from typing import Callable - import pytest from django.test import Client from django.urls import reverse -from hypothesis import given -from hypothesis import strategies as st -from structlog.testing import capture_logs +from hypothesis import given, strategies as st +from logot import Logot, logged from .models import Teil @@ -58,47 +56,16 @@ def test_enter_endpoint_accepts_only_post_requests( assert response.status_code == expected_status +@pytest.mark.xfail(reason="WIP, kein Plan warum nichts gecaptured zu werden scheint") def test_enter_endpoints_emits_expected_logs( - client: Client, random_name: Callable[[int], str] + client: Client, logot: Logot, random_name: Callable[[int], str] ): - """ - note: capture_logs() yields a list of dicts, not a list of logfmt lines - that we configured for the app - """ same_name = random_name(10) - with capture_logs() as logs: - response = client.post(reverse("collector:enter"), data={"new_name": same_name}) - assert response.status_code == 302 - assert any( - ( - le["event"].lower() == "New Teil entered".lower() - and le["log_level"].lower() == "info" - and "teil_id" in le - for le in logs - ) - ) + response = client.post(reverse("collector:enter"), data={"new_name": same_name}) + assert response.status_code == 302 + logot.assert_logged(logged.info("New Teil entered")) - with capture_logs() as logs: - response = client.post(reverse("collector:enter"), data={"new_name": same_name}) - assert response.status_code == 302 - assert any( - ( - le["event"].lower() == "Teil already existed".lower() - and le["log_level"].lower() == "warning" - and "teil_id" not in le - for le in logs - ) - ) - - -def test_model_manager_lists_newest_teil_first(): - t1 = Teil.objects.create(name="Teil 1") - t2 = Teil.objects.create(name="Teil 2") - t3 = Teil.objects.create(name="Teil 3") - - assert t1.modified < t2.modified < t3.modified - - all_teile = Teil.objects.all() - - assert all_teile[2].modified < all_teile[1].modified < all_teile[0].modified + response = client.post(reverse("collector:enter"), data={"new_name": same_name}) + assert response.status_code == 302 + logot.assert_logged(logged.warning("Teil already existed")) diff --git a/justfile b/justfile index b6c14fb..7ae5614 100644 --- a/justfile +++ b/justfile @@ -4,8 +4,6 @@ deps: sync: pip-sync requirements/dev.txt -freshdeps: deps sync - lint: lint-ruff lint-django lint-woodpecker lint-ruff: @@ -13,7 +11,6 @@ lint-ruff: lint-django: python -m django check - python -m django validate_templates lint-woodpecker: -woodpecker-cli lint .woodpecker/workflow.yaml @@ -23,5 +20,3 @@ serve: test *ARGS: ENV_PATH=.env.test python -m pytest {{ARGS}} - -alias fd := freshdeps diff --git a/pyproject.toml b/pyproject.toml index 9c87656..c60b9ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ addopts = [ "--no-migrations", "--capture=sys", ] +logot_capturer = "logot.structlog.StructlogCapturer" [build-system] requires = ["pdm-backend"] diff --git a/requirements/dev.in b/requirements/dev.in index 583c174..8c26e50 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -1,9 +1,9 @@ -r test.in -django-debug-toolbar # debugging in the browser -django-stubs # type hints for django -ipython # more colorful repl -pip-compile-multi # superior dependency management -rich # pretty exceptions on dev/console -ruff # linter -uv # resolver for pip-compile-multi +django-debug-toolbar +django-stubs +ipython +pip-compile-multi +rich +ruff +uv diff --git a/requirements/prod.txt b/requirements/prod.txt index 84c4010..493a11f 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,4 +1,4 @@ -# SHA1:d8e7f5aef64e2e1e161d339a9c1c53d42cdd0981 +# SHA1:48c3af154036b224a6b21f175ea0a949febaf6f5 # # This file is autogenerated by pip-compile-multi # To update, run: diff --git a/requirements/test.in b/requirements/test.in index 2c801fa..f1e3b52 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -3,3 +3,4 @@ hypothesis[django] pytest pytest-django +logot[pytest,structlog] diff --git a/requirements/test.txt b/requirements/test.txt index a038000..7aa87fa 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,4 +1,4 @@ -# SHA1:9bf147356ad56dbe073ef0973141bdfb94631c9b +# SHA1:40e4b481355fc16525f8944d39904264b6e382a6 # # This file is autogenerated by pip-compile-multi # To update, run: @@ -7,8 +7,9 @@ # -r prod.txt attrs==25.3.0 -hypothesis==6.129.3 +hypothesis==6.129.2 iniconfig==2.0.0 +logot==1.3.0 packaging==24.2 pluggy==1.5.0 pytest==8.3.5