From 2cb8a0d2c8e286fab132876de29821fe70128d5c Mon Sep 17 00:00:00 2001 From: Stefano Apostolico Date: Fri, 29 Nov 2024 19:02:40 +0100 Subject: [PATCH] update tests --- src/country_workspace/__monitor__.py | 43 ------------------- .../compat/admin_extra_buttons.py | 1 - tests/.coveragerc | 3 ++ tests/admin/test_admin_program.py | 35 +++++++++++++++ 4 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 src/country_workspace/__monitor__.py create mode 100644 tests/admin/test_admin_program.py diff --git a/src/country_workspace/__monitor__.py b/src/country_workspace/__monitor__.py deleted file mode 100644 index 90af37e..0000000 --- a/src/country_workspace/__monitor__.py +++ /dev/null @@ -1,43 +0,0 @@ -import sys - - -def monitor(app): - from celery.events import EventReceiver - - state = app.events.State() - - def announce_failed_tasks(event): - state.event(event) - # task name is sent only with -received event, and state - # will keep track of this for us. - task = state.tasks.get(event["uuid"]) - - sys.stdout.write( - "TASK FAILED: %s[%s] %s\n" - % ( - task.name, - task.uuid, - task.info(), - ) - ) - - def on_event(event): - if event["type"] != "worker-heartbeat": - state.event(event) - - with app.connection() as connection: - recv = EventReceiver(connection, handlers={"*": on_event}) - recv.capture(limit=None, timeout=None) - - -def run(): - import django - - django.setup() - from country_workspace.config.celery import app - - monitor(app) - - -if __name__ == "__main__": - run() diff --git a/src/country_workspace/compat/admin_extra_buttons.py b/src/country_workspace/compat/admin_extra_buttons.py index 378fa6c..453da4c 100644 --- a/src/country_workspace/compat/admin_extra_buttons.py +++ b/src/country_workspace/compat/admin_extra_buttons.py @@ -28,7 +28,6 @@ def confirm_action( if request.method == "POST": ret = None try: - breakpoint() ret = action(request) if success_message: modeladmin.message_user(request, success_message, messages.SUCCESS) diff --git a/tests/.coveragerc b/tests/.coveragerc index 6c2919a..b947f55 100644 --- a/tests/.coveragerc +++ b/tests/.coveragerc @@ -6,8 +6,11 @@ omit = */tests/** */migrations/*, src/country_workspace/management/commands/demo.py + src/country_workspace/management/commands/trigger_error.py src/country_workspace/security/backends.py src/country_workspace/versioning/scripts/* + src/country_workspace/contrib/hope/ddt.py + src/country_workspace/cache/ddt.py */wsgi.py, diff --git a/tests/admin/test_admin_program.py b/tests/admin/test_admin_program.py new file mode 100644 index 0000000..f906905 --- /dev/null +++ b/tests/admin/test_admin_program.py @@ -0,0 +1,35 @@ +from typing import TYPE_CHECKING + +from django.urls import reverse + +import pytest +from django_webtest.pytest_plugin import MixinWithInstanceVariables + +from country_workspace.models import User + +if TYPE_CHECKING: + from testutils.types import CWTestApp + + from country_workspace.workspaces.models import CountryProgram + + +@pytest.fixture() +def program(): + from testutils.factories import CountryProgramFactory + + return CountryProgramFactory() + + +@pytest.fixture() +def app(django_app_factory: "MixinWithInstanceVariables") -> "CWTestApp": + django_app = django_app_factory(csrf_checks=False) + yield django_app + + +def test_program_zap(app, user: "User", program: "CountryProgram"): + base_url = reverse("admin:country_workspace_program_zap", args=[program.pk]) + app.set_user(user) + res = app.get(base_url, expect_errors=True) + res = res.form.submit() + res = res.follow() + assert res.status_code == 302